Commit graph

53 commits

Author SHA1 Message Date
Damien Elmes
ee3f963919 remove ':' from field names 2019-12-30 18:50:00 +10:00
Michal Pokorný (Rai)
9383a72704 Remove unneeded utf-8 encoding declaration
UTF-8 is the default as of Python 3.
See: https://docs.python.org/3/reference/lexical_analysis.html#encoding-declarations
2019-12-27 18:06:06 +01:00
Damien Elmes
3e1b474dca bridge->backend 2019-12-25 08:59:33 +10:00
Damien Elmes
3ce4d5fd3d compute template requirements in Rust
on a 100 field template, what took ~75 seconds now takes ~3 seconds.
2019-12-24 19:57:54 +10:00
Damien Elmes
4863431c93 add type hint to models 2019-12-24 14:06:31 +10:00
Damien Elmes
17af26dcb5 apply black to all files 2019-12-23 10:34:10 +10:00
Michal Pokorný (Rai)
13afb0dbff Move repeated calls to _renderQA into local function 2019-12-23 00:32:09 +01:00
Damien Elmes
7399e0bd2b Model->NoteType 2019-12-22 08:58:56 +10:00
Michal Pokorný (Rai)
67a39c58cb Add types for models, templates and field dicts 2019-12-21 12:02:16 +01:00
Damien Elmes
c1587254f4 use isort to tidy up imports 2019-12-20 19:19:29 +10:00
Damien Elmes
b6b8df2dcf add a bunch of annotations for mypy 2019-12-20 15:07:40 +10:00
Damien Elmes
efd78e66ef models 2019-12-20 11:07:08 +10:00
Damien Elmes
6ecfff56c5 add pytype inferred types to anki/
I've corrected some obvious issues, and we can fix others over time.
Mypy tests are currently broken, as adding the type hints has increased
mypy's testing surface.
2019-12-20 11:07:08 +10:00
Damien Elmes
e59af745f7
Merge pull request #361 from Arthur-Milchior/testReqs
test req
2019-12-16 20:44:23 +10:00
Damien Elmes
d7cb7eaea0 avoid recalculating reqs in actions like adding cards 2019-12-16 20:27:58 +10:00
Damien Elmes
b4b8717a20 set instance vars in __init__() 2019-12-16 17:49:32 +10:00
Arthur Milchior
a1d602f154 update requireds saves reqs as lists instead of tuples.
The goal of this change is to be consistent with JSON. Indeed, the
dictionnary is saved as JSON, which has list and does not has
tuple. The request was made in https://github.com/dae/anki/pull/361#issuecomment-565915191
2019-12-15 22:55:29 -08:00
Damien Elmes
37a239cf38 add basic type checking for anki/ 2019-12-16 08:17:28 +10:00
Arthur Milchior
556ef5d34b newField checks its input is a str
Indeed, it takes as input a name (str). For some reason in some test
it was given a model. This actually led to some strange failed test.
2019-11-25 00:15:20 +01:00
Damien Elmes
0577157970 Revert "Merge pull request #345 from Arthur-Milchior/noFullSyncWhenEditingNewModel"
This reverts commit 0ffb308004, reversing
changes made to fed2f2fa3d.

This approach is flawed. Any minor change to the note type will set usn
to -1, causing the schema not to be modified when it should be.
2019-10-27 21:37:21 +10:00
Arthur Milchior
9863b6f9ff Use _modSchemaIfRequired in all cases.
Same logic than in last commit. Actually, there is no change of model
which need a full sync until the model is uploaded. After all, even if
a change in model imply that some card will change, those cards and
notes have not been uploaded either
2019-10-24 04:45:12 +02:00
Arthur Milchior
b78480fe52 New model can be edited without full sync
This commit solves a problem that I had many time in the past. When I
create a new model, I usually want to edit it. Clone of existing
models present no interest by themselves. And as soon as I edit it, I
need to do a full sync.

As far as I understand ankiweb (which is sadly closed source), the
full sync is required because ankiweb needs to know that the model
associated to note type on the server did change. But since the model
is new, it has no note type associated to on the server, so there is
no need to do a full sync immediatly. Since the model is new, it also
means there is no risk of the inconsistency with a change made in
another computer/smartphone.

