mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 15:02:21 -04:00
support for shifting
This commit is contained in:
parent
b69031cd4f
commit
7acdbfa9ae
2 changed files with 33 additions and 5 deletions
|
@ -790,7 +790,7 @@ where id = :id""", vals)
|
|||
# Random<->ordered new cards
|
||||
##########################################################################
|
||||
|
||||
def sortCards(self, cids, start=1, step=1, shuffle=False):
|
||||
def sortCards(self, cids, start=1, step=1, shuffle=False, shift=False):
|
||||
scids = ids2str(cids)
|
||||
now = intTime()
|
||||
fids = self.deck.db.list(
|
||||
|
@ -802,6 +802,17 @@ where id = :id""", vals)
|
|||
random.shuffle(fids)
|
||||
for c, fid in enumerate(fids):
|
||||
due[fid] = start+c*step
|
||||
high = start+c*step
|
||||
# shift?
|
||||
if shift:
|
||||
low = self.deck.db.scalar(
|
||||
"select min(due) from cards where due >= ? and type = 0 "
|
||||
"and id not in %s" % scids,
|
||||
start)
|
||||
shiftby = high - low + 1
|
||||
self.deck.db.execute("""
|
||||
update cards set mod=?, due=due+? where id not in %s
|
||||
and due >= ?""" % scids, now, shiftby, low)
|
||||
# reorder cards
|
||||
d = []
|
||||
for id, fid in self.deck.db.execute(
|
||||
|
|
|
@ -693,10 +693,10 @@ def test_reorder():
|
|||
f = d.newFact()
|
||||
f['Front'] = u"one"
|
||||
d.addFact(f)
|
||||
f = d.newFact()
|
||||
f['Front'] = u"two"
|
||||
d.addFact(f)
|
||||
assert f.cards()[0].due == f.id
|
||||
f2 = d.newFact()
|
||||
f2['Front'] = u"two"
|
||||
d.addFact(f2)
|
||||
assert f2.cards()[0].due == f2.id
|
||||
found=False
|
||||
# 50/50 chance of being reordered
|
||||
for i in range(20):
|
||||
|
@ -707,6 +707,23 @@ def test_reorder():
|
|||
assert found
|
||||
d.sched.orderCards()
|
||||
assert f.cards()[0].due == f.id
|
||||
# shifting
|
||||
f3 = d.newFact()
|
||||
f3['Front'] = u"three"
|
||||
d.addFact(f3)
|
||||
f4 = d.newFact()
|
||||
f4['Front'] = u"four"
|
||||
d.addFact(f4)
|
||||
assert f.cards()[0].due == 1
|
||||
assert f2.cards()[0].due == 2
|
||||
assert f3.cards()[0].due == 3
|
||||
assert f4.cards()[0].due == 4
|
||||
d.sched.sortCards([
|
||||
f3.cards()[0].id, f4.cards()[0].id], start=1, shift=True)
|
||||
assert f.cards()[0].due == 3
|
||||
assert f2.cards()[0].due == 4
|
||||
assert f3.cards()[0].due == 1
|
||||
assert f4.cards()[0].due == 2
|
||||
|
||||
def test_forget():
|
||||
d = getEmptyDeck()
|
||||
|
|
Loading…
Reference in a new issue