* Added the ability to suspend/unsuspend cards.
* Added the ability to add/remove tags.
This commit is contained in:
parent
28ad457773
commit
e582d8284b
@ -412,6 +412,16 @@ class CollectionHandler(RestHandlerBase):
|
||||
|
||||
col.sched.answerCard(card, ease)
|
||||
|
||||
@noReturnValue
|
||||
def suspend_cards(self, col, req):
|
||||
card_ids = req.data['ids']
|
||||
col.sched.suspendCards(card_ids)
|
||||
|
||||
@noReturnValue
|
||||
def unsuspend_cards(self, col, req):
|
||||
card_ids = req.data['ids']
|
||||
col.sched.unsuspendCards(card_ids)
|
||||
|
||||
#
|
||||
# GLOBAL / MISC
|
||||
#
|
||||
@ -509,6 +519,20 @@ class NoteHandler(RestHandlerBase):
|
||||
note = col.getNote(req.ids[1])
|
||||
return self._serialize(note)
|
||||
|
||||
@noReturnValue
|
||||
def add_tags(self, col, req):
|
||||
note = col.getNote(req.ids[1])
|
||||
for tag in req.data['tags']:
|
||||
note.addTag(tag)
|
||||
note.flush()
|
||||
|
||||
@noReturnValue
|
||||
def remove_tags(self, col, req):
|
||||
note = col.getNote(req.ids[1])
|
||||
for tag in req.data['tags']:
|
||||
note.delTag(tag)
|
||||
note.flush()
|
||||
|
||||
class DeckHandler(RestHandlerBase):
|
||||
"""Default handler group for 'deck' type."""
|
||||
|
||||
@ -573,6 +597,22 @@ class CardHandler(RestHandlerBase):
|
||||
card = col.getCard(req.ids[1])
|
||||
return self._serialize(card, req.data)
|
||||
|
||||
def _forward_to_note(self, card_id, name):
|
||||
card = col.getCard(card_id)
|
||||
|
||||
req_copy = req.copy()
|
||||
req_copy.ids[1] = card.nid
|
||||
|
||||
return self.app.execute_handler('note', name, col, req)
|
||||
|
||||
@noReturnValue
|
||||
def add_tags(self, col, req):
|
||||
self._forward_to_note(req.ids[1], 'add_tags')
|
||||
|
||||
@noReturnValue
|
||||
def remove_tags(self, col, req):
|
||||
self._forward_to_note(req.ids[1], 'remove_tags')
|
||||
|
||||
# Our entry point
|
||||
def make_app(global_conf, **local_conf):
|
||||
# TODO: we should setup the default language from conf!
|
||||
|
||||
@ -349,6 +349,28 @@ class CollectionHandlerTest(CollectionTestBase):
|
||||
card = self.execute('next_card', {})
|
||||
self.assertEqual(card['reps'], 1)
|
||||
|
||||
def test_suspend_cards(self):
|
||||
# add a note programatically
|
||||
self.add_default_note()
|
||||
|
||||
# get the id for the one card on this collection
|
||||
card_id = self.collection.findCards('')[0]
|
||||
|
||||
# suspend it
|
||||
self.execute('suspend_cards', {'ids': [card_id]})
|
||||
|
||||
# test that getting the next card will be None
|
||||
card = self.collection.sched.getCard()
|
||||
self.assertEqual(card, None)
|
||||
|
||||
# unsuspend it
|
||||
self.execute('unsuspend_cards', {'ids': [card_id]})
|
||||
|
||||
# test that now we're getting the next card!
|
||||
self.collection.sched.reset()
|
||||
card = self.collection.sched.getCard()
|
||||
self.assertEqual(card.id, card_id)
|
||||
|
||||
class ImportExportHandlerTest(CollectionTestBase):
|
||||
export_rows = [
|
||||
['Card front 1', 'Card back 1', 'Tag1 Tag2'],
|
||||
@ -431,6 +453,30 @@ class NoteHandlerTest(CollectionTestBase):
|
||||
self.assertEqual(ret['string_tags'], 'Tag1 Tag2')
|
||||
self.assertEqual(ret['usn'], -1)
|
||||
|
||||
def test_add_tags(self):
|
||||
self.add_default_note()
|
||||
note_id = self.collection.findNotes('')[0]
|
||||
note = self.collection.getNote(note_id)
|
||||
self.assertFalse('NT1' in note.tags)
|
||||
self.assertFalse('NT2' in note.tags)
|
||||
|
||||
self.execute('add_tags', {'tags': ['NT1', 'NT2']}, note_id)
|
||||
note = self.collection.getNote(note_id)
|
||||
self.assertTrue('NT1' in note.tags)
|
||||
self.assertTrue('NT2' in note.tags)
|
||||
|
||||
def test_remove_tags(self):
|
||||
self.add_default_note()
|
||||
note_id = self.collection.findNotes('')[0]
|
||||
note = self.collection.getNote(note_id)
|
||||
self.assertTrue('Tag1' in note.tags)
|
||||
self.assertTrue('Tag2' in note.tags)
|
||||
|
||||
self.execute('remove_tags', {'tags': ['Tag1', 'Tag2']}, note_id)
|
||||
note = self.collection.getNote(note_id)
|
||||
self.assertFalse('Tag1' in note.tags)
|
||||
self.assertFalse('Tag2' in note.tags)
|
||||
|
||||
class DeckHandlerTest(CollectionTestBase):
|
||||
def setUp(self):
|
||||
super(DeckHandlerTest, self).setUp()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user