Exemple #1
0
 def ajax__plugin_name(self, djp):
     '''
     Ajax post view function which handle the change of pluging within one html block.
     It return JSON serializable object 
     '''
     form = self.get_form(djp, all = False)
     if form.is_valid():
         url        = form.cleaned_data['url']
         instance   = djp.instance
         new_plugin = form.cleaned_data.get('plugin_name',None)
         pform,purl = self.get_plugin_form(djp, new_plugin, withdata = False)
         if pform:
             html = UniForm(pform,tag=False).render(djp)
         else:
             html = u''
         data = jhtmls(identifier = '#%s' % instance.pluginid('options'), html = html)
         preview = self.get_preview(djp.request, instance, url, plugin = new_plugin, wrapped = False)
         data.add('#%s' % instance.pluginid('preview'), preview)
         id = instance.pluginid('edit')
         if callable(new_plugin.edit_form):
             data.add('#%s' % id, type = 'show')
         else:
             data.add('#%s' % id, type = 'hide')
         return data
     else:
         return form.json_errors()
Exemple #2
0
 def handle_post(self, djp, api, user_data):
     f = self.get_form(djp)
     if not f.is_valid():
         return djp.view.error_post(djp,'Error in form')
     msg  = f.cleaned_data['message']
     api.update_status(msg)
     return jhtmls(identifier = '.twitter-box-editor', html = '', type = 'value')
Exemple #3
0
def change_type(self, djp):
    '''Ajax view to change instrument form'''
    form = self.get_form(djp, withdata=False)
    forms = list(form.forms_only())
    if len(forms) == 2:
        form = forms[1]
        html = form.layout.render(form)
    else:
        html = ''
    return jhtmls(html=html, identifier='.data-id-instrument')
Exemple #4
0
def change_type(self, djp):
    '''Ajax view to change instrument form'''
    form = self.get_form(djp, withdata = False)
    forms = list(form.forms_only())
    if len(forms) == 2:
        form = forms[1]
        html = form.layout.render(form)
    else:
        html = ''
    return jhtmls(html = html, identifier = '.data-id-instrument')
Exemple #5
0
    def default_post(self, djp):
        '''View called when changing the content plugin values.
The instance.plugin object is maintained but its fields may change.'''
        # First get the plugin name
        is_ajax = djp.request.is_ajax()
        form = self.get_form(djp, all = False)
        
        if not form.is_valid():
            if is_ajax:
                return form.json_errors()
            else:
                return djp.view.handle_response(djp)
        
        instance = djp.instance
        request = djp.request
        cd = form.cleaned_data
        plugin = cd['plugin_name']
        url = cd['url']
        instance.plugin_name = plugin.name
        
        # Get the full form
        form  =  self.get_form(djp)
        if form.is_valid():
            forms      = list(form.forms_only())
            instance   = form[0].save(commit = False)
            pform = None if len(forms) == 1 else forms[1]
            #pform      = instance.plugin.get_form(djp)
            instance.arguments = instance.plugin.save(pform)
            instance.save()
            # We now serialize the argument form
            if is_ajax:
                page = instance.page
                block = instance.block
                preview = self.get_preview(request, instance, url,  wrapped = False)
                jquery = jhtmls(identifier = '#%s' % instance.pluginid('preview'), html = preview)
                form.add_message(request, "Plugin changed to %s" % instance.plugin.description)
                jquery.update(form.json_message())
                cblocks = self.model.objects.filter(page = page, block = block)
                if instance.position == cblocks.count()-1:
                    b = page.get_block(block)
                    editdjp = self(request, instance = b)
                    html = self.render(editdjp, url = url)
                    wrapper  = EditWrapperHandler(url)
                    html = wrapper(editdjp,b,html)
                    jquery.add('#'+block_htmlid(page.id,block),html,'append')
                return jquery
            else:
                pass 
        else:
            if is_ajax:
                return form.json_errors()
            else:
                pass
Exemple #6
0
 def json_errors(self, withmessage = True):
     '''Serialize form errors for AJAX-JSON interaction.
     '''
     jerr = jhtmls()
     for form in self.forms:
         form = form[1]
         if isinstance(form,BaseForm):
             self._formerrors(jerr, form)
     for formset in self.formsets:
         for form in formset.forms:
             self._formerrors(jerr, form)
     jerr.update(self.json_message())
     return jerr
Exemple #7
0
 def json_message(self):
     msg = self._make_messages('messagelist',self._messages)
     err = self._make_messages('errorlist',self._errors)
     return jhtmls(identifier = '.form-messages', html = msg+err, alldocument = False)
Exemple #8
0
 def get_preview_response(self, djp, url):
     instance = djp.instance
     preview = self.get_preview(djp.request, instance, url,  wrapped = False)
     return jhtmls(identifier = '#%s' % instance.pluginid('preview'), html = preview)
Exemple #9
0
 def edit_block(self, request):
     return jhtmls(identifier = '#' + self.instance.pluginid(),
                   html = self.instance.plugin_edit_block(request))