Thus, when a field/template is added, I check that the model is not
new by checking both whether it's id is not null, and also that it's
usn is not -1. (I set usn early in the model's life)

If it does not make into anki, then it'll be an add-on. But it's worth
a try first.
2019-10-24 04:44:52 +02:00
Damien Elmes
8497da27cf ensure the list of note types is not empty
fixes an issue opening the add screen if a user manages to delete
all their note types with an add-on or a sync
2019-04-21 18:02:12 +10:00
Damien Elmes
3cf770c73c Revert "moveTemplate slightly quicker"
This reverts commit b29fd508c7.

This caused a regression:
https://github.com/dae/anki/pull/294
2019-03-11 13:49:58 +10:00
Damien Elmes
ebdd8dae4b tidy up unused imports 2019-03-04 17:25:19 +10:00
Damien Elmes
6e077ab414 use raw strings for regexs 2019-03-04 17:03:43 +10:00
Damien Elmes
4037a034aa fix inconsistent indentation 2019-03-04 16:54:22 +10:00
Damien Elmes
372d5ed6e8 update copyright and clarify licenses 2019-02-05 14:01:33 +10:00
Damien Elmes
867e4b9f94 support {{CardFlag}}
https://anki.tenderapp.com/discussions/ankidesktop/32158-flags
2019-02-05 13:00:47 +10:00
Arthur-Milchior
b29fd508c7 moveTemplate slightly quicker
When a template is moved, only move the ord of cards whose position
did change.
2019-01-20 15:46:58 +01:00
Damien Elmes
b17946b282 fix detection of multiline cloze deletions 2018-06-15 11:24:59 +10:00
Rémy Léone
4446b85ef2 Simplify comparisons 2017-09-10 15:32:51 +02:00
Illia Volochii
13b7e01044 Stop inheriting from object
It is not needed in Python 3.
2017-02-07 00:21:33 +02:00
Damien Elmes
15b349e3a8 start port to python 3
unit tests pass and main screens of GUI load
2016-05-12 14:45:35 +10:00
Dave Shifflett
643ec35449 Use alternate pattern match during field changes
When a user renames or deletes a field, Anki tries to go through the
user's templates to substitute occurrences of that field name with its
new name or remove the field.

However, if the user has multiple Mustache placeholders on a single
line, this does not work as intended because the leading (.*) capture
group grabs the text in-between the two (or more) Mustache placeholders.

Examples:

    {{#Flag}}
        ...
    {{/Flag}}{{^Flag}}
        ...
    {{/Flag}}

or

    {{Front}} {{#Flag}}...{{/Flag}}

or

    {{Front}} Hello. {{Victim}}
2014-12-29 20:09:09 -06:00
Damien Elmes
6e7e08ebd0 be explicit about modSchema()'s check flag
- remove gui code that adds exceptions for syncing
- use check=False for all syncing and upgrade code
2014-11-03 16:28:12 +09:00
Soren I. Bjornstad
625d7d5a82 rename fields in template properly when more than one modifier used
Previously something like {{type:cloze:Text}} in the template would not
be renamed when the field was renamed.
2014-08-11 11:33:39 -05:00
Damien Elmes
694682d964 fix multiple cloze tags contained on one line
inner regex was capturing multiple clozes. fixes
https://anki.tenderapp.com/discussions/ankidesktop/6599-empty-cards-3533-cards-to-delete
2014-04-16 01:15:59 +09:00
Julien Baley
7e3597fb8e Adding support for chained modifiers. One can now write e.g. {{cloze:text:Field}} or {{text:cloze:Field}}, it's order independent. 2014-02-18 17:24:28 +00:00
Damien Elmes
7aee582a58 loop should exit early, and allNames() doesn't need modification 2013-10-06 09:26:43 +09:00
Damien Elmes
f1837e7e0a when ensuring model unique, check id not obj
this should fix an issue where we were attaching a suffix to non-duplicate
names on sync
2013-10-05 23:53:09 +09:00
Damien Elmes
9524dbed96 give note types unique name when adding/importing (#325) 2013-10-04 09:00:08 +09:00
Damien Elmes
e73bfa9d02 ignore qfmt/afmt when checking if note types are the same 2013-09-04 02:18:53 +09:00
Damien Elmes
cfac1eb99b add utf8 input back to latex
This was what we originally had in templates in Anki 1. It was changed to
utf8x at one point, then we discovered that some LaTeX installs didn't have
that package so it was removed, when we should have reverted to utf8 instead.
This fixes things like umlauts but does not allow display of things like
Japanese text.
2013-05-27 10:52:55 +09:00
Damien Elmes
7957dff33f make sure sort field updated when field deleted (#737) 2013-04-11 14:23:06 +09:00
Damien Elmes
c437a38446 move card type deletion back to X on card tabs 2013-04-11 14:02:01 +09:00
Damien Elmes
19012e6110 don't set browser font on card creation (#543) 2013-01-29 09:40:47 +09:00
Damien Elmes
c335ea2cee note type manager needs to ignore the default note type for current deck 2013-01-08 21:39:37 +09:00
Damien Elmes
0447cb4f41 fix issues with clozes and <% %> 2013-01-04 14:39:06 +09:00
Damien Elmes
d11a1e0d54 allow browser font customization on a per-template basis 2012-12-22 10:10:52 +09:00