示例#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 register(self, func, label):
        if not callable(func):
            raise ValueError('%r must be a callable' % func)

        if is_old_style_action(func):
            warnings.warn('The formmodel action "%s" is missing the third '
                          'argument "request". You should update your code to '
                          'match action(form_model, form, request).' % label,
                          RemovedIn06Warning)

        func.label = label
        key = '%s.%s' % (func.__module__, func.__name__)
        self._actions[key] = func
示例#3
0
    def register(self, func, label):
        if not callable(func):
            raise ValueError("%r must be a callable" % func)

        if is_old_style_action(func):
            warnings.warn(
                'The formmodel action "%s" is missing the third '
                'argument "request". You should update your code to '
                "match action(form_model, form, request)." % label,
                DeprecationWarning,
            )

        func.label = label
        key = "%s.%s" % (func.__module__, func.__name__)
        self._actions[key] = func
示例#4
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 = {}
        for actionkey in self.form_model.actions:
            action = action_registry.get(actionkey)
            if action is None:
                continue
            args = (self.form_model, form)

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

            self.action_results[actionkey] = action(*args)
        messages.success(self.request,
            _('Thank you for submitting this form.'))
        return super(DynamicFormView, self).form_valid(form)
示例#5
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 = {}
        for actionkey in self.form_model.actions:
            action = action_registry.get(actionkey)
            if action is None:
                continue
            args = (self.form_model, form)

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

            self.action_results[actionkey] = action(*args)
        messages.success(self.request,
                         _('Thank you for submitting this form.'))
        return super(DynamicFormView, self).form_valid(form)