def add_complaint(request): # A HTTP POST? if request.user.is_authenticated(): if request.method == 'POST': form = ComplaintForm(request.POST,request.FILES) # Have we been provided with a valid form? if form.is_valid(): # Save the new category to the database. return confirmview(request) # Now call the index() view. # The user will be shown the homepage. else: # The supplied form contained errors - just print them to the terminal. print form.errors else: # If the request was not a POST, display the form to enter details. form = ComplaintForm() # Bad form (or form details), no form supplied... # Render the form with error messages (if any). return render(request, 'add_form/add_form.html',{'form':form} ) else: render_to_response("Not logged in.")
def confirmview(request): form=ComplaintForm(request.POST,request.FILES) if form.is_valid(): #unnecessary validation fname = form.cleaned_data['fname'] #lname = form.cleaned_data['lname'] office = form.cleaned_data['office'] birth_date = form.cleaned_data['birth_date'] #address = form.cleaned_data['address'] village = form.cleaned_data['village'] taluka = form.cleaned_data['taluka'] #pin = form.cleaned_data['pin'] email = form.cleaned_data['email'] mob = form.cleaned_data['mob'] #ph_areacode = form.cleaned_data['ph_areacode'] #ph_no = form.cleaned_data['ph_no'] complaint_type = form.cleaned_data['complaint_type'] descrip = form.cleaned_data['descrip'] acc_person = form.cleaned_data['acc_person'] status = form.cleaned_data['status'] status_remarks = form.cleaned_data['status_remarks'] filename = request.FILES.getlist('docfile') dict = { 'fname':fname, # 'lname' : lname, 'office' : office, 'birth_date' :birth_date, # 'address' :address, 'village' :village, 'taluka' :taluka, # 'pin' :pin, 'email' :email, 'mob' :mob, #'ph_areacode' :ph_areacode, #'ph_no' :ph_no, 'complaint_type' :complaint_type, 'descrip' :descrip, 'acc_person' :acc_person, 'status' :status, 'status_remarks' :status_remarks, 'filename': filename } form.save() return render(request, 'rango/confirmation.html',dict) else: pass