mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Reformatting through black
This commit is contained in:
parent
957f0c8e8b
commit
35c8f21eb6
5 changed files with 67 additions and 21 deletions
|
@ -88,7 +88,11 @@ class Card:
|
||||||
self.mod = intTime()
|
self.mod = intTime()
|
||||||
self.usn = self.col.usn()
|
self.usn = self.col.usn()
|
||||||
# bug check
|
# bug check
|
||||||
if self.queue == QUEUE_TYPE_REV and self.odue and not self.col.decks.isDyn(self.did):
|
if (
|
||||||
|
self.queue == QUEUE_TYPE_REV
|
||||||
|
and self.odue
|
||||||
|
and not self.col.decks.isDyn(self.did)
|
||||||
|
):
|
||||||
hooks.card_odue_was_invalid()
|
hooks.card_odue_was_invalid()
|
||||||
assert self.due < 4294967296
|
assert self.due < 4294967296
|
||||||
self.col.db.execute(
|
self.col.db.execute(
|
||||||
|
@ -120,7 +124,11 @@ insert or replace into cards values
|
||||||
self.mod = intTime()
|
self.mod = intTime()
|
||||||
self.usn = self.col.usn()
|
self.usn = self.col.usn()
|
||||||
# bug checks
|
# bug checks
|
||||||
if self.queue == QUEUE_TYPE_REV and self.odue and not self.col.decks.isDyn(self.did):
|
if (
|
||||||
|
self.queue == QUEUE_TYPE_REV
|
||||||
|
and self.odue
|
||||||
|
and not self.col.decks.isDyn(self.did)
|
||||||
|
):
|
||||||
hooks.card_odue_was_invalid()
|
hooks.card_odue_was_invalid()
|
||||||
assert self.due < 4294967296
|
assert self.due < 4294967296
|
||||||
self.col.db.execute(
|
self.col.db.execute(
|
||||||
|
|
|
@ -344,7 +344,10 @@ class Anki2Importer(Importer):
|
||||||
card[4] = intTime()
|
card[4] = intTime()
|
||||||
card[5] = usn
|
card[5] = usn
|
||||||
# review cards have a due date relative to collection
|
# review cards have a due date relative to collection
|
||||||
if card[7] in (QUEUE_TYPE_REV, QUEUE_TYPE_DAY_LEARN_RELEARN) or card[6] == CARD_TYPE_REV:
|
if (
|
||||||
|
card[7] in (QUEUE_TYPE_REV, QUEUE_TYPE_DAY_LEARN_RELEARN)
|
||||||
|
or card[6] == CARD_TYPE_REV
|
||||||
|
):
|
||||||
card[8] -= aheadBy
|
card[8] -= aheadBy
|
||||||
# odue needs updating too
|
# odue needs updating too
|
||||||
if card[14]:
|
if card[14]:
|
||||||
|
|
|
@ -153,14 +153,21 @@ order by due"""
|
||||||
def unburyCards(self):
|
def unburyCards(self):
|
||||||
"Unbury cards."
|
"Unbury cards."
|
||||||
self.col.conf["lastUnburied"] = self.today
|
self.col.conf["lastUnburied"] = self.today
|
||||||
self.col.log(self.col.db.list(f"select id from cards where queue = {QUEUE_TYPE_SIBLING_BURIED}"))
|
self.col.log(
|
||||||
self.col.db.execute(f"update cards set queue=type where queue = {QUEUE_TYPE_SIBLING_BURIED}")
|
self.col.db.list(
|
||||||
|
f"select id from cards where queue = {QUEUE_TYPE_SIBLING_BURIED}"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.col.db.execute(
|
||||||
|
f"update cards set queue=type where queue = {QUEUE_TYPE_SIBLING_BURIED}"
|
||||||
|
)
|
||||||
|
|
||||||
def unburyCardsForDeck(self):
|
def unburyCardsForDeck(self):
|
||||||
sids = ids2str(self.col.decks.active())
|
sids = ids2str(self.col.decks.active())
|
||||||
self.col.log(
|
self.col.log(
|
||||||
self.col.db.list(
|
self.col.db.list(
|
||||||
f"select id from cards where queue = {QUEUE_TYPE_SIBLING_BURIED} and did in %s" % sids
|
f"select id from cards where queue = {QUEUE_TYPE_SIBLING_BURIED} and did in %s"
|
||||||
|
% sids
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.col.db.execute(
|
self.col.db.execute(
|
||||||
|
@ -746,7 +753,10 @@ where queue in ({QUEUE_TYPE_LRN},{QUEUE_TYPE_DAY_LEARN_RELEARN}) and type = {CAR
|
||||||
)
|
)
|
||||||
# new cards in learning
|
# new cards in learning
|
||||||
self.forgetCards(
|
self.forgetCards(
|
||||||
self.col.db.list(f"select id from cards where queue in ({QUEUE_TYPE_LRN},{QUEUE_TYPE_DAY_LEARN_RELEARN}) %s" % extra)
|
self.col.db.list(
|
||||||
|
f"select id from cards where queue in ({QUEUE_TYPE_LRN},{QUEUE_TYPE_DAY_LEARN_RELEARN}) %s"
|
||||||
|
% extra
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def _lrnForDeck(self, did):
|
def _lrnForDeck(self, did):
|
||||||
|
@ -1321,14 +1331,18 @@ To study outside of the normal schedule, click the Custom Study button below."""
|
||||||
def newDue(self):
|
def newDue(self):
|
||||||
"True if there are any new cards due."
|
"True if there are any new cards due."
|
||||||
return self.col.db.scalar(
|
return self.col.db.scalar(
|
||||||
(f"select 1 from cards where did in %s and queue = {QUEUE_TYPE_NEW} " "limit 1")
|
(
|
||||||
|
f"select 1 from cards where did in %s and queue = {QUEUE_TYPE_NEW} "
|
||||||
|
"limit 1"
|
||||||
|
)
|
||||||
% self._deckLimit()
|
% self._deckLimit()
|
||||||
)
|
)
|
||||||
|
|
||||||
def haveBuried(self):
|
def haveBuried(self):
|
||||||
sdids = ids2str(self.col.decks.active())
|
sdids = ids2str(self.col.decks.active())
|
||||||
cnt = self.col.db.scalar(
|
cnt = self.col.db.scalar(
|
||||||
f"select 1 from cards where queue = {QUEUE_TYPE_SIBLING_BURIED} and did in %s limit 1" % sdids
|
f"select 1 from cards where queue = {QUEUE_TYPE_SIBLING_BURIED} and did in %s limit 1"
|
||||||
|
% sdids
|
||||||
)
|
)
|
||||||
return not not cnt
|
return not not cnt
|
||||||
|
|
||||||
|
@ -1391,7 +1405,8 @@ To study outside of the normal schedule, click the Custom Study button below."""
|
||||||
self.remFromDyn(ids)
|
self.remFromDyn(ids)
|
||||||
self.removeLrn(ids)
|
self.removeLrn(ids)
|
||||||
self.col.db.execute(
|
self.col.db.execute(
|
||||||
f"update cards set queue={QUEUE_TYPE_SUSPENDED},mod=?,usn=? where id in " + ids2str(ids),
|
f"update cards set queue={QUEUE_TYPE_SUSPENDED},mod=?,usn=? where id in "
|
||||||
|
+ ids2str(ids),
|
||||||
intTime(),
|
intTime(),
|
||||||
self.col.usn(),
|
self.col.usn(),
|
||||||
)
|
)
|
||||||
|
@ -1462,7 +1477,8 @@ and (queue={QUEUE_TYPE_NEW} or (queue={QUEUE_TYPE_REV} and due<=?))""",
|
||||||
# then bury
|
# then bury
|
||||||
if toBury:
|
if toBury:
|
||||||
self.col.db.execute(
|
self.col.db.execute(
|
||||||
f"update cards set queue={QUEUE_TYPE_SIBLING_BURIED},mod=?,usn=? where id in " + ids2str(toBury),
|
f"update cards set queue={QUEUE_TYPE_SIBLING_BURIED},mod=?,usn=? where id in "
|
||||||
|
+ ids2str(toBury),
|
||||||
intTime(),
|
intTime(),
|
||||||
self.col.usn(),
|
self.col.usn(),
|
||||||
)
|
)
|
||||||
|
@ -1479,7 +1495,10 @@ and (queue={QUEUE_TYPE_NEW} or (queue={QUEUE_TYPE_REV} and due<=?))""",
|
||||||
" where id in " + ids2str(ids),
|
" where id in " + ids2str(ids),
|
||||||
STARTING_FACTOR,
|
STARTING_FACTOR,
|
||||||
)
|
)
|
||||||
pmax = self.col.db.scalar(f"select max(due) from cards where type={CARD_TYPE_NEW}") or 0
|
pmax = (
|
||||||
|
self.col.db.scalar(f"select max(due) from cards where type={CARD_TYPE_NEW}")
|
||||||
|
or 0
|
||||||
|
)
|
||||||
# takes care of mod + usn
|
# takes care of mod + usn
|
||||||
self.sortCards(ids, start=pmax + 1)
|
self.sortCards(ids, start=pmax + 1)
|
||||||
self.col.log(ids)
|
self.col.log(ids)
|
||||||
|
@ -1515,7 +1534,8 @@ usn=:usn,mod=:mod,factor=:fact where id=:id""",
|
||||||
sids = ids2str(ids)
|
sids = ids2str(ids)
|
||||||
# we want to avoid resetting due number of existing new cards on export
|
# we want to avoid resetting due number of existing new cards on export
|
||||||
nonNew = self.col.db.list(
|
nonNew = self.col.db.list(
|
||||||
f"select id from cards where id in %s and (queue != {QUEUE_TYPE_NEW} or type != {CARD_TYPE_NEW})" % sids
|
f"select id from cards where id in %s and (queue != {QUEUE_TYPE_NEW} or type != {CARD_TYPE_NEW})"
|
||||||
|
% sids
|
||||||
)
|
)
|
||||||
# reset all cards
|
# reset all cards
|
||||||
self.col.db.execute(
|
self.col.db.execute(
|
||||||
|
|
|
@ -1516,7 +1516,10 @@ To study outside of the normal schedule, click the Custom Study button below."""
|
||||||
def newDue(self) -> Any:
|
def newDue(self) -> Any:
|
||||||
"True if there are any new cards due."
|
"True if there are any new cards due."
|
||||||
return self.col.db.scalar(
|
return self.col.db.scalar(
|
||||||
(f"select 1 from cards where did in %s and queue = {QUEUE_TYPE_NEW} " "limit 1")
|
(
|
||||||
|
f"select 1 from cards where did in %s and queue = {QUEUE_TYPE_NEW} "
|
||||||
|
"limit 1"
|
||||||
|
)
|
||||||
% self._deckLimit()
|
% self._deckLimit()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1613,7 +1616,8 @@ end)
|
||||||
"Suspend cards."
|
"Suspend cards."
|
||||||
self.col.log(ids)
|
self.col.log(ids)
|
||||||
self.col.db.execute(
|
self.col.db.execute(
|
||||||
f"update cards set queue={QUEUE_TYPE_SUSPENDED},mod=?,usn=? where id in " + ids2str(ids),
|
f"update cards set queue={QUEUE_TYPE_SUSPENDED},mod=?,usn=? where id in "
|
||||||
|
+ ids2str(ids),
|
||||||
intTime(),
|
intTime(),
|
||||||
self.col.usn(),
|
self.col.usn(),
|
||||||
)
|
)
|
||||||
|
@ -1622,7 +1626,9 @@ end)
|
||||||
"Unsuspend cards."
|
"Unsuspend cards."
|
||||||
self.col.log(ids)
|
self.col.log(ids)
|
||||||
self.col.db.execute(
|
self.col.db.execute(
|
||||||
(f"update cards set %s,mod=?,usn=? where queue = {QUEUE_TYPE_SUSPENDED} and id in %s")
|
(
|
||||||
|
f"update cards set %s,mod=?,usn=? where queue = {QUEUE_TYPE_SUSPENDED} and id in %s"
|
||||||
|
)
|
||||||
% (self._restoreQueueSnippet, ids2str(ids)),
|
% (self._restoreQueueSnippet, ids2str(ids)),
|
||||||
intTime(),
|
intTime(),
|
||||||
self.col.usn(),
|
self.col.usn(),
|
||||||
|
@ -1733,7 +1739,10 @@ and (queue={QUEUE_TYPE_NEW} or (queue={QUEUE_TYPE_REV} and due<=?))""",
|
||||||
" where id in " + ids2str(ids),
|
" where id in " + ids2str(ids),
|
||||||
STARTING_FACTOR,
|
STARTING_FACTOR,
|
||||||
)
|
)
|
||||||
pmax = self.col.db.scalar(f"select max(due) from cards where type={CARD_TYPE_NEW}") or 0
|
pmax = (
|
||||||
|
self.col.db.scalar(f"select max(due) from cards where type={CARD_TYPE_NEW}")
|
||||||
|
or 0
|
||||||
|
)
|
||||||
# takes care of mod + usn
|
# takes care of mod + usn
|
||||||
self.sortCards(ids, start=pmax + 1)
|
self.sortCards(ids, start=pmax + 1)
|
||||||
self.col.log(ids)
|
self.col.log(ids)
|
||||||
|
@ -1769,7 +1778,8 @@ usn=:usn,mod=:mod,factor=:fact where id=:id""",
|
||||||
sids = ids2str(ids)
|
sids = ids2str(ids)
|
||||||
# we want to avoid resetting due number of existing new cards on export
|
# we want to avoid resetting due number of existing new cards on export
|
||||||
nonNew = self.col.db.list(
|
nonNew = self.col.db.list(
|
||||||
f"select id from cards where id in %s and (queue != {QUEUE_TYPE_NEW} or type != {CARD_TYPE_NEW})" % sids
|
f"select id from cards where id in %s and (queue != {QUEUE_TYPE_NEW} or type != {CARD_TYPE_NEW})"
|
||||||
|
% sids
|
||||||
)
|
)
|
||||||
# reset all cards
|
# reset all cards
|
||||||
self.col.db.execute(
|
self.col.db.execute(
|
||||||
|
@ -1933,7 +1943,9 @@ where queue < {QUEUE_TYPE_NEW}"""
|
||||||
# adding 'hard' in v2 scheduler means old ease entries need shifting
|
# adding 'hard' in v2 scheduler means old ease entries need shifting
|
||||||
# up or down
|
# up or down
|
||||||
def _remapLearningAnswers(self, sql: str) -> None:
|
def _remapLearningAnswers(self, sql: str) -> None:
|
||||||
self.col.db.execute(f"update revlog set %s and type in ({CARD_TYPE_NEW},{CARD_TYPE_REV})" % sql)
|
self.col.db.execute(
|
||||||
|
f"update revlog set %s and type in ({CARD_TYPE_NEW},{CARD_TYPE_REV})" % sql
|
||||||
|
)
|
||||||
|
|
||||||
def moveToV1(self) -> None:
|
def moveToV1(self) -> None:
|
||||||
self._emptyAllFiltered()
|
self._emptyAllFiltered()
|
||||||
|
|
|
@ -337,7 +337,9 @@ class DataModel(QAbstractTableModel):
|
||||||
date = c.due
|
date = c.due
|
||||||
elif c.queue == QUEUE_TYPE_NEW or c.type == CARD_TYPE_NEW:
|
elif c.queue == QUEUE_TYPE_NEW or c.type == CARD_TYPE_NEW:
|
||||||
return str(c.due)
|
return str(c.due)
|
||||||
elif c.queue in (QUEUE_TYPE_REV, QUEUE_TYPE_DAY_LEARN_RELEARN) or (c.type == CARD_TYPE_REV and c.queue < 0):
|
elif c.queue in (QUEUE_TYPE_REV, QUEUE_TYPE_DAY_LEARN_RELEARN) or (
|
||||||
|
c.type == CARD_TYPE_REV and c.queue < 0
|
||||||
|
):
|
||||||
date = time.time() + ((c.due - self.col.sched.today) * 86400)
|
date = time.time() + ((c.due - self.col.sched.today) * 86400)
|
||||||
else:
|
else:
|
||||||
return ""
|
return ""
|
||||||
|
@ -1936,7 +1938,8 @@ update cards set usn=?, mod=?, did=? where id in """
|
||||||
def _reposition(self):
|
def _reposition(self):
|
||||||
cids = self.selectedCards()
|
cids = self.selectedCards()
|
||||||
cids2 = self.col.db.list(
|
cids2 = self.col.db.list(
|
||||||
f"select id from cards where type = {CARD_TYPE_NEW} and id in " + ids2str(cids)
|
f"select id from cards where type = {CARD_TYPE_NEW} and id in "
|
||||||
|
+ ids2str(cids)
|
||||||
)
|
)
|
||||||
if not cids2:
|
if not cids2:
|
||||||
return showInfo(_("Only new cards can be repositioned."))
|
return showInfo(_("Only new cards can be repositioned."))
|
||||||
|
|
Loading…
Reference in a new issue