def example_email(request): """ this view handles : .serving the form json config based on the django Form (EmailFormExample) .form result processing (POST) """ # set the default form baseform = EmailFormExample # add our stuff ExtJsForm.addto(baseform) if request.method == 'POST': # load the form with supplied data form = baseform(request.POST) if form.is_valid(): print "FORM SUBMITTED, do your custom processing, like sending the email" return utils.JsonSuccess() else: return utils.JsonError(form.html_errorlist()) else: # init a blank form # you can override some default fields values form = baseform(initial = {'message':'the new message text'}) return utils.JsonResponse(form.as_extjs())
def example_model(request): """ this view handles : .serving the form json config based on the django ModelForm (AbstractModelForm) .form result processing (POST) """ # set the default form baseform = AbstractModelExampleForm # add our stuff ExtJsForm.addto(baseform) if request.method == 'POST': # load the form with supplied data form = baseform(request.POST) if form.is_valid(): print "FORM SUBMITTED, do your custom processing, like saving the instance" # here you can bind an instance and update his data (doesnt work with abstract models of course) # form.instance = baseform._meta.model.objects.get(pk = request.POST['pk']) # form.save() # save instance with supplied data return utils.JsonSuccess() else: return utils.JsonError(form.html_errorlist()) else: # init a blank form # you can preload the form with some model instance # instance = baseform._meta.model.objects.get(pk = request.GET['pk']) # or preload the form.inital dict instance = None initial = {'offre':'test offre !!'} form = baseform(instance = instance, initial = initial) return utils.JsonResponse(form.as_extjs())