示例#1
0
    def form_valid(self, form):
        """
        Instantiates an empty dict ``self.action_results`` that takes the
        return values of every action that is called, unless the return value
        of that action is ``None``.
        """

        self.action_results = {}
        advert = AdBase.objects.get(id=form.cleaned_data['content'])
        for actionkey in self.form_model.actions:
            action = action_registry.get(actionkey)
            if action is None:
                continue
            args = (self.form_model, form, advert)

            if not is_old_style_action(action):
                args = args + (self.request,)

            self.action_results[actionkey] = action(*args)
        try:
            dl_url = self.request.META['DL_URL']
        except:
            dl_url = ''

        #messages.success(self.request,
        #    _('Thank you for submitting this form.'))
        ctx = {'ad': advert, 'advert': advert, 'dl_url': dl_url}
        success_message = Template(self.form_model.success_message).render(Context(ctx))
        ctx = {'dl_url': dl_url, 'success_message': success_message}
        return render(self.request, self.get_success_template(), ctx)
示例#2
0
 def form_valid(self, form):
     for actionkey in self.form_model.actions:
         action = action_registry.get(actionkey)
         if action is None:
             continue
         action(self.form_model, form)
     messages.success(self.request,
         _('Thank you for submitting this form.'))
     return super(DynamicFormView, self).form_valid(form)
    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')])
示例#4
0
    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"),
            ],
        )
示例#6
0
文件: views.py 项目: Khanos/SoftCode
 def form_valid(self, form):
     """
     Instantiates an empty dict ``self.action_results`` that takes the
     return values of every action that is called, unless the return value
     of that action is ``None``.
     """
     self.action_results = {}
     for actionkey in self.form_model.actions:
         action = action_registry.get(actionkey)
         if action is None:
             continue
         self.action_results[actionkey] = action(self.form_model, form)
     messages.success(self.request,
         _('Thank you for submitting this form.'))
     return super(DynamicFormView, self).form_valid(form)
 def test_register_old(self):
     with warnings.catch_warnings(record=True) as w:
         warnings.simplefilter('always')
         action_registry.register(some_old_action, 'My Old Label')
         warnings.simplefilter('default')
     self.assertEqual(len(w), 2 if sys.version_info[:2] >= (3, 5) else 1)
     self.assertIs(w[-1].category, RemovedIn06Warning)
     self.assertEqual(
         w[-1].message.args[0],
         'The formmodel action "My Old Label" is missing the third argument '
         '"request". You should update your code to match '
         'action(form_model, form, request).')
     func = action_registry.get(self.key4)
     self.assertEqual(func, some_old_action)
     self.assertEqual(func.label, 'My Old Label')
 def test_register_old(self):
     with warnings.catch_warnings(record=True) as w:
         warnings.simplefilter('always')
         action_registry.register(some_old_action, 'My Old Label')
         warnings.simplefilter('default')
     self.assertEqual(len(w), 1)
     self.assertIs(w[0].category, DeprecationWarning)
     self.assertEqual(
         w[0].message.args[0],
         'The formmodel action "My Old Label" is missing the third argument '
         '"request". You should update your code to match '
         'action(form_model, form, request).'
     )
     func = action_registry.get(self.key4)
     self.assertEqual(func, some_old_action)
     self.assertEqual(func.label, 'My Old Label')
 def test_register(self):
     action_registry.register(some_action, 'My Label')
     func = action_registry.get(self.key3)
     self.assertEqual(func, some_action)
     self.assertEqual(func.label, 'My Label')
 def test_get_default_action(self):
     self.assertEqual(action_registry.get(self.key1),
                      dynamic_form_send_email)
     self.assertEqual(action_registry.get(self.key2),
                      dynamic_form_store_database)
示例#11
0
 def test_register(self):
     action_registry.register(some_action, 'My Label')
     func = action_registry.get(self.key3)
     self.assertEqual(func, some_action)
     self.assertEqual(func.label, 'My Label')
示例#12
0
 def test_get_default_action(self):
     self.assertEqual(action_registry.get(self.key1),
         dynamic_form_send_email)
     self.assertEqual(action_registry.get(self.key2),
         dynamic_form_store_database)