示例#1
0
    def process(self, request=None):
        data = self.data
        user = data['user']
        user_created = False

        if not user.is_authenticated:
            user_created = True
            user, password = AccountManager.create_user(**self.data)
            self.data['user'] = user

        if request is not None:
            extra = registry.run_hook('pre_request_creation',
                request,
                user=user,
                data=data
            )
            data.update(extra)

        foirequest = self.create_request(self.data['publicbodies'][0])

        if user_created:
            AccountManager(user).send_confirmation_mail(
                request_id=foirequest.pk,
                password=password
            )
        return foirequest
示例#2
0
def make_same_request(request, slug, message_id):
    foirequest = get_object_or_404(FoiRequest, slug=slug)
    message = get_object_or_404(FoiMessage, id=int(message_id))
    if not message.not_publishable:
        return render_400(request)
    if not foirequest == message.request:
        return render_400(request)
    if foirequest.same_as is not None:
        foirequest = foirequest.same_as
    if not request.user.is_authenticated():
        new_user_form = NewUserForm(request.POST)
        if not new_user_form.is_valid():
            return show(request, slug, context={"new_user_form": new_user_form}, status=400)
        else:
            user, password = AccountManager.create_user(**new_user_form.cleaned_data)
    else:
        user = request.user
        if foirequest.user == user:
            return render_400(request)
        same_requests = FoiRequest.objects.filter(user=user, same_as=foirequest).count()
        if same_requests:
            messages.add_message(request, messages.ERROR,
                _("You already made an identical request"))
            return render_400(request)

    throttle_message = check_throttle(request.user, FoiRequest)
    if throttle_message:
        messages.add_message(request, messages.ERROR, throttle_message)
        return render_400(request)

    body = u"%s\n\n%s" % (foirequest.description,
            _('Please see this request on %(site_name)s where you granted access to this information: %(url)s') % {
                'url': foirequest.get_absolute_domain_short_url(),
                'site_name': settings.SITE_NAME
            })

    kwargs = registry.run_hook('pre_request_creation', request,
        user=user,
        public_body=foirequest.public_body,
        foi_law=foirequest.law,
        form_data=dict(
            subject=foirequest.title,
            body=body,
            public=foirequest.public
        )  # Don't pass post_data, get default letter of law
    )
    fr = FoiRequest.from_request_form(**kwargs)
    fr.same_as = foirequest
    fr.save()
    if user.is_active:
        messages.add_message(request, messages.SUCCESS,
                _('You successfully requested this document! Your request is displayed below.'))
        return redirect(fr)
    else:
        AccountManager(user).send_confirmation_mail(request_id=fr.pk,
                password=password)
        messages.add_message(request, messages.INFO,
                _('Please check your inbox for mail from us to confirm your mail address.'))
        # user cannot access the request yet!
        return redirect("/")
示例#3
0
文件: views.py 项目: pdehaye/froide
def make_same_request(request, slug, message_id):
    foirequest = get_object_or_404(FoiRequest, slug=slug)
    message = get_object_or_404(FoiMessage, id=int(message_id))
    if not message.not_publishable:
        return render_400(request)
    if not foirequest == message.request:
        return render_400(request)
    if foirequest.same_as is not None:
        foirequest = foirequest.same_as
    if not request.user.is_authenticated:
        new_user_form = NewUserForm(request.POST)
        if not new_user_form.is_valid():
            return show(request, slug, context={"new_user_form": new_user_form}, status=400)
        else:
            user, password = AccountManager.create_user(**new_user_form.cleaned_data)
    else:
        user = request.user
        if foirequest.user == user:
            return render_400(request)
        same_requests = FoiRequest.objects.filter(user=user, same_as=foirequest).count()
        if same_requests:
            messages.add_message(request, messages.ERROR,
                _("You already made an identical request"))
            return render_400(request)

    throttle_message = check_throttle(request.user, FoiRequest)
    if throttle_message:
        messages.add_message(request, messages.ERROR, throttle_message)
        return render_400(request)

    body = u"%s\n\n%s" % (foirequest.description,
            _('Please see this request on %(site_name)s where you granted access to this information: %(url)s') % {
                'url': foirequest.get_absolute_domain_short_url(),
                'site_name': settings.SITE_NAME
            })

    kwargs = registry.run_hook('pre_request_creation', request,
        user=user,
        public_body=foirequest.public_body,
        foi_law=foirequest.law,
        form_data=dict(
            subject=foirequest.title,
            body=body,
            public=foirequest.public
        )  # Don't pass post_data, get default letter of law
    )
    fr = FoiRequest.from_request_form(**kwargs)
    fr.same_as = foirequest
    fr.save()
    if user.is_active:
        messages.add_message(request, messages.SUCCESS,
                _('You successfully requested this document! Your request is displayed below.'))
        return redirect(fr)
    else:
        AccountManager(user).send_confirmation_mail(request_id=fr.pk,
                password=password)
        messages.add_message(request, messages.INFO,
                _('Please check your inbox for mail from us to confirm your mail address.'))
        # user cannot access the request yet!
        return redirect("/")
