diff --git a/designer/import_dialog.ui b/designer/import_dialog.ui index 88c93bd..19220e4 100644 --- a/designer/import_dialog.ui +++ b/designer/import_dialog.ui @@ -40,6 +40,23 @@ + + + &Author + + + authorBox + + + + + + + + + + + Ta&gs @@ -49,10 +66,10 @@ - + - + Lines of Conte&xt @@ -62,7 +79,7 @@ - + @@ -84,7 +101,7 @@ - + Lines to &Recite @@ -94,7 +111,7 @@ - + Number of occluded lines shown on the answer side of each card. @@ -107,7 +124,7 @@ - + Lines in Gro&ups of @@ -117,7 +134,7 @@ - + 1 @@ -215,6 +232,7 @@ titleBox + authorBox tagsBox contextLinesSpin reciteLinesSpin diff --git a/docs/changes.rst b/docs/changes.rst index 3b50442..d479097 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -2,6 +2,11 @@ Changelog ========= +LPCG 1.3.1 +========== + +* Added Author field. + LPCG 1.3.0 ========== @@ -93,4 +98,4 @@ LPCG 0.9.1 LPCG 0.9.0 ========== -* First public release. \ No newline at end of file +* First public release. diff --git a/src/gen_notes.py b/src/gen_notes.py index 124eeb7..bc37b17 100644 --- a/src/gen_notes.py +++ b/src/gen_notes.py @@ -12,7 +12,7 @@ def __init__(self) -> None: self.successor: Optional['PoemLine'] = None self.seq = -1 - def populate_note(self, note: 'Note', title: str, tags: List[str], + def populate_note(self, note: 'Note', title: str, author: str, tags: List[str], context_lines: int, recite_lines: int, deck_id: int) -> None: """ Fill the _note_ with content testing on the current line. @@ -20,6 +20,7 @@ def populate_note(self, note: 'Note', title: str, tags: List[str], note.model()['did'] = deck_id # type: ignore note.tags = tags note['Title'] = title + note['Author'] = author note['Sequence'] = str(self.seq) note['Context'] = self._format_context(context_lines) note['Line'] = self._format_text(recite_lines) @@ -80,7 +81,7 @@ def _get_text(self, _lines: int) -> List[str]: """ raise NotImplementedError - def populate_note(self, note: 'Note', title: str, tags: List[str], + def populate_note(self, note: 'Note', title: str, author: str, tags: List[str], context_lines: int, recite_lines: int, deck_id: int) -> None: raise AssertionError("The Beginning node cannot be used to populate a note.") @@ -243,10 +244,11 @@ def _normalize_blank_lines(text_lines): def add_notes(col: Any, note_constructor: Callable, - title: str, tags: List[str], text: List[str], deck_id: int, - context_lines: int, group_lines: int, recite_lines: int): + title: str, author:str, tags: List[str], text: List[str], + deck_id: int, context_lines: int, group_lines: int, + recite_lines: int): """ - Generate notes from the given title, tags, poem text, and number of + Generate notes from the given title, author, tags, poem text, and number of lines of context. Return the number of notes added. Return the number of notes added. @@ -258,7 +260,7 @@ def add_notes(col: Any, note_constructor: Callable, added = 0 for line in _poemlines_from_textlines(text, group_lines): n = note_constructor(col, col.models.byName("LPCG 1.0")) - line.populate_note(n, title, tags, context_lines, recite_lines, deck_id) + line.populate_note(n, title, author, tags, context_lines, recite_lines, deck_id) col.addNote(n) added += 1 return added diff --git a/src/lpcg_dialog.py b/src/lpcg_dialog.py index 93e3cfa..3f959ef 100644 --- a/src/lpcg_dialog.py +++ b/src/lpcg_dialog.py @@ -56,6 +56,7 @@ def accept(self): '"Open File" button to import a text file.') return + author = self.form.authorBox.text().strip() tags = self.mw.col.tags.split(self.form.tagsBox.text()) text = cleanse_text(self.form.textBox.toPlainText().strip(), self.mw.addonManager.getConfig(__name__)) @@ -65,7 +66,7 @@ def accept(self): did = self.deckChooser.selectedId() try: - notes_generated = add_notes(self.mw.col, Note, title, tags, text, did, + notes_generated = add_notes(self.mw.col, Note, title, author, tags, text, did, context_lines, group_lines, recite_lines) except KeyError as e: showWarning( diff --git a/src/models.py b/src/models.py index b57c1a9..5ab1fe8 100644 --- a/src/models.py +++ b/src/models.py @@ -144,7 +144,7 @@ def is_at_version(cls, current_version: str) -> bool: return current_version == cls.version -def upgrade_onethreeoh(mod): +def upgrade_none_to_onethreeoh(mod): "Upgrade LPCG model from unversioned to version 1.3.0." mm = aqt.mw.col.models field = mm.newField("Prompt") @@ -175,11 +175,36 @@ def upgrade_onethreeoh(mod): ) +def upgrade_onethreeoh_to_onethreeone(mod): + "Upgrade LPCG model from 1.3.0 to version 1.3.1." + mm = aqt.mw.col.models + mm.addField(mod, mm.newField("Author")) + + mod['css'].replace('.title', '.title, .author') + + assert len(mod['tmpls']) == 1, "LPCG note type has extra templates!" + for side in ['qfmt', 'afmt']: + mod['tmpls'][0][side] = mod['tmpls'][0][side].replace( + '
{{Title}} {{Sequence}}
', + dedent(''' +
{{Title}} {{Sequence}}
+ {{#Author}}
{{Author}}
{{/Author}} + ''').strip() + ) + + +def upgrade_unversioned_to_onethreeone(mod): + "Upgrade LPCG model from 1.3.0 to version 1.3.1." + upgrade_none_to_onethreeoh(mod) + upgrade_onethreeoh_to_onethreeone(mod) + + class LpcgOne(ModelData): class LpcgOneTemplate(TemplateData): name = "LPCG1" front = """
{{Title}} {{Sequence}}
+ {{#Author}}
{{Author}}
{{/Author}}
@@ -193,6 +218,7 @@ class LpcgOneTemplate(TemplateData): """ back = """
{{Title}} {{Sequence}}
+ {{#Author}}
{{Author}}
{{/Author}}
@@ -203,7 +229,7 @@ class LpcgOneTemplate(TemplateData): """ name = "LPCG 1.0" - fields = ("Line", "Context", "Title", "Sequence", "Prompt") + fields = ("Line", "Context", "Title", "Author", "Sequence", "Prompt") templates = (LpcgOneTemplate,) styling = """ .card { @@ -234,7 +260,7 @@ class LpcgOneTemplate(TemplateData): filter: invert(85%); } - .title { + .title, .author { text-align: center; font-size: small; } @@ -245,9 +271,10 @@ class LpcgOneTemplate(TemplateData): """ sort_field = "Sequence" is_cloze = False - version = "1.3.0" + version = "1.3.1" upgrades = ( - ("none", "1.3.0", upgrade_onethreeoh), + ("none", "1.3.0", upgrade_none_to_onethreeoh), + ("1.3.0", "1.3.1", upgrade_onethreeoh_to_onethreeone), ) diff --git a/test/test_gen_notes.py b/test/test_gen_notes.py index 6a5509c..bf856c5 100644 --- a/test/test_gen_notes.py +++ b/test/test_gen_notes.py @@ -168,6 +168,7 @@ def mock_note(): col = MockCollection() note_constructor = MockNote title = "'Tis Winter" + author = "Samuel Longfellow" tags = ["poem", "test"] deck_id = 1 context_lines = 2 @@ -185,6 +186,7 @@ def test_render_default_settings(mock_note): assert len(col.notes) == 16 assert col.notes[0]['Title'] == mock_note['title'] + assert col.notes[0]['Author'] == mock_note['author'] assert col.notes[0].tags == mock_note['tags'] assert col.notes[0]['Sequence'] == "1" assert col.notes[0]['Context'] == "

[Beginning]

" @@ -192,6 +194,7 @@ def test_render_default_settings(mock_note): assert 'Prompt' not in col.notes[0] assert col.notes[3]['Title'] == mock_note['title'] + assert col.notes[3]['Author'] == mock_note['author'] assert col.notes[3].tags == mock_note['tags'] assert col.notes[3]['Sequence'] == "4" assert col.notes[3]['Context'] == ( @@ -242,6 +245,7 @@ def test_render_groups_of_three(mock_note): assert len(col.notes) == 6 assert col.notes[0]['Title'] == mock_note['title'] + assert col.notes[0]['Author'] == mock_note['author'] assert col.notes[0].tags == mock_note['tags'] assert col.notes[0]['Sequence'] == "1" assert col.notes[0]['Context'] == "

[Beginning]

"