CardType

class mnemosyne.libmnemosyne.card_type.CardType(component_manager)

A card type groups a number of fact views on a certain fact, thereby forming a set of related cards.

A card type needs an id as well as a name, because the name can change for different translations.

Inherited card types should have ids where :: separates the different levels of the hierarchy, e.g. parent_id::child_id.

The keys from the fact are also given more verbose names here. This is not done in fact.py, on one hand to save space in the database, and on the other hand to allow the possibility that different card types give different names to the same key. (E.g. foreign word’ could be called ‘French’ in a French card type, or ‘pronunciation’ could be called ‘reading’ in a Kanji card type.) This in done in self.fields, which is a list of the form [(fact_key, fact_key_name)]. It is tempting to use a dictionary here, but we can’t do that since ordering is important.

Fields which need to be different for all facts belonging to this card type are listed in unique_fields.

Note that a fact could contain more data than those listed in the card type’s ‘fields’ variable, which could be useful for card types needing hidden fields.

We could use the component manager to track fact views, but this is probably overkill.

The renderer is determined only when we need it, as opposed to when we create the card type, because it is not sure that the renderer already exists at that stage.

The functions create_related_cards and update_related_cards and after_review provide an extra layer of abstraction and can be overridden by card types like cloze deletion, which require a varying number of fact views with card specific data.

after_repetition(card)
answer(card)
before_repetition(card)
get_renderer()
is_data_valid(fact_data)
key_names()
key_with_name(key_name)
keys()
question(card)
If for the card type this operation results in updated, added or deleted card data apart from the updated fact data from which they derive, these should be returned here, so that they can be taken into account in the database storage.

Previous topic

Tag

Next topic

Card

This Page

Quick search