Beispiel #1
0
 def get_context_data(self, **kwargs):
     if self.request.POST:
         form = NoticeOfElectionForm(self.request.POST)
     else:
         form = NoticeOfElectionForm()
     context = super().get_context_data(**kwargs)
     context["form"] = form
     context["user_can_upload_docs"] = user_is_moderator(self.request.user)
     return context
Beispiel #2
0
 def get_context_data(self, **kwargs):
     if self.request.POST:
         form = NoticeOfElectionForm(self.request.POST)
     else:
         form = NoticeOfElectionForm()
     context = super().get_context_data(**kwargs)
     context["geography_html"] = self.get_geography_html(context["object"])
     context["document"], context["document_type"] = self.get_document(
         context["object"]
     )
     context["form"] = form
     context["user_can_upload_docs"] = user_is_moderator(self.request.user)
     return context
Beispiel #3
0
    def post(self, *args, **kwargs):
        if not user_is_moderator(self.request.user):
            return self.handle_no_permission()

        form = NoticeOfElectionForm(self.request.POST)
        if form.is_valid():
            document_url = form.cleaned_data["document"]

            doc = Document()
            doc.source_url = document_url
            doc.archive_document(document_url, kwargs["election_id"])
            doc.save()

            e = Election.public_objects.get(election_id=kwargs["election_id"])
            e.notice = doc
            e.save()

        return self.get(*args, **kwargs)
Beispiel #4
0
    def get_context_data(self, form, **kwargs):
        context = super().get_context_data(form=form, **kwargs)
        all_data = self.get_all_cleaned_data()
        # print("\n".join(str(all_data).split(',')))
        if not "date" in all_data:
            all_data["date"] = None

        all_data["election_organisation"] = self.get_organisations

        if not all_data.get("election_organisation"):
            all_data.update(self.storage.extra_data)
        else:
            all_data["radar_id"] = self.storage.extra_data.get(
                "radar_id", None)

        context["all_data"] = all_data
        if self.kwargs["step"] in ["review", self.done_step_name]:
            all_ids = create_ids_for_each_ballot_paper(
                all_data, self.get_election_subtypes)
            context["all_ids"] = all_ids
        context["user_is_moderator"] = user_is_moderator(self.request.user)
        return context
Beispiel #5
0
 def test_func(self):
     return user_is_moderator(self.request.user)
Beispiel #6
0
    def done(self, form_list, **kwargs):
        # Make the elections

        context = self.get_context_data(form_list)
        all_data = self.get_all_cleaned_data()

        # Attach Notice of Election doc
        if all_data.get("document", False):
            # only sync the Notice of Election doc to S3 once
            # (not once per ballot paper)
            directory = get_notice_directory(context["all_ids"])
            doc = Document()
            doc.source_url = all_data["document"]
            doc.archive_document(all_data["document"], directory)
            doc.save()

            for election in context["all_ids"]:
                # Attach Notice of Election docs to IDs we are creating
                # but only link the document to the individual ballot IDs
                # because we can't make a safe assumption about whether
                # all of the elections in a group are covered by a single
                # Notice of Election document - it will vary
                if not election.group_type:
                    election.notice = doc

        status = ModerationStatuses.suggested.value
        notes = ""
        if user_is_moderator(self.request.user):
            status = ModerationStatuses.approved.value
            notes = "auto approved for user {}".format(self.request.user)

        for election in context["all_ids"]:
            election.save(status=status, user=self.request.user, notes=notes)

        if not user_is_moderator(
                self.request.user) and len(context["all_ids"]) > 0:

            ballots = [e for e in context["all_ids"] if e.group_type == None]
            if len(ballots) == 1:
                message = """
                    New election {} suggested by anonymous user:\n
                    <https://elections.democracyclub.org.uk/election_radar/moderation_queue/>
                """.format(ballots[0].election_id)
            else:
                message = """
                    {} New elections suggested by anonymous user:\n
                    <https://elections.democracyclub.org.uk/election_radar/moderation_queue/>
                """.format(len(ballots))
            post_to_slack(message)

        # if this election was created from a radar entry set the status
        # of the radar entry to indicate we have made an id for it
        if isinstance(self.storage.extra_data,
                      dict) and self.storage.extra_data.get("radar_id", False):

            se = SnoopedElection.objects.get(
                pk=self.storage.extra_data["radar_id"])
            se.status = "id_created"
            se.save()

        return HttpResponseRedirect("/")