示例#1
0
    def __init__(self,*args,**kw):
        #print self.__class__.__name__,"__init__()"
        ViewManyReportRenderer.__init__(self,*args,**kw)
        
        fs_args = {}
        if self.report.master is not None:
            formset_class = inlineformset_factory(
                  self.report.master,
                  self.report.model,
                  fk_name=self.report.fk_name,
                  extra=self.extra, 
                  max_num=self.max_num,
                  can_order=self.can_order, 
                  can_delete=self.can_delete)
            fs_args['instance'] = self.master_instance
        else:
            formset_class = modelformset_factory(
                  self.report.model,
                  extra=self.extra, 
                  max_num=self.max_num,
                  can_order=self.can_order, 
                  can_delete=self.can_delete)
            fs_args['queryset'] = self.page.object_list

        
        if self.request.method == 'POST':
            fs = formset_class(self.request.POST,**fs_args)
            if fs.is_valid():
                #print self.__class__.__name__, "valid"
                fs.save()
                if self.can_delete and fs.deleted_forms:
                    for form in fs.deleted_forms:
                        print "Deleted:", form.instance
                #editing.stop_editing(self.request)
                redirect_to(self.request,self.again(editing=0))
                """
                start from begin because paginator and page must reload
                e.g. if an instance has been added, it may now be at 
                a different row and the page count may have changed.
                """
                #return HttpResponseRedirect(self.again(editing=None))
                #redirect_to(self.request,self.again(editing=None))
            else:
                print fs.errors
                editing.continue_editing(self.request)
        else:
            #print self.__class__.__name__, "not POST"
            fs = formset_class(**fs_args)
        self.formset = fs
示例#2
0
 def __init__(self,*args,**kw):
     ViewOneReportRenderer.__init__(self,*args,**kw)
     if self.request.method == 'POST':
         frm = self.report.form_class(self.request.POST,
           instance=self.row.instance)
         if frm.is_valid():
             #print self.__class__.__name__, "valid"
             frm.save()
             #print "SAVED:", self.row.instance
             #editing.stop_editing(self.request)
             redirect_to(self.request,self.again(editing=0))
             #return HttpResponseRedirect(self.again(editing=None))
         else:
             print frm.errors
             editing.continue_editing(self.request)
     else:
         frm = self.report.form_class(instance=self.row.instance)
     self.form = frm
     
     self.row.form = frm