class SimpleVocabularyFactory(object): implements(IVocabularyFactory) def __init__(self, vocab): self.vocab = vocab def __call__(self, context): terms = [SimpleTerm(title=_(title), value=value) for value, title in self.vocab.iteritems()] return SimpleVocabulary(sorted(terms, key=lambda elem: elem.title)) AccountsVocabularyFactory = CatalogVocabularyFactory('FinanceAccount') TransactionsVocabularyFactory = CatalogVocabularyFactory('FinanceTransaction') CategoriesVocabularyFactory = CatalogVocabularyFactory('FinanceCategory') TransfersVocabularyFactory = CatalogVocabularyFactory('FinanceTransfer') currency_vocab = {v.code: v.name for k, v in CURRENCY.iteritems()} CurrenciesVocabularyFactory = SimpleVocabularyFactory(currency_vocab) account_types = { 'Cash': 'Cash', 'Bank': 'Bank', 'CCard': 'Credit Card', 'Invst': 'Investing', 'Oth A': 'Asset', 'Oth L': 'Liability', } AccountTypesVocabularyFactory = SimpleVocabularyFactory(account_types)