Пример #1
0
    def test_get_fields(self):
        concept_id = 1
        key = cache.id_key % concept_id
        fkey = cache.field_id_key % concept_id

        self.assertFalse(djcache.has_key(key))
        self.assertFalse(djcache.has_key(fkey))

        fields = cache.get_fields(concept_id)

        self.assertTrue(djcache.has_key(key))
        self.assertEqual(djcache.get(fkey), fields)
Пример #2
0
    def _get_form(self):
        if not hasattr(self, '_form'):
            from avocado.criteria.cache import cache
            form_fields = {}
            fields = cache.get_fields(self.id)

            for f in fields:
                form_fields[f.field_name] = f.formfield()

            class CriterionForm(forms.Form):
                def __init__(self, *args, **kwargs):
                    super(CriterionForm, self).__init__(*args, **kwargs)
                    self.fields.update(form_fields)

            self._form = CriterionForm
        return self._form