Esempio n. 1
0
    def post(self, *args, **kwargs):
        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.objects.get(election_id=kwargs['election_id'])
            e.notice = doc
            e.save()

        return self.get(*args, **kwargs)
Esempio n. 2
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)
Esempio n. 3
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

        for election in context['all_ids']:
            election.save()

        # 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('/')
Esempio n. 4
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("/")