示例#4
0
文件: views.py 项目: gabelula/froide
def submit_request(request, public_body=None):
    error = False
    foilaw = None
    if public_body is not None:
        public_body = get_object_or_404(PublicBody, slug=public_body)
        if not public_body.email:
            raise Http404
        all_laws = FoiLaw.objects.filter(jurisdiction=public_body.jurisdiction)
    else:
        all_laws = FoiLaw.objects.all()
    context = {"public_body": public_body}

    request_form = RequestForm(all_laws, FoiLaw.get_default_law(), True, request.POST)
    context["request_form"] = request_form
    context["public_body_form"] = PublicBodyForm()
    if public_body is None and request.POST.get("public_body") == "new":
        pb_form = PublicBodyForm(request.POST)
        context["public_body_form"] = pb_form
        if pb_form.is_valid():
            data = pb_form.cleaned_data
            data["confirmed"] = False
            # Take the first jurisdiction there is
            data["jurisdiction"] = Jurisdiction.objects.all()[0]
            data["slug"] = slugify(data["name"])
            public_body = PublicBody(**data)
        else:
            error = True

    if not request_form.is_valid():
        error = True
    else:
        if (
            public_body is None
            and request_form.cleaned_data["public_body"] != ""
            and request_form.cleaned_data["public_body"] != "new"
        ):
            public_body = request_form.public_body_object

    context["user_form"] = None
    user = None
    if not request.user.is_authenticated():
        user_form = NewUserForm(request.POST)
        context["user_form"] = user_form
        if not user_form.is_valid():
            error = True
    else:
        user = request.user

    if not error:
        password = None
        if user is None:
            user, password = AccountManager.create_user(**user_form.cleaned_data)
        sent_to_pb = 1
        if public_body is not None and public_body.pk is None:
            public_body._created_by = user
            public_body.save()
            sent_to_pb = 2
        elif public_body is None:
            sent_to_pb = 0

        if foilaw is None:
            if public_body is not None:
                foilaw = public_body.default_law
            else:
                foilaw = request_form.foi_law

        foi_request = FoiRequest.from_request_form(
            user, public_body, foilaw, form_data=request_form.cleaned_data, post_data=request.POST
        )

        if user.is_active:
            if sent_to_pb == 0:
                messages.add_message(
                    request, messages.INFO, _("Others can now suggest the Public Bodies for your request.")
                )
            elif sent_to_pb == 2:
                messages.add_message(
                    request,
                    messages.INFO,
                    _(
                        "Your request will be sent as soon as the newly created Public Body was confirmed by an administrator."
                    ),
                )

            else:
                messages.add_message(request, messages.INFO, _("Your request has been sent."))
            return redirect(u"%s%s" % (foi_request.get_absolute_url(), _("?request-made")))
        else:
            AccountManager(user).send_confirmation_mail(request_id=foi_request.pk, password=password)
            messages.add_message(
                request, messages.INFO, _("Please check your inbox for mail from us to confirm your mail address.")
            )
            # user cannot access the request yet!
            return redirect("/")
    messages.add_message(
        request, messages.ERROR, _("There were errors in your form submission. Please review and submit again.")
    )
    return render(request, "foirequest/request.html", context, status=400)
示例#5
0
文件: views.py 项目: hylje/froide
def submit_request(request, public_body=None):
    error = False
    foilaw = None
    if public_body is not None:
        public_body = get_object_or_404(PublicBody,
                slug=public_body)
        if not public_body.email:
            raise Http404
        all_laws = FoiLaw.objects.filter(jurisdiction=public_body.jurisdiction)
    else:
        all_laws = FoiLaw.objects.all()
    context = {"public_body": public_body}

    request_form = RequestForm(all_laws, FoiLaw.get_default_law(),
            True, request.POST)
    context['request_form'] = request_form
    context['public_body_form'] = PublicBodyForm()
    if (public_body is None and
            request.POST.get('public_body') == "new"):
        pb_form = PublicBodyForm(request.POST)
        context["public_body_form"] = pb_form
        if pb_form.is_valid():
            data = pb_form.cleaned_data
            data['confirmed'] = False
            # Take the first jurisdiction there is
            data['jurisdiction'] = Jurisdiction.objects.all()[0]
            data['slug'] = slugify(data['name'])
            public_body = PublicBody(**data)
        else:
            error = True

    if not request_form.is_valid():
        error = True
    else:
        if (public_body is None and
                request_form.cleaned_data['public_body'] != '' and
                request_form.cleaned_data['public_body'] != 'new'):
            public_body = request_form.public_body_object

    context['user_form'] = None
    user = None
    if not request.user.is_authenticated():
        user_form = NewUserForm(request.POST)
        context['user_form'] = user_form
        if not user_form.is_valid():
            error = True
    else:
        user = request.user

    if not error:
        password = None
        if user is None:
            user, password = AccountManager.create_user(**user_form.cleaned_data)
        sent_to_pb = 1
        if public_body is not None and public_body.pk is None:
            public_body._created_by = user
            public_body.save()
            sent_to_pb = 2
        elif public_body is None:
            sent_to_pb = 0

        if foilaw is None:
            if public_body is not None:
                foilaw = public_body.default_law
            else:
                foilaw = request_form.foi_law

        foi_request = FoiRequest.from_request_form(
                user,
                public_body,
                foilaw,
                form_data=request_form.cleaned_data,
                post_data=request.POST
        )

        if user.is_active:
            if sent_to_pb == 0:
                messages.add_message(request, messages.INFO,
                    _('Others can now suggest the Public Bodies for your request.'))
            elif sent_to_pb == 2:
                messages.add_message(request, messages.INFO,
                    _('Your request will be sent as soon as the newly created Public Body was confirmed by an administrator.'))

            else:
                messages.add_message(request, messages.INFO,
                    _('Your request has been sent.'))
            return redirect(u'%s%s' % (foi_request.get_absolute_url(), _('?request-made')))
        else:
            AccountManager(user).send_confirmation_mail(request_id=foi_request.pk,
                    password=password)
            messages.add_message(request, messages.INFO,
                    _('Please check your inbox for mail from us to confirm your mail address.'))
            # user cannot access the request yet!
            return redirect("/")
    messages.add_message(request, messages.ERROR,
        _('There were errors in your form submission. Please review and submit again.'))
    return render(request, 'foirequest/request.html', context, status=400)
