Exemple #1
0
def fill(request, form, template="autoforms/fill.html", success_template="autoforms/fill_done.html"):
    data = request.GET or request.POST
    # is_popup = data.get('is_popup',None)
    is_popup = True
    if request.method == "GET":
        dform = form.as_form()
        return render_to_response(
            template,
            {"title": form.name, "is_popup": is_popup, "form": form, "dform": dform},
            context_instance=RequestContext(request),
        )
    else:
        dform = AutoForm(fields=form.sorted_fields(), data=request.POST)
        if dform.is_valid():
            if form.enable:
                # save the data only form is enable
                fi = FormInstance(_form=form, _name=form.name)
                fi.save(data=dform.cleaned_data)
            return render_to_response(
                success_template,
                {"title": form.name, "is_popup": is_popup, "form": form, "dform": dform},
                context_instance=RequestContext(request),
            )
        else:
            return render_to_response(
                template,
                {"title": form.name, "is_popup": is_popup, "form": form, "dform": dform},
                context_instance=RequestContext(request),
            )
Exemple #2
0
 def persist(self,data):
     """
     usage:
     data = request.POST
     form.persist(data)
     """
     form = self.as_form(data)
     if form.is_valid():
         fi = FormInstance(_form=self,_name=self.name)
         fi.save(form.cleaned_data)
         return fi
     else:
         return None
Exemple #3
0
 def persist(self, data):
     """
     usage:
     data = request.POST
     form.persist(data)
     """
     form = self.as_form(data)
     if form.is_valid():
         fi = FormInstance(_form=self, _name=self.name)
         fi.save(form.cleaned_data)
         return fi
     else:
         return None
Exemple #4
0
def fill(request,form,template='autoforms/fill.html',success_template='autoforms/fill_done.html'):
    data = request.GET or request.POST
    #is_popup = data.get('is_popup',None)
    is_popup = True
    if request.method == 'GET':
        dform = form.as_form()
        return render_to_response(template,{'title':form.name,'is_popup':is_popup,'form':form,'dform':dform},context_instance=RequestContext(request))
    else:
        dform = AutoForm(fields=form.sorted_fields(),data=request.POST)
        if dform.is_valid():
            if form.enable:
                # save the data only form is enable
                fi = FormInstance(_form=form,_name=form.name)
                fi.save(data=dform.cleaned_data)
            return render_to_response(success_template,{'title':form.name,'is_popup':is_popup,'form':form,'dform':dform},context_instance=RequestContext(request))
        else:
            return render_to_response(template,{'title':form.name,'is_popup':is_popup,'form':form,'dform':dform},context_instance=RequestContext(request))