def test_unregister(self): action_registry.register(some_action, 'My Label') action_registry.unregister(self.key3) self.assertIsNone(action_registry.get(self.key3)) choices = sorted(action_registry.get_as_choices(), key=lambda x: x[1]) self.assertEqual(choices, [('dynamic_forms.actions.dynamic_form_send_email', 'Send via email'), ('dynamic_forms.actions.dynamic_form_store_database', 'Store in database')])
def test_unregister(self): action_registry.register(some_action, 'My Label') action_registry.unregister(self.key3) self.assertIsNone(action_registry.get(self.key3)) choices = sorted(action_registry.get_as_choices(), key=lambda x: x[1]) self.assertEqual(choices, [ ('dynamic_forms.actions.dynamic_form_send_email', 'Send via email'), ('dynamic_forms.actions.dynamic_form_store_database', 'Store in database') ])
def test_unregister(self): action_registry.register(some_action, "My Label") action_registry.unregister(self.key3) self.assertIsNone(action_registry.get(self.key3)) self.assertEqual( action_registry.get_as_choices(), [ ("dynamic_forms.actions.dynamic_form_send_email", "Send via email"), ("dynamic_forms.actions.dynamic_form_store_database", "Store in database"), ], )
class FormModel(models.Model): name = models.CharField(_('Name'), max_length=50, unique=True) submit_url = models.CharField( _('Submit URL'), max_length=100, unique=True, help_text=_('The full URL path to the form. It should start ' 'and end with a forward slash (<code>/</code>).')) success_url = models.CharField( _('Success URL'), max_length=100, help_text=_( 'The full URL path where the user will be ' 'redirected after successfully sending the form. It should start ' 'and end with a forward slash (<code>/</code>). If empty, the ' 'success URL is generated by appending <code>done/</code> to the ' '“Submit URL”.'), blank=True, default='') actions = TextMultiSelectField(_('Actions'), default='', choices=action_registry.get_as_choices()) form_template = models.CharField( _('Form template path'), max_length=100, default='dynamic_forms/form.html', choices=settings.DYNAMIC_FORMS_FORM_TEMPLATES) success_template = models.CharField( _('Success template path'), max_length=100, default='dynamic_forms/form_success.html', choices=settings.DYNAMIC_FORMS_SUCCESS_TEMPLATES) allow_display = models.BooleanField( _('Allow display'), default=False, help_text=_( 'Allow a user to view the input at a later time. This ' 'requires the “Store in database” action to be active. The sender ' 'will be given a unique URL to recall the data.')) recipient_email = models.EmailField( _('Recipient email'), blank=True, null=True, help_text=_('Email address to send form data.')) class Meta: ordering = ['name'] verbose_name = _('Dynamic form') verbose_name_plural = _('Dynamic forms') def __str__(self): return self.name def get_fields_as_dict(self): """ Returns an ``OrderedDict`` (``SortedDict`` when ``OrderedDict is not available) with all fields associated with this form where their name is the key and their label is the value. """ return OrderedDict(self.fields.values_list('name', 'label').all()) def save(self, *args, **kwargs): """ Makes sure that the ``submit_url`` and -- if defined the ``success_url`` -- end with a forward slash (``'/'``). """ if not self.submit_url.endswith('/'): self.submit_url = self.submit_url + '/' if self.success_url: if not self.success_url.endswith('/'): self.success_url = self.success_url + '/' else: self.success_url = self.submit_url + 'done/' super(FormModel, self).save(*args, **kwargs)
def test_get_default_actions_as_choices(self): choices = sorted(action_registry.get_as_choices(), key=lambda x: x[1]) self.assertEqual(choices, [(self.key1, 'Send via email'), (self.key2, 'Store in database')])
def test_get_default_actions_as_choices(self): choices = sorted(action_registry.get_as_choices(), key=lambda x: x[1]) self.assertEqual(choices, [ (self.key1, 'Send via email'), (self.key2, 'Store in database') ])
def test_get_default_actions_as_choices(self): self.assertEqual( action_registry.get_as_choices(), [(self.key1, "Send via email"), (self.key2, "Store in database")] )