예제 #1
0
    def add_person(self, person_data):
        # TODO Move this out of the view layer
        person = Person.objects.create(name=person_data['name'])
        person_extra = PersonExtra.objects.create(base=person)
        check_creation_allowed(self.request.user,
                               person_extra.current_candidacies)

        change_metadata = get_change_metadata(self.request,
                                              person_data['source'])

        person_extra.record_version(change_metadata)
        person_extra.save()

        LoggedAction.objects.create(
            user=self.request.user,
            person=person,
            action_type='person-create',
            ip_address=get_client_ip(self.request),
            popit_person_new_version=change_metadata['version_id'],
            source=change_metadata['information_source'],
        )

        # Add a message to be displayed after redirect:
        messages.add_message(self.request,
                             messages.SUCCESS,
                             get_call_to_action_flash_message(person,
                                                              new_person=True),
                             extra_tags='safe do-something-else')
        return person_extra
예제 #2
0
def update_person(
    request=None, person=None, party=None, post_election=None, source=None
):
    election = post_election.election

    person.not_standing.remove(election)

    check_creation_allowed(request.user, person.current_candidacies)

    membership, _ = Membership.objects.update_or_create(
        post=post_election.post,
        person=person,
        post_election=post_election,
        defaults={
            "party": party,
            "party_list_position": None,
            "elected": None,
            "role": election.candidate_membership_role,
        },
    )

    # Now remove other memberships in this election for that
    # person, although we raise an exception if there is any
    # object that has a
    # ForeignKey to the membership, since that would result in
    # losing data.
    old_memberships = (
        Membership.objects.exclude(pk=membership.pk)
        .exclude(post_election__candidates_locked=True)
        .filter(person=person, post_election__election=post_election.election)
    )
    for old_membership in old_memberships:
        raise_if_unsafe_to_delete(old_membership)
        old_membership.delete()

    memberships_for_election = Membership.objects.filter(
        person=person, post_election__election=post_election.election
    )

    if (
        not memberships_for_election.exists()
        or memberships_for_election.count() > 1
    ):
        raise ValueError(
            "Attempt to create invalid memberships for {}".format(person)
        )

    change_metadata = get_change_metadata(request, source)

    person.record_version(change_metadata)
    person.save()

    LoggedAction.objects.create(
        user=request.user,
        person=person,
        action_type="person-update",
        ip_address=get_client_ip(request),
        popit_person_new_version=change_metadata["version_id"],
        source=change_metadata["information_source"],
    )
예제 #3
0
    def add_person(self, person_data):
        # TODO Move this out of the view layer
        person = Person.objects.create(name=person_data['name'])
        person_extra = PersonExtra.objects.create(base=person)
        check_creation_allowed(
            self.request.user, person_extra.current_candidacies
        )

        change_metadata = get_change_metadata(
            self.request, person_data['source']
        )

        person_extra.record_version(change_metadata)
        person_extra.save()

        LoggedAction.objects.create(
            user=self.request.user,
            person=person,
            action_type='person-create',
            ip_address=get_client_ip(self.request),
            popit_person_new_version=change_metadata['version_id'],
            source=change_metadata['information_source'],
        )

        # Add a message to be displayed after redirect:
        messages.add_message(
            self.request,
            messages.SUCCESS,
            get_call_to_action_flash_message(person, new_person=True),
            extra_tags='safe do-something-else'
        )
        return person_extra
def update_person(request=None,
                  person_extra=None,
                  party=None,
                  post_election=None,
                  source=None):
    election = post_election.election

    person_extra.not_standing.remove(election)

    check_creation_allowed(request.user, person_extra.current_candidacies)

    membership, _ = Membership.objects.update_or_create(
        post=post_election.postextra.base,
        person=person_extra.base,
        extra__election=election,
        role=election.candidate_membership_role,
        defaults={
            'on_behalf_of': party,
        })

    MembershipExtra.objects.get_or_create(base=membership,
                                          defaults={
                                              'party_list_position': None,
                                              'election': election,
                                              'elected': None,
                                              'post_election': post_election,
                                          })

    # Now remove other memberships in this election for that
    # person, although we raise an exception if there is any
    # object (other than its MembershipExtra) that has a
    # ForeignKey to the membership, since that would result in
    # losing data.
    old_memberships = Membership.objects \
        .exclude(pk=membership.pk) \
        .filter(
            person=person_extra.base,
            extra__election=election,
            role=election.candidate_membership_role,
        )
    for old_membership in old_memberships:
        raise_if_unsafe_to_delete(old_membership)
        old_membership.delete()

    change_metadata = get_change_metadata(request, source)

    person_extra.record_version(change_metadata)
    person_extra.save()

    LoggedAction.objects.create(
        user=request.user,
        person=person_extra.base,
        action_type='person-update',
        ip_address=get_client_ip(request),
        popit_person_new_version=change_metadata['version_id'],
        source=change_metadata['information_source'],
    )
예제 #5
0
    def add_person(self, person_data):
        # TODO Move this out of the view layer
        person = Person.objects.create(name=person_data['name'])
        person_extra = PersonExtra.objects.create(base=person)
        check_creation_allowed(self.request.user,
                               person_extra.current_candidacies)

        change_metadata = get_change_metadata(self.request,
                                              person_data['source'])

        person_extra.record_version(change_metadata)
        person_extra.save()

        LoggedAction.objects.create(
            user=self.request.user,
            person=person,
            action_type='person-create',
            ip_address=get_client_ip(self.request),
            popit_person_new_version=change_metadata['version_id'],
            source=change_metadata['information_source'],
        )

        return person_extra