예제 #1
0
    def save(self, *args, **kwargs):
        if not self.name:
            self.name = slugify(self.label)

        given_options = self.options
        field_type_cls = dynamic_form_field_registry.get(self.field_type)
        invalid = set(self.options.keys()) - set(field_type_cls._meta.keys())
        if invalid:
            for key in invalid:
                del given_options[key]
            self.options = given_options

        return super(FormFieldModel, self).save(*args, **kwargs)
예제 #2
0
 def __init__(self, *args, **kwargs):
     instance = kwargs.get('instance', None)
     meta = None
     if instance:
         df = dynamic_form_field_registry.get(instance.field_type)
         if df:
             meta = df._meta
     super(AdminFormFieldInlineForm, self).__init__(*args, **kwargs)
     if meta is not None:
         self.fields['_options'] = OptionsField(meta, required=False,
             label=_('Options'))
     else:
         self.fields['_options'].widget = ReadOnlyWidget(show_text=_(
             'The options for this field will be available once it has '
             'been stored the first time.'
         ))
예제 #3
0
 def generate_form_field(self, form):
     field_type_cls = dynamic_form_field_registry.get(self.field_type)
     field = field_type_cls(**self.get_form_field_kwargs())
     field.contribute_to_form(form)
     return field
예제 #4
0
 def test_get_default_action(self):
     self.assertEqual(registry.get(self.key % 'BooleanField'), BooleanField)
     self.assertEqual(registry.get(self.key % 'ChoiceField'), ChoiceField)
예제 #5
0
    def test_unregister(self):
        key = 'tests.test_formfields.CharField'
        registry.register(CharField)
        registry.unregister(key)

        self.assertIsNone(registry.get(key))
예제 #6
0
 def test_register(self):
     registry.register(CharField)
     cls = registry.get('tests.test_formfields.CharField')
     self.assertEqual(cls, CharField)
     self.assertEqual(cls.get_display_type(), 'Char')