def request_crowdfunding(request, pk): foirequest = get_object_or_404(FoiRequest, pk=pk) if not can_write_foirequest(foirequest, request): return render_403(request) crowdfundings = Crowdfunding.objects.filter(request=foirequest) if request.method == 'POST': form = CrowdfundingRequestStartForm(data=request.POST, crowdfundings=crowdfundings, user=request.user, foirequest=foirequest) if form.is_valid(): form.save() messages.add_message( request, messages.SUCCESS, _('Your crowdfunding campaign ' 'has been submitted for approval.')) return redirect(foirequest) else: messages.add_message(request, messages.ERROR, _('Your form contained errors.')) else: form = CrowdfundingRequestStartForm(crowdfundings=crowdfundings, user=request.user, foirequest=foirequest) return render(request, 'froide_crowdfunding/request_crowdfunding.html', context={ "crowdfunding_form": form, 'object': foirequest, })
def get_object(self, queryset=None): obj = super().get_object(queryset=None) self.message = get_object_or_404( FoiMessage, id=self.kwargs['message_id'] ) self.message_user = self.message.request.user if not can_write_foirequest(self.message.request, self.request): raise Http404 return obj
def report_problem(request, message_pk): message = get_object_or_404(FoiMessage, pk=message_pk) foirequest = message.request if not can_write_foirequest(foirequest, request): return render_403(request) form = ProblemReportForm(data=request.POST, user=request.user, message=message) if form.is_valid(): form.save() else: messages.add_message(request, messages.ERROR, _('Your report could not be created.')) return redirect(message)
def send_as_fax(request, message_id): message = get_object_or_404(FoiMessage, id=message_id) if not can_write_foirequest(message.request, request): return HttpResponse(status=403) ignore_law = request.user.is_superuser if not message_can_be_faxed( message, ignore_time=True, ignore_law=ignore_law): return HttpResponse(status=400) fax_message = create_fax_message(message, ignore_time=True, ignore_law=ignore_law) return redirect(fax_message)
def pdf_report(request, message_id): message = get_object_or_404(FoiMessage, id=message_id) if not can_write_foirequest(message.request, request): return HttpResponse(status=403) if not message_can_get_fax_report(message): return HttpResponse(status=404) pdf_generator = FaxReportPDFGenerator(message) response = HttpResponse(pdf_generator.get_pdf_bytes(), content_type="application/pdf") response["Content-Disposition"] = ("attachment; " 'filename="fax-report-%s.pdf"' % message.pk) return response
def request_form_page(request, pk=None): foirequest = None is_embed, base_template = _get_embed_info(request) status = 200 if pk is not None: if not request.user.is_authenticated: raise Http404 foirequest = get_object_or_404(FoiRequest, pk=int(pk)) if not can_write_foirequest(foirequest, request): raise Http404 if request.method == "POST": form = LegalActionRequestForm(request.POST, request.FILES, foirequest=foirequest) if form.is_valid(): form.save() messages.add_message( request, messages.SUCCESS, _("We have received your submission and we will review it. Thank you!" ), ) if foirequest is None: url = reverse("legalaction-thanks") return redirect(url + ("?embed=1" if is_embed else "")) else: return redirect(foirequest) else: status = 400 messages.add_message(request, messages.WARNING, _("Please check for errors in your form.")) else: form = LegalActionRequestForm(foirequest=foirequest) return render( request, "froide_legalaction/form.html", { "form": form, "base_template": base_template }, status=status, )
def report_problem(request, message_pk): message = get_object_or_404(FoiMessage, pk=message_pk) foirequest = message.request if not can_write_foirequest(foirequest, request): return render_403(request) form = ProblemReportForm( data=request.POST, user=request.user, message=message ) if form.is_valid(): form.save() else: messages.add_message( request, messages.ERROR, _('Your report could not be created.') ) return redirect(message)
def request_crowdfunding(request, pk): foirequest = get_object_or_404(FoiRequest, pk=pk) if not can_write_foirequest(foirequest, request): return render_403(request) if request.method == 'POST': form = CrowdfundingRequestStartForm(data=request.POST, user=request.user, foirequest=foirequest) if form.is_valid(): obj = form.save() messages.add_message( request, messages.SUCCESS, _('Your crowdfunding campaign ' 'has been submitted for approval.')) context = { 'user': obj.user, 'crowdfunding': obj, 'site_name': settings.SITE_NAME, } send_template_email( user=obj.user, subject=_('💸 Your crowdfunding project has been created'), template='froide_crowdfunding/emails/needs_approval.txt', context=context) mail_managers( _('Crowdfunding project needs approval'), settings.SITE_URL + reverse('admin:froide_crowdfunding_crowdfunding_change', args=(obj.pk, ))) return redirect(foirequest) else: messages.add_message(request, messages.ERROR, _('Your form contained errors.')) else: form = CrowdfundingRequestStartForm(user=request.user, foirequest=foirequest) return render(request, 'froide_crowdfunding/request_crowdfunding.html', context={ "crowdfunding_form": form, 'object': foirequest, })