def post(self, request, id): report = get_object_or_404(Report, pk=id) form = ReportForm(request.POST, instance=report) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('reports:detail', args=(report.id, ))) else: params = dict() params['report'] = report params['form'] = form return render(request, 'reports/edit.html', params)
def post(self, request): form = ReportForm(request.POST) if form.is_valid(): form.save() return HttpResponse( json.dumps({ 'success': 1 }), content_type="application/json" ) else: return HttpResponse( json.dumps({ 'success': 0, 'errors': dict(form.errors.items()), }), content_type="application/json" )
def New(request): template_file = "report-new.html" context = RequestContext(request) form = ReportForm(request.POST or None, request.FILES or None) if form.is_valid(): mymodel = form.save() msg = u"Report successfully created" messages.add_message(request, messages.SUCCESS, msg) return redirect("report:home") params = { 'form': form, } return render_to_response ( template_file, params, context_instance = context )
def Edit(request,report_id): template_file = "report-edit.html" context = RequestContext(request) obj = Report.objects.get(pk=report_id) form = ReportForm(request.POST or None, request.FILES or None,instance=obj) if form.is_valid(): mymodel = form.save() msg = u"Eeport saved successfully" messages.add_message(request, messages.SUCCESS, msg) return redirect("report:home") params = { 'form': form, 'report_id': report_id, } return render_to_response ( template_file, params, context_instance = context )