2
# criterion.py <Peter.Bienstman@UGent.be>
5
from mnemosyne.libmnemosyne.utils import rand_uuid
6
from mnemosyne.libmnemosyne.component import Component
9
class Criterion(Component):
11
"""Used to select a subset of cards, e.g. which cards are currently
12
active, i.e. included in the review process.
14
The available Criteria are stored as classes in the component_manager.
16
The actual instances together with their data are stored in the database.
20
component_type = "activity_criterion"
22
instantiate = Component.LATER
24
def __init__(self, component_manager, id=None):
25
Component.__init__(self, component_manager)
32
def apply_to_card(self, card):
34
"""Set the card active or not depending on the criterion. Does not
35
write to the database. Called after creating or updating cards, to
36
see whether these cards should start out their life as active or not.
38
Also called after reviewing a card.
40
The tag and card type creation and deletion function are callbacks
41
called by the rest of libmnemosyne when these objects get created or
42
destroyed, such that Criteria can update their status if needed.
46
raise NotImplementedError
48
def tag_created(self, tag):
51
def tag_deleted(self, tag):
54
def card_type_created(self, card_type):
57
def card_type_deleted(self, card_type):
60
def data_to_string(self):
62
"""Convert variables to a string for storage in the database. We don't
63
use pickle here as that would make it difficult for non-Python programs
68
raise NotImplementedError
70
def set_data_from_string(self, data_string):
71
raise NotImplementedError
73
def data_to_sync_string(self):
75
"""Convert variables to a string for sending across during syncing.
76
Could be different from 'data_to_string', as it should use ids instead
79
raise NotImplementedError
81
def set_data_from_sync_string(self, data_string):
82
raise NotImplementedError
85
class CriterionApplier(Component):
87
"""Can be registered 'used_for' a certain Criterion to apply it in bulk to
88
all the cards in the database. Is much faster than fetching each card from
89
the database, calling Criterion.apply_to_card, and storing it back in the
92
This code is not part of Criterion, because it is dependent on the database
97
component_type = "criterion_applier"
99
def apply_to_database(self, criterion):
100
raise NotImplementedError