示例#6
0
文件: views.py 项目: pdehaye/froide
def submit_request(request, public_body=None):
    error = False
    foi_law = None
    if public_body is not None:
        public_body = get_object_or_404(PublicBody,
                slug=public_body)
        if not public_body.email:
            raise Http404
        all_laws = FoiLaw.objects.filter(jurisdiction=public_body.jurisdiction)
    else:
        all_laws = FoiLaw.objects.all()
    context = {"public_body": public_body}

    request_form = RequestForm(user=request.user,
                               list_of_laws=all_laws,
                               default_law=FoiLaw.get_default_law(),
                               data=request.POST)
    context['request_form'] = request_form
    context['public_body_form'] = PublicBodyForm()
    if (public_body is None and
            request.POST.get('public_body') == "new"):
        pb_form = PublicBodyForm(request.POST)
        context["public_body_form"] = pb_form
        if pb_form.is_valid():
            data = pb_form.cleaned_data
            data['confirmed'] = False
            # Take the first jurisdiction there is
            data['jurisdiction'] = Jurisdiction.objects.all()[0]
            data['slug'] = slugify(data['name'])
            public_body = PublicBody(**data)
        else:
            error = True

    if not request_form.is_valid():
        error = True
    else:
        if (public_body is None and
                request_form.cleaned_data['public_body'] != '' and
                request_form.cleaned_data['public_body'] != 'new'):
            public_body = request_form.public_body_object

    context['user_form'] = None
    user = None
    if not request.user.is_authenticated:
        user_form = NewUserForm(request.POST)
        context['user_form'] = user_form
        if not user_form.is_valid():
            error = True
    else:
        user = request.user

    if error:
        messages.add_message(request, messages.ERROR,
            _('There were errors in your form submission. Please review and submit again.'))
        return render(request, 'foirequest/request.html', context, status=400)

    password = None
    if user is None:
        user, password = AccountManager.create_user(**user_form.cleaned_data)
    sent_to_pb = 1
    if public_body is not None and public_body.pk is None:
        public_body._created_by = user
        public_body.save()
        sent_to_pb = 2
    elif public_body is None:
        sent_to_pb = 0

    if foi_law is None:
        if public_body is not None:
            foi_law = public_body.default_law
        else:
            foi_law = request_form.foi_law

    kwargs = registry.run_hook('pre_request_creation', request,
        user=user,
        public_body=public_body,
        foi_law=foi_law,
        form_data=request_form.cleaned_data,
        post_data=request.POST
    )
    foi_request = FoiRequest.from_request_form(**kwargs)

    if user.is_active:
        if sent_to_pb == 0:
            messages.add_message(request, messages.INFO,
                _('Others can now suggest the Public Bodies for your request.'))
        elif sent_to_pb == 2:
            messages.add_message(request, messages.INFO,
                _('Your request will be sent as soon as the newly created Public Body was confirmed by an administrator.'))

        else:
            messages.add_message(request, messages.INFO,
                _('Your request has been sent.'))
        if request_form.cleaned_data['redirect_url']:
            redirect_url = request_form.cleaned_data['redirect_url']
            if is_safe_url(redirect_url, allowed_hosts=settings.ALLOWED_REDIRECT_HOSTS):
                return redirect(redirect_url)
        return redirect(u'%s%s' % (foi_request.get_absolute_url(), _('?request-made')))
    else:
        AccountManager(user).send_confirmation_mail(request_id=foi_request.pk,
                password=password)
        messages.add_message(request, messages.INFO,
                _('Please check your inbox for mail from us to confirm your mail address.'))
        # user cannot access the request yet!
        return redirect("/")