Esempio n. 1
0
 def __call__(self, request):
     method = request.method
     if not request.is_xhr:
         # not and AJAX REQUEST
         callable = getattr(self, '%s_response' % method)
     else:
         data = request.REQUEST
         ajax_action = forms.get_ajax_action(data)
         callable = getattr(self, 'ajax_%s_response' % method)
         if ajax_action:
             ajax_view = 'ajax__' + ajax_action
             if hasattr(self, ajax_view):
                 callable = getattr(self, ajax_view)
             else:
                 callable = getattr(self.appmodel, ajax_view, callable)
     return callable(request)
Esempio n. 2
0
 def __call__(self, request):
     method = request.method
     if not request.is_xhr:
         # not and AJAX REQUEST
         callable = getattr(self, "%s_response" % method)
     else:
         data = request.REQUEST
         ajax_action = forms.get_ajax_action(data)
         callable = getattr(self, "ajax_%s_response" % method)
         if ajax_action:
             ajax_view = "ajax__" + ajax_action
             if hasattr(self, ajax_view):
                 callable = getattr(self, ajax_view)
             else:
                 callable = getattr(self.appmodel, ajax_view, callable)
     return callable(request)
Esempio n. 3
0
    def ajax_post_response(self, request, commit=True, plugin_form=True):
        '''View called when changing the content plugin values.
The instance.plugin object is maintained but its fields may change.'''
        fhtml = self.get_form(request, withdata=True)
        form = fhtml.form

        if plugin_form:
            instance = request.instance
            prefix = form.prefix
            if not form.is_valid():
                if commit:
                    return fhtml.maker.json_messages(form)
                else:
                    return ajax.jhtmls(request.environ)
            data = form.cleaned_data
            pform = self.get_plugin_form(request,
                                         data['plugin_name'],
                                         prefix,
                                         withdata=commit)

            #plugin editing form is available
            if pform is not None:
                # if plugin form is bound and has error, returns the errors
                if pform.form.is_bound and not pform.is_valid():
                    return fhtml.maker.json_messages(pform.form)
                # Check what action to perform.
                action = forms.get_ajax_action(request.REQUEST)
                instance = form.submit(commit=commit)
                plugin = instance.plugin
                if action:
                    action_func = getattr(plugin, 'ajax__' + action, None)
                    if action_func:
                        value = forms.get_ajax_action_value(
                            action, request.REQUEST)
                        return action_func(request, value)
                # if committing, we get the arguments from the form
                if commit:
                    instance.arguments = plugin.save(pform.form)
                    instance.save()
                plugin_form = pform.render(request)
            else:
                instance = form.submit(commit=commit)
                plugin_form = ''
            plugin_form = self.plugin_form_container(instance, plugin_form)
            jquery = ajax.jhtmls(request.environ,
                                 identifier='#' + plugin_form.attr('id'),
                                 html=plugin_form.render(request),
                                 type='replacewith')
        else:
            # we are just rerendering the plugin with a different wrapper
            instance = form.submit(commit=commit)
            jquery = ajax.jhtmls(request.environ)

        preview = self.get_preview(request, instance)
        jquery.add('#%s' % instance.pluginid('preview'),
                   html.render(request, preview))

        if plugin_form:
            if commit:
                form.add_message("Plugin changed to %s"\
                                 % instance.plugin.description)

            jquery.update(fhtml.maker.json_messages(form))

        return jquery
Esempio n. 4
0
    def ajax_post_response(self, request, commit=True, plugin_form=True):
        '''View called when changing the content plugin values.
The instance.plugin object is maintained but its fields may change.'''
        fhtml = self.get_form(request, withdata=True)
        form = fhtml.form

        if plugin_form:
            instance = request.instance
            prefix = form.prefix
            if not form.is_valid():
                if commit:
                    return fhtml.maker.json_messages(form)
                else:
                    return ajax.jhtmls(request.environ)
            data = form.cleaned_data
            pform = self.get_plugin_form(request,
                                         data['plugin_name'],
                                         prefix,
                                         withdata=commit)

            #plugin editing form is available
            if pform is not None:
                # if plugin form is bound and has error, returns the errors
                if pform.form.is_bound and not pform.is_valid():
                    return fhtml.maker.json_messages(pform.form)
                # Check what action to perform.
                action = forms.get_ajax_action(request.REQUEST)
                instance = form.submit(commit=commit)
                plugin = instance.plugin
                if action:
                    action_func = getattr(plugin,'ajax__'+action,None)
                    if action_func:
                        value = forms.get_ajax_action_value(action,
                                                            request.REQUEST)
                        return action_func(request, value)
                # if committing, we get the arguments from the form
                if commit:
                    instance.arguments = plugin.save(pform.form)
                    instance.save()
                plugin_form = pform.render(request)
            else:
                instance = form.submit(commit=commit)
                plugin_form = ''
            plugin_form = self.plugin_form_container(instance, plugin_form)
            jquery = ajax.jhtmls(request.environ,
                                 identifier = '#' + plugin_form.attr('id'),
                                 html = plugin_form.render(request),
                                 type = 'replacewith')
        else:
            # we are just rerendering the plugin with a different wrapper
            instance = form.submit(commit=commit)
            jquery = ajax.jhtmls(request.environ)

        preview = self.get_preview(request, instance)
        jquery.add('#%s' % instance.pluginid('preview'),
                   html.render(request, preview))

        if plugin_form:
            if commit:
                form.add_message("Plugin changed to %s"\
                                 % instance.plugin.description)

            jquery.update(fhtml.maker.json_messages(form))

        return jquery