def create_pro(request): # Login the user user = authenticate(username=request.POST.get('username'), password=request.POST.get('password')) if user and user.is_active: login(request, user) else: return HttpResponseForbidden('invalid username or password') # Create report report_form = ProReportForm(request.POST, prefix='report') comment_form = ReportCommentForm(request.POST, prefix='comment') if not report_form.is_valid(): return HttpResponse(unicode(report_form.errors), status=400) report = report_form.save(commit=False) report.private = True report.save() report.subscribe_author() # Create the comment if exists if ((request.POST["comment-text"] or comment_form.is_valid()) and request.POST["comment-text"] != ''): comment = comment_form.save(commit=False) comment.report = report comment.is_new_report = True comment.save() return report
def create_pro(request, several_occurences=False, mobile_notification=False): # Login the user user = authenticate(username=request.POST.get('username'), password=request.POST.get('password')) if user and user.is_active: login(request, user) else: return HttpResponseForbidden('invalid username or password') # Create report report_form = ProReportForm(request.POST, prefix='report') comment_form = ReportCommentForm(request.POST, prefix='comment') if not report_form.is_valid(): return HttpResponse(unicode(report_form.errors), status=400) report = report_form.save(commit=False) report.private = True report.several_occurences = several_occurences report.mobile_notification = mobile_notification report.save() report.subscribe_author() # Create the comment if exists if ((request.POST["comment-text"] or comment_form.is_valid()) and request.POST["comment-text"] != ''): comment = comment_form.save(commit=False) comment.report = report comment.is_new_report = True comment.save() return report
def new(request): pnt = dict_to_point(request.REQUEST) ReportFileFormSet = inlineformset_factory(Report, ReportFile, form=ReportFileForm, extra=0) report = None if request.method == "POST": report_form = ProReportForm(request.POST, request.FILES, prefix='report') comment_form = ReportCommentForm(request.POST, request.FILES, prefix='comment') fingerprint = RequestFingerprint(request) # this checks update is_valid too if report_form.is_valid() and ( not request.POST["comment-text"] or comment_form.is_valid()) and not fingerprint.is_duplicate(): # this saves the update as part of the report. report = report_form.save(commit=False) # Use `hack_multi_file` instead of ``request.FILES``. file_formset = ReportFileFormSet( request.POST, hack_multi_file(request), instance=report, prefix='files', queryset=ReportFile.objects.none()) if file_formset.is_valid(): user = FMSUser.objects.get(pk=request.user.id) fingerprint.save() report.forceAutoDispatching = False report.save() if report_form.cleaned_data['subscription']: report.subscribe_author() if request.POST["comment-text"]: comment = comment_form.save(commit=False) comment.report = report comment.created_by = user # Used for comment post_save signal: comment.is_new_report = True comment.save() files = file_formset.save(commit=False) for report_file in files: report_file.created_by = user # Used for file post_save signal: report_file.is_new_report = True report_file.save() report.forceAutoDispatching = True report.save() messages.add_message(request, messages.SUCCESS, _("Newly created report successfull"), extra_tags="new_report") return HttpResponseRedirect(report.get_absolute_url_pro()) else: report = None else: report_form = ProReportForm(initial={ 'x': request.REQUEST.get('x'), 'y': request.REQUEST.get('y') }, prefix='report') file_formset = ReportFileFormSet(prefix='files', queryset=ReportFile.objects.none()) comment_form = ReportCommentForm(prefix='comment') return render_to_response("pro/reports/new.html", { "report": report, "all_zipcodes": ZipCode.objects.all(), "category_classes": ReportMainCategoryClass.objects.prefetch_related('categories').all(), "report_form": report_form, "pnt": pnt, "file_formset": file_formset, "comment_form": comment_form, "isNewIncident": True }, context_instance=RequestContext(request))
def new(request): pnt = dict_to_point(request.REQUEST) ReportFileFormSet = inlineformset_factory(Report, ReportFile, form=ReportFileForm, extra=0) report = None if request.method == "POST": report_form = ProReportForm(request.POST, request.FILES, prefix='report') comment_form = ReportCommentForm(request.POST, request.FILES, prefix='comment') fingerprint = RequestFingerprint(request) # this checks update is_valid too if report_form.is_valid() and (not request.POST["comment-text"] or comment_form.is_valid()) and not fingerprint.is_duplicate(): # this saves the update as part of the report. report = report_form.save(commit=False) # Use `hack_multi_file` instead of ``request.FILES``. file_formset = ReportFileFormSet(request.POST, hack_multi_file(request), instance=report, prefix='files', queryset=ReportFile.objects.none()) if file_formset.is_valid(): user = FMSUser.objects.get(pk=request.user.id) fingerprint.save() report.save() if report_form.cleaned_data['subscription']: report.subscribe_author() if request.POST["comment-text"]: comment = comment_form.save(commit=False) comment.report = report comment.created_by = user # Used for comment post_save signal: comment.is_new_report = True comment.save() files = file_formset.save(commit=False) for report_file in files: report_file.created_by = user # Used for file post_save signal: report_file.is_new_report = True report_file.save() messages.add_message(request, messages.SUCCESS, _("Newly created report successfull"), extra_tags="new_report") return HttpResponseRedirect(report.get_absolute_url_pro()) else: report = None else: report_form = ProReportForm(initial={ 'x': request.REQUEST.get('x'), 'y': request.REQUEST.get('y') }, prefix='report') file_formset = ReportFileFormSet(prefix='files', queryset=ReportFile.objects.none()) comment_form = ReportCommentForm(prefix='comment') return render_to_response("pro/reports/new.html", { "report": report, "all_zipcodes": ZipCode.objects.all(), "category_classes": ReportMainCategoryClass.objects.prefetch_related('categories').all(), "report_form": report_form, "pnt": pnt, "file_formset": file_formset, "comment_form": comment_form, }, context_instance=RequestContext(request))