Skip to content

Commit

Permalink
Fix issues related to new cards.
Browse files Browse the repository at this point in the history
  • Loading branch information
rpearl committed Feb 19, 2017
1 parent 17ca259 commit 7dc03cc
Showing 1 changed file with 51 additions and 9 deletions.
60 changes: 51 additions & 9 deletions catchup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,30 @@ def do_suspend(self):

def get_tagged_cids(self, query=None):
config = mw.col.conf['catchup']
find_query = 'tag:%s' % (config['tag'],)
if query is not None:
find_query = 'tag:%s is:suspended' % (config['tag'],)
if query:
find_query += ' (%s)' % (query,)
cids = mw.col.findCards(find_query, order='c.type, c.due')

return cids

def _fixup_tags(self, unsuspended):
config = mw.col.conf['catchup']
cids = self.get_tagged_cids()
for cid in cids:
if cid in unsuspended:
continue
card = mw.col.getCard(cid)
note = card.note()
note.addTag(config['tag'])
note.flush()

def do_unsuspend(self):
config = mw.col.conf['catchup']

cids = self.get_tagged_cids(query=config['unsuspend_query'])
query = '-is:new '+config['unsuspend_query']

cids = self.get_tagged_cids(query=query)

unsuspended = []

Expand All @@ -140,9 +153,29 @@ def do_unsuspend(self):
note.flush()
unsuspended.append(cid)
mw.col.sched.unsuspendCards(unsuspended)

self._fixup_tags(unsuspended)

self.update_stats()
showInfo('%d cards unsuspended' % len(unsuspended))

def do_unsuspend_new(self):
config = mw.col.conf['catchup']
cids = self.get_tagged_cids(query='is:new')
unsuspended = []
for cid in cids:
card = mw.col.getCard(cid)
note = card.note()
note.delTag(config['tag'])
note.flush()
unsuspended.append(cid)
mw.col.sched.unsuspendCards(unsuspended)
self._fixup_tags(unsuspended)

self.update_stats()
showInfo('%d cards unsuspended' % len(unsuspended))


def set_dirty_config(self):
self.ctl_suspend.setEnabled(False)
self.ctl_unsuspend.setEnabled(False)
Expand All @@ -163,16 +196,23 @@ def update_stats(self):
if config['show_stats']:
days = set()

cids = self.get_tagged_cids()
all_cids = self.get_tagged_cids()
new_behind = 0

for cid in cids:
for cid in all_cids:
card = mw.col.getCard(cid)
days.add(card.due)

if card.type == 2: # review
days.add(card.due)
else:
new_behind += 1
total_behind = len(all_cids)
review_behind = total_behind - new_behind
self.days_behind_label.setText("Days behind")
self.days_behind.setText("%d" % len(days))
self.cards_behind_label.setText("Cards behind")
self.cards_behind.setText("%d" % len(cids))
self.cards_behind.setText("New/Learn: %d\t In review: %d\t Total %d" %
(new_behind, review_behind, total_behind)
)
else:
self.days_behind_label.setText("Intentionally left blank")
self.days_behind.setText("")
Expand Down Expand Up @@ -214,10 +254,12 @@ def __init__(self):

self.add_label("Actions")
self.ctl_suspend = self.add_widget(QPushButton("Suspend overdue cards"), small=True)
self.ctl_unsuspend = self.add_widget(QPushButton("Unsuspend oldest cards"), small=True)
self.ctl_unsuspend = self.add_widget(QPushButton("Unsuspend earliest cards"), small=True)
self.ctl_unsuspend_new = self.add_widget(QPushButton("Unsuspend new/learning cards"), small=True)

self.ctl_suspend.clicked.connect(self.do_suspend)
self.ctl_unsuspend.clicked.connect(self.do_unsuspend)
self.ctl_unsuspend_new.clicked.connect(self.do_unsuspend_new)

self.add_rule()
self.add_widget(QLabel('Check the README for instructions and examples'))
Expand Down

0 comments on commit 7dc03cc

Please sign in to comment.