Skip to content

Commit 9159653

Browse files
authored
Merge pull request #126 from RumovZ/update-for-2.1.45
Update for 2.1.45
2 parents 6d4ea7b + e1a4b57 commit 9159653

File tree

5 files changed

+184
-278
lines changed

5 files changed

+184
-278
lines changed

advancedbrowser/advancedbrowser/advanced_fields.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
from anki.cards import Card
88
from anki.consts import *
99
from anki.hooks import addHook
10-
11-
from aqt.utils import tr
1210
from anki.lang import FormatTimeSpan as FormatTimeSpanContext
11+
1312
from aqt import *
14-
from aqt.utils import askUser
13+
from aqt.operations.card import set_card_flag
14+
from aqt.utils import askUser, tr
1515

1616

1717
class AdvancedFields:
@@ -67,7 +67,7 @@ def cAvgtimeOnData(c, n, t):
6767
avgtime = mw.col.db.scalar(
6868
"select avg(time)/1000.0 from revlog where cid = ?", c.id)
6969
if avgtime:
70-
return mw.col.backend.format_time_span(avgtime)
70+
return mw.col.format_timespan(avgtime)
7171
return None
7272

7373
cc = advBrowser.newCustomColumn(
@@ -84,7 +84,7 @@ def cTottimeOnData(c, n, t):
8484
tottime = mw.col.db.scalar(
8585
"select sum(time)/1000.0 from revlog where cid = ?", c.id)
8686
if tottime:
87-
return mw.col.backend.format_time_span(tottime)
87+
return mw.col.format_timespan(tottime)
8888
return None
8989

9090
cc = advBrowser.newCustomColumn(
@@ -102,7 +102,7 @@ def cFasttimeOnData(c, n, t):
102102
"select time/1000.0 from revlog where cid = ? "
103103
"order by time asc limit 1", c.id)
104104
if tm:
105-
return mw.col.backend.format_time_span(tm)
105+
return mw.col.format_timespan(tm)
106106
return None
107107

108108
# Note: capital ASC required to avoid search+replace
@@ -124,7 +124,7 @@ def cSlowtimeOnData(c, n, t):
124124
"select time/1000.0 from revlog where cid = ? "
125125
"order by time desc limit 1", c.id)
126126
if tm:
127-
return mw.col.backend.format_time_span(tm)
127+
return mw.col.format_timespan(tm)
128128
return None
129129

130130
srt = ("(select time/1000.0 from revlog where cid = c.id "
@@ -143,7 +143,7 @@ def cSlowtimeOnData(c, n, t):
143143
def cOverdueIvl(c, n, t):
144144
val = self.valueForOverdue(c.odid, c.queue, c.type, c.due)
145145
if val:
146-
return mw.col.backend.format_time_span(val * 24 * 60 * 60, context=FormatTimeSpanContext.INTERVALS)
146+
return mw.col.format_timespan(val * 24 * 60 * 60, context=FormatTimeSpanContext.INTERVALS)
147147

148148
srt = (f"""
149149
select
@@ -176,9 +176,9 @@ def cPrevIvl(c, n, t):
176176
elif ivl == 0:
177177
return "0 days"
178178
elif ivl > 0:
179-
return mw.col.backend.format_time_span(ivl*86400, context=FormatTimeSpanContext.INTERVALS)
179+
return mw.col.format_timespan(ivl*86400, context=FormatTimeSpanContext.INTERVALS)
180180
else:
181-
return mw.col.backend.format_time_span(-ivl, context=FormatTimeSpanContext.INTERVALS)
181+
return mw.col.format_timespan(-ivl, context=FormatTimeSpanContext.INTERVALS)
182182

183183
srt = ("(select ivl from revlog where cid = c.id "
184184
"order by id desc limit 1 offset 1) asc nulls last")
@@ -214,7 +214,7 @@ def cPrevDur(c, n, t):
214214
"select time/1000.0 from revlog where cid = ? "
215215
"order by id desc limit 1", c.id)
216216
if time:
217-
return mw.col.backend.format_time_span(time)
217+
return mw.col.format_timespan(time)
218218
return None
219219

220220
srt = ("(select time/1000.0 from revlog where cid = c.id "
@@ -323,20 +323,18 @@ def setData(c: Card, value: str):
323323
try:
324324
value = int(value)
325325
except ValueError:
326-
value = {"":0, "no":0,"red":1, "orange":2, "green":3, "blue":4}.get(value.strip().lower())
326+
value = {"":0, "no":0,"red":1, "orange":2, "green":3, "blue":4, "pink":5, "turquoise":6, "purple":7}.get(value.strip().lower())
327327
if value is None:
328328
return False
329-
if not 0 <= value <= 4:
329+
if not 0 <= value <= 7:
330330
return False
331-
c.setUserFlag(value)
331+
set_card_flag(parent=advBrowser.browser, card_ids=[c.id], flag=value).run_in_background()
332332
return True
333333

334334
cc = advBrowser.newCustomColumn(
335335
type="cflags",
336336
name="Flag",
337-
onData=lambda c, n, t: {1: tr(TR.ACTIONS_RED_FLAG), 2:tr(TR.ACTIONS_ORANGE_FLAG),
338-
3: tr(TR.ACTIONS_GREEN_FLAG), 4:tr(TR.ACTIONS_BLUE_FLAG)}
339-
.get(c.flags, None),
337+
onData=lambda c, n, t: mw.flags.get_flag(c.flags).label if c.flags else None,
340338
onSort=lambda: "(case when c.flags = 0 then null else c.flags end) asc nulls last",
341339
setData=setData,
342340
)

advancedbrowser/advancedbrowser/basic_fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def onAdvBrowserLoad(self, advBrowser):
2828

2929
def setData(c: Card, value: str):
3030
n = c.note()
31-
m = n.model()
31+
m = n.note_type()
3232
if m["type"] == MODEL_CLOZE:
3333
tmpl = m["tmpls"][0]
3434
tmpl_name = tmpl["name"]

0 commit comments

Comments
 (0)