Reformatting through black

This commit is contained in:
Arthur Milchior 2020-01-31 00:58:03 -08:00
parent 957f0c8e8b
commit 35c8f21eb6
5 changed files with 67 additions and 21 deletions

View File

@ -88,7 +88,11 @@ class Card:
self.mod = intTime()
self.usn = self.col.usn()
# 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()
assert self.due < 4294967296
self.col.db.execute(
@ -120,7 +124,11 @@ insert or replace into cards values
self.mod = intTime()
self.usn = self.col.usn()
# 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()
assert self.due < 4294967296
self.col.db.execute(

View File

@ -344,7 +344,10 @@ class Anki2Importer(Importer):
card[4] = intTime()
card[5] = usn
# 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
# odue needs updating too
if card[14]:

View File

@ -153,14 +153,21 @@ order by due"""
def unburyCards(self):
"Unbury cards."
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.db.execute(f"update cards set queue=type where queue = {QUEUE_TYPE_SIBLING_BURIED}")
self.col.log(
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):
sids = ids2str(self.col.decks.active())
self.col.log(
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(
@ -746,7 +753,10 @@ where queue in ({QUEUE_TYPE_LRN},{QUEUE_TYPE_DAY_LEARN_RELEARN}) and type = {CAR
)
# new cards in learning
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):
@ -1321,14 +1331,18 @@ To study outside of the normal schedule, click the Custom Study button below."""
def newDue(self):
"True if there are any new cards due."
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()
)
def haveBuried(self):
sdids = ids2str(self.col.decks.active())
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
@ -1391,7 +1405,8 @@ To study outside of the normal schedule, click the Custom Study button below."""
self.remFromDyn(ids)
self.removeLrn(ids)
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(),
self.col.usn(),
)
@ -1462,7 +1477,8 @@ and (queue={QUEUE_TYPE_NEW} or (queue={QUEUE_TYPE_REV} and due<=?))""",
# then bury
if toBury:
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(),
self.col.usn(),
)
@ -1479,7 +1495,10 @@ and (queue={QUEUE_TYPE_NEW} or (queue={QUEUE_TYPE_REV} and due<=?))""",
" where id in " + ids2str(ids),
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
self.sortCards(ids, start=pmax + 1)
self.col.log(ids)
@ -1515,7 +1534,8 @@ usn=:usn,mod=:mod,factor=:fact where id=:id""",
sids = ids2str(ids)
# we want to avoid resetting due number of existing new cards on export
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
self.col.db.execute(

View File

@ -1516,7 +1516,10 @@ To study outside of the normal schedule, click the Custom Study button below."""
def newDue(self) -> Any:
"True if there are any new cards due."
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()
)
@ -1613,7 +1616,8 @@ end)
"Suspend cards."
self.col.log(ids)
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(),
self.col.usn(),
)
@ -1622,7 +1626,9 @@ end)
"Unsuspend cards."
self.col.log(ids)
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)),
intTime(),
self.col.usn(),
@ -1733,7 +1739,10 @@ and (queue={QUEUE_TYPE_NEW} or (queue={QUEUE_TYPE_REV} and due<=?))""",
" where id in " + ids2str(ids),
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
self.sortCards(ids, start=pmax + 1)
self.col.log(ids)
@ -1769,7 +1778,8 @@ usn=:usn,mod=:mod,factor=:fact where id=:id""",
sids = ids2str(ids)
# we want to avoid resetting due number of existing new cards on export
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
self.col.db.execute(
@ -1933,7 +1943,9 @@ where queue < {QUEUE_TYPE_NEW}"""
# adding 'hard' in v2 scheduler means old ease entries need shifting
# up or down
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:
self._emptyAllFiltered()

View File

@ -337,7 +337,9 @@ class DataModel(QAbstractTableModel):
date = c.due
elif c.queue == QUEUE_TYPE_NEW or c.type == CARD_TYPE_NEW:
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)
else:
return ""
@ -1936,7 +1938,8 @@ update cards set usn=?, mod=?, did=? where id in """
def _reposition(self):
cids = self.selectedCards()
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:
return showInfo(_("Only new cards can be repositioned."))