Exemplo n.º 1
0
 def configure_form(self):
     form_object = FormConfiguration.objects.get(slug=self.slug)
     field_data = pickle_to_data(form_object.fields)
     form_fields = field_data["fields"][FORM_WORKFLOW[self.type]["label"]]
     self.selected_fields = form_fields.keys()
     self.extra_fields = field_data["extra_data"][FORM_WORKFLOW[self.type]["label"]]
     self.mandatory_fields = [x if y.get("mandatory", "0") == "1" else "0" for x, y in form_fields.items()]
     [self.default_form.fields[x].__setattr__("priority", y["priority"]) for x, y in form_fields.items()]
     [self.default_form.fields[x].__setattr__("group", y["group"]) for x, y in form_fields.items()]
     return render_to_response(self.template, self.__dict__, context_instance=RequestContext(self.request))
Exemplo n.º 2
0
    def post_form(self):

        form_object = FormConfiguration.objects.get(slug=self.slug)
        field_dict = pickle_to_data(form_object.fields)
        args_dict = self.request.POST
        field_dict["fields"][FORM_WORKFLOW[self.type]["label"]] = self.add_option_fields(
            self.request.POST.getlist("options")
        )
        field_dict = self.get_extra_fields(field_dict)
        if self.request.POST.get("delete_fields"):
            for label in self.request.POST.getlist("delete_fields"):
                field_dict = self.delete_extra_fields(label, field_dict)
        form_object.fields = data_to_pickle(field_dict)
        form_object.save()
        return HttpResponseRedirect(reverse("configureform", args=[self.slug, self.next]))
Exemplo n.º 3
0
 def get_configured_form(self, form, type, form_object, attrs_dict={}):
     """
     This function will return form with form fields and custom fields
     pass argument attrs_dict={'class':{'label1':'class1'},'onclick':{'label2':'f1'}} for adding extra attributes to field
     """
     field_list = pickle_to_data(form_object.fields)
     dict = {}
     for k, v in form.fields.iteritems():
         if k in field_list["fields"][FORM_WORKFLOW[type]["label"]]:
             v.required = field_list["fields"][FORM_WORKFLOW[type]["label"]][k]
             v.priority = field_list["fields"][FORM_WORKFLOW[type]["label"]][k]["priority"]
             dict.update({k: v})
     form.fields = dict
     dynamic_form = DynamicFormView().get_dynamic_form(field_list["extra_data"][FORM_WORKFLOW[type]["label"]])
     form.fields.update(dynamic_form.fields)
     form = self.add_form_attrs(form, attrs_dict)
     form = self.add_priority(form)
     return form