# `CardType`

class mnemosyne.libmnemosyne.card_type.CardType(component_manager, **kwds)

  A card type groups a number of fact views on a certain fact, thereby forming a set of sister 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 is done in self.fact_keys_and_names, 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.

  Keys which need to be different for all facts belonging to this card type are listed in ‘unique_fact_keys’.

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

  The functions ‘create_sister_cards’ and ‘edit_fact’ can be overridden by card types which can have a varying number of fact views, e.g. the cloze card type.

  component_type = 'card_type'
  create_sister_cards(fact)

    Initial grading of cards and storing in the database should not happen here, but is done in the main controller.

  edit_fact(fact, new_fact_data)

    If for the card type this operation results in edited, added or deleted card data apart from the edited fact data from which they derive, these should be returned here, so that they can be taken into account in the database storage.

    Initial grading of cards and storing in the database should not happen here, but is done in the main controller.

  extra_data = {}
  fact_data(card)

    Returns the data in fact of a card. Normally. this is just ‘card.fact.data’, but specialty card types (e.g. the cloze card type) can override this.

  fact_key_format_proxies()

    Sometimes, a card type can dynamically create a key when generating a question or an answer (see e.g. the cloze card type). Since the user cannot specify how this key should be formatted, it should be formatted like an other, static key. This function returns a dictionary with this correspondence.

  fact_key_names()
  fact_key_with_name(name)
  fact_keys()
  fact_keys_and_names = None
  fact_views = None
  hidden_from_UI = False
  id = '-1'
  is_fact_data_valid(fact_data)

    Check if all the required keys are present.

  keyboard_shortcuts = {}
  name = ''
  name_for_fact_key(key)
  render_answer(card, render_chain='default', **render_args)
  render_question(card, render_chain='default', **render_args)
  required_fact_keys = None
  unique_fact_keys = None