From a7bc0693891c07e3df0fd59179fab1e8cccd1b41 Mon Sep 17 00:00:00 2001 From: Arthur-Milchior Date: Sat, 16 Feb 2019 11:28:02 +0100 Subject: [PATCH 1/4] Adding Arthur Milchior to contributors --- aqt/about.py | 1 + 1 file changed, 1 insertion(+) diff --git a/aqt/about.py b/aqt/about.py index 718eaadf8..0baa2e9f7 100644 --- a/aqt/about.py +++ b/aqt/about.py @@ -117,6 +117,7 @@ system. It's free and open source.") "黃文龍", "David Bailey", "Arman High", + "Arthur Milchior", )) abouttext += '

' + _("Written by Damien Elmes, with patches, translation,\ From 7e72361b227319cc3bd9cc9a23e9d4da52807bed Mon Sep 17 00:00:00 2001 From: Arthur-Milchior Date: Sat, 16 Feb 2019 11:28:50 +0100 Subject: [PATCH 2/4] Correct deck when previewing an existing card --- anki/collection.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/anki/collection.py b/anki/collection.py index cf8cb82d5..2a9e48223 100644 --- a/anki/collection.py +++ b/anki/collection.py @@ -437,10 +437,12 @@ insert into cards values (?,?,?,?,?,?,0,0,?,0,0,0,0,0,0,0,0,"")""", card.nid = note.id card.ord = template['ord'] # Use template did (deck override) if valid, otherwise model did - if template['did'] and str(template['did']) in self.decks.decks: - card.did = template['did'] - else: - card.did = note.model()['did'] + card.did = self.db.scalar("select did from cards where nid = ? and ord = ?", card.nid, card.ord) + if not card.did: + if template['did'] and str(template['did']) in self.decks.decks: + card.did = template['did'] + else: + card.did = note.model()['did'] # if invalid did, use default instead deck = self.decks.get(card.did) if deck['dyn']: From 2608513381ff0020adf630a330f98a4c95effe44 Mon Sep 17 00:00:00 2001 From: Arthur-Milchior Date: Sat, 16 Feb 2019 12:25:22 +0100 Subject: [PATCH 3/4] Show deck of the addCard window --- anki/collection.py | 10 ++++++---- aqt/clayout.py | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/anki/collection.py b/anki/collection.py index 2a9e48223..8f6221ba3 100644 --- a/anki/collection.py +++ b/anki/collection.py @@ -417,7 +417,7 @@ insert into cards values (?,?,?,?,?,?,0,0,?,0,0,0,0,0,0,0,0,"")""", # type 0 - when previewing in add dialog, only non-empty # type 1 - when previewing edit, only existing # type 2 - when previewing in models dialog, all templates - def previewCards(self, note, type=0): + def previewCards(self, note, type=0, did = None): if type == 0: cms = self.findTemplates(note) elif type == 1: @@ -428,19 +428,21 @@ insert into cards values (?,?,?,?,?,?,0,0,?,0,0,0,0,0,0,0,0,"")""", return [] cards = [] for template in cms: - cards.append(self._newCard(note, template, 1, flush=False)) + cards.append(self._newCard(note, template, 1, flush=False, did = did)) return cards - def _newCard(self, note, template, due, flush=True): + def _newCard(self, note, template, due, did = None, flush=True): "Create a new card." card = anki.cards.Card(self) card.nid = note.id card.ord = template['ord'] - # Use template did (deck override) if valid, otherwise model did card.did = self.db.scalar("select did from cards where nid = ? and ord = ?", card.nid, card.ord) + # Use template did (deck override) if valid, otherwise did in argument, otherwise model did if not card.did: if template['did'] and str(template['did']) in self.decks.decks: card.did = template['did'] + elif did: + card.did = did else: card.did = note.model()['did'] # if invalid did, use default instead diff --git a/aqt/clayout.py b/aqt/clayout.py index d0414c6bf..2e9764cee 100644 --- a/aqt/clayout.py +++ b/aqt/clayout.py @@ -61,7 +61,8 @@ class CardLayout(QDialog): self.setFocus() def redraw(self): - self.cards = self.col.previewCards(self.note, 2) + did = self.parent.deckChooser.selectedId() if self.addMode else None + self.cards = self.col.previewCards(self.note, 2, did = did) idx = self.ord if idx >= len(self.cards): self.ord = len(self.cards) - 1 From 23f389bf2adb0c8881cd3ceb00bb2a3136577325 Mon Sep 17 00:00:00 2001 From: Arthur-Milchior Date: Sun, 17 Feb 2019 19:26:31 +0100 Subject: [PATCH 4/4] Correcting a small bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I though «addMode» meant «call from addcard window». Instead, to know whether parent is addcard, I check whether it has attribute deckChooser --- aqt/clayout.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/aqt/clayout.py b/aqt/clayout.py index 2e9764cee..037f3b954 100644 --- a/aqt/clayout.py +++ b/aqt/clayout.py @@ -61,7 +61,9 @@ class CardLayout(QDialog): self.setFocus() def redraw(self): - did = self.parent.deckChooser.selectedId() if self.addMode else None + did = None + if hasattr(self.parent,"deckChooser"): + did = self.parent.deckChooser.selectedId() self.cards = self.col.previewCards(self.note, 2, did = did) idx = self.ord if idx >= len(self.cards):