def empty_dynamic_deck(self, col, req): name = req.data.get('name', t('Custom Study Session')) deck = col.decks.byName(name) if not deck: raise HTTPBadRequest("Cannot find a deck with the given name: %s" % name) if not deck['dyn']: raise HTTPBadRequest("The given deck is not dynamic: %s" % name) col.sched.emptyDyn(deck['id'])
def _get_answer_buttons(self, col, card): l = [] # Put the correct number of buttons cnt = col.sched.answerButtons(card) for idx in range(0, cnt - 1): l.append(self.button_labels[idx]) l.append('Again') l.reverse() # Loop through and add the ease, estimated time (in seconds) and other info return [{ 'ease': ease, 'label': label, 'string_label': t(label), 'interval': col.sched.nextIvl(card, ease), 'string_interval': col.sched.nextIvlStr(card, ease), } for ease, label in enumerate(l, 1)]
def create_dynamic_deck(self, col, req): name = req.data.get('name', t('Custom Study Session')) deck = col.decks.byName(name) if deck: if not deck['dyn']: raise HTTPBadRequest( "There is an existing non-dynamic deck with the name %s" % name) # safe to empty it because it's a dynamic deck # TODO: maybe this should be an option? col.sched.emptyDyn(deck['id']) else: deck = col.decks.get(col.decks.newDyn(name)) query = req.data.get('query', '') count = int(req.data.get('count', 100)) mode = req.data.get('mode', 'random') try: mode = self.dyn_modes[mode] except KeyError: raise HTTPBadRequest("Unknown mode: %s" % mode) deck['terms'][0] = [query, count, mode] if mode != anki.consts.DYN_RANDOM: deck['resched'] = True else: deck['resched'] = False if not col.sched.rebuildDyn(deck['id']): raise HTTPBadRequest("No cards matched the criteria you provided") col.decks.save(deck) col.sched.reset() return deck
def create_dynamic_deck(self, col, req): name = req.data.get('name', t('Custom Study Session')) deck = col.decks.byName(name) if deck: if not deck['dyn']: raise HTTPBadRequest("There is an existing non-dynamic deck with the name %s" % name) # safe to empty it because it's a dynamic deck # TODO: maybe this should be an option? col.sched.emptyDyn(deck['id']) else: deck = col.decks.get(col.decks.newDyn(name)) query = req.data.get('query', '') count = int(req.data.get('count', 100)) mode = req.data.get('mode', 'random') try: mode = self.dyn_modes[mode] except KeyError: raise HTTPBadRequest("Unknown mode: %s" % mode) deck['terms'][0] = [query, count, mode] if mode != anki.consts.DYN_RANDOM: deck['resched'] = True else: deck['resched'] = False if not col.sched.rebuildDyn(deck['id']): raise HTTPBadRequest("No cards matched the criteria you provided") col.decks.save(deck) col.sched.reset() return deck