Exemplo n.º 1
0
def check_permissions(request, id, type):
    """
        Checks propper permissions for the current user:
        
        Type can be one of:
        
        'council_admin' - id is expected to be election_instance_id
        'party_admin' - id to be an election_instance_party
        'candidate' - id to be an election_instance_party
        
        Issue: It would be better to work with objects to prevent the party_id being passed instead of 
        the election_instance_party, now we just have to assume it's ok
    """
    if request.user.is_authenticated():
        if request.user.is_staff:
            return
        if request.user.profile is None:
            raise PermissionDeniedException()

        if type == 'council_admin' and request.user.councils.filter(
                election_instances__pk=id):
            return
        elif type == 'party_admin':
            if request.user.profile.type == 'council_admin' and request.user.councils.filter(
                    election_instances__election_instance_parties__pk=id):
                return
            elif request.user.parties.filter(election_instance_parties__pk=id):
                return
        elif type == 'candidate':
            if request.user.profile.type == 'council_admin' and request.user.councils.filter(
                    election_instances__election_instance_parties__pk=id):
                return
            elif request.user.profile.type == 'party_admin' and request.user.parties.filter(
                    election_instance_parties__pk=id):
                return
            elif request.user.elections.filter(election_party_instance__pk=id):
                return

    raise PermissionDeniedException()
Exemplo n.º 2
0
def party_contact_wizard(request, id, user_id=None):
    check_permissions(request, id, 'party_admin')
    if user_id is None:
        if not (request.user.profile is None
                or request.user.profile.type != 'party_admin'):
            user_id = request.user.id
        elif request.user.is_staff or (request.user.profile
                                       and request.user.profile.type
                                       == 'council_admin'):
            user_id is None
        else:
            raise PermissionDeniedException()

    return PartyContactWizard(user_id=user_id, eip_id=id)(request)
Exemplo n.º 3
0
def election_setup(request, election_instance_id, user_id=None):
    '''
    Election setup wizard.
    @param int election_instance_id
    @param int user_id

    Both parameters are required. It's obvious what they mean.
    '''
    check_permissions(request, election_instance_id, 'council_admin')
    if user_id is None:
        user_id = request.user.id
        if not request.user.profile or request.user.profile.type != 'council_admin':
            raise PermissionDeniedException('You are not the correct user')

    return ElectionSetupWizard2(election_instance_id=election_instance_id,
                                user_id=user_id)(request)
Exemplo n.º 4
0
def redirect_view(request):
    if request.user.is_staff:
        return redirect('bo.election_event')
    elif request.user.profile.type == 'council_admin':
        election_instance = request.user.councils.all(
        )[0].election_instances.all()[0]
        return redirect('bo.election_instance_view', id=election_instance.id)
    elif request.user.profile.type == 'party_admin':
        election_instance_party = request.user.parties.all().order_by(
            '-id')[0].election_instance_parties.all()[0]
        return redirect('bo.election_party_view',
                        id=election_instance_party.id)
    elif request.user.profile.type == 'candidate':
        election_instance_party = request.user.elections.all().order_by(
            '-id')[0].election_party_instance
        return redirect('bo.politician_welcome',
                        eip_id=election_instance_party.id)
    else:
        raise PermissionDeniedException()
Exemplo n.º 5
0
def politician_welcome(request, eip_id):
    check_permissions(request, eip_id, 'candidate')
    election_instance_party = get_object_or_404(ElectionInstanceParty,
                                                pk=eip_id)
    if not request.user.profile or request.user.profile.type != 'candidate':
        raise PermissionDeniedException('Geen toegang met de huidige account')
    else:
        user = get_object_or_404(election_instance_party.candidates,
                                 candidate=request.user).candidate

    return render_to_response(
        'backoffice/wizard/politician_profile/welcome.html', {
            'user_id': user.id,
            'politician': user.profile,
            'election_instance': election_instance_party.election_instance,
            'eip_id': eip_id,
            'questions': range(0, get_question_count(eip_id)),
        },
        context_instance=RequestContext(request))
Exemplo n.º 6
0
    def __init__(self, *args, **kwargs):
        # Getting "user_id" and "election_instance_id" passed to the Wizard.
        self.user_id, self.election_instance_id = kwargs['user_id'], kwargs['election_instance_id']
        
        self.election_instance = get_object_or_404(ElectionInstance, pk=self.election_instance_id)
        self.user = get_object_or_404(self.election_instance.council.chanceries, pk=self.user_id)
        
        if self.user.profile is None or self.user.profile.type != 'council_admin':
            raise PermissionDeniedException('Wrong profile type')
        self.chancery_profile = self.user.profile
        '''
        Loading forms and models from other applications.
        '''
        try:
            ChanceryProfileForm = get_profile_forms('council_admin', 'edit')[0]
            ChanceryContactInformationForm = get_profile_forms('council_admin', 'contact_information')[0]
        except Exception:
            raise

        '''
        TODO for checkboxes we need to populate the data properly, because now it doesn't happen.
        '''
        step1_forms = {}
        step1_initial = {}
         # Get the form(s) for chancery profile and add them to step1_forms
        idx = 0
        for profile_form in get_profile_forms('council_admin', 'edit'):
            step1_forms.update({'chancery_registration%s' % idx : profile_form})
            workingdays = self.chancery_profile.workingdays or ''
            step1_initial.update({'chancery_registration%s' % idx : {
                'name': {
                    'first_name': self.chancery_profile.first_name,
                    'middle_name': self.chancery_profile.middle_name,
                    'last_name': self.chancery_profile.last_name,
                },
                'gender': self.chancery_profile.gender,
                'telephone': self.chancery_profile.telephone,
                'workingdays': workingdays.split(','),
            }})
            idx += 1

        #FIXME:  step5_forms = {}
        #         step5_initial = {}
        #          # Get the form(s) for chancery profile and add them to step5_forms
        #         idx = 0
        #         for profile_form in get_profile_forms('council_admin', 'contact_information'):
        #             step5_forms.update({'chancery_contact_information%s' % idx : profile_form})
        #             step5_initial.update({'chancery_contact_information%s' % idx : {
        #                 'website': self.chancery_profile.website,
        #                 'address': {
        #                     'street': self.chancery_profile.street,
        #                     'number': self.chancery_profile.house_num,
        #                     'postalcode': self.chancery_profile.postcode,
        #                     'city': self.chancery_profile.town,
        #                 }
        #             }})
        #             idx += 1

        # Updates ChanceryProfile
        step1 = Step('chancery_registration',
                     forms=step1_forms,
                     template='backoffice/wizard/election_setup/step1.html',
                     initial=step1_initial,
                     extra_context={'instance':self.election_instance, })
        # Updates ElectionInstance
        step2 = Step('election_details',
                     forms={'election_details': ElectionInstanceForm},
                     template='backoffice/wizard/election_setup/step2.html',
                     initial={'election_details': self.election_instance},
                     extra_context={'instance':self.election_instance, })
        # Updates Council
        step3 = Step('council_contact_information',
                     forms={'council_contact_information': CouncilContactInformationForm},
                     template='backoffice/wizard/election_setup/step3.html',
                     initial={'council_contact_information': {
                        'name': self.election_instance.council.name,
                        'address': {
                            'street': self.election_instance.council.street,
                            'number': self.election_instance.council.house_num,
                            'postalcode': self.election_instance.council.postcode,
                            'city': self.election_instance.council.town,
                        },
                        'website': self.election_instance.council.website,
                        'email': self.election_instance.council.email,
                     }},
                     extra_context={'instance':self.election_instance, })
        # Updates Council
        step4 = Step('council_additional_information',
                     forms={'council_additional_information': CouncilForm},
                     template='backoffice/wizard/election_setup/step4.html',
                     initial={'council_additional_information': self.election_instance.council},
                     extra_context={'instance':self.election_instance, })
        # Updates ChanceryProfile
        #FIXME: step5 = Step('chancery_contact_information',
        #                      forms=step5_forms,
        #                      template='backoffice/wizard/election_setup/step5.html',
        #                      initial=step5_initial)
        # Updates Council
        # step6 = Step('council_styling_setup',
        #                      forms={'council_styling_setup': CouncilStylingSetupForm},
        #                      template='backoffice/wizard/election_setup/step6.html',
        #                      initial={'council_styling_setup': self.election_instance.council},
        #                      extra_context={'instance':self.election_instance, })
        #FIXME: scenario_tree = step1.next(step2.next(step3.next(step4.next(step5.next(step6)))))
        #FIXME: scenario_tree = step1.next(step2.next(step3.next(step4.next(step6))))
        scenario_tree = step1.next(step2.next(step3.next(step4)))

        template = 'backoffice/wizard/election_setup/base.html',
        super(self.__class__, self).__init__(scenario_tree, template)
Exemplo n.º 7
0
    def __init__(self, eip_id, user_id, *args, **kwargs):
        self.eip = get_object_or_404(ElectionInstanceParty, pk=eip_id)
        self.election_instance = self.eip.election_instance
        if user_id is None:
            self.user = self.eip.party.contacts.all()[0]
        else:
            self.user = get_object_or_404(self.eip.party.contacts, pk=user_id)

        if not self.user.profile or self.user.profile.type != 'party_admin':
            raise PermissionDeniedException('Wrong user profile type')

        workingdays = self.user.profile.workingdays or ''
        self.user_profile_dict = {
            'name': {
                'first_name': self.user.profile.first_name,
                'middle_name': self.user.profile.middle_name,
                'last_name': self.user.profile.last_name,
            },
            'gender': self.user.profile.gender,
            #'picture': self.user.profile.picture,
            'telephone': self.user.profile.telephone,
            'workingdays': workingdays.split(','),
        }

        step1_forms = dict(party_contact=ContactProfileForm)
        step2_forms = dict(
            election_party_contact_form=ElectionPartyContactForm)
        step3_forms = dict(
            election_party_additional_form=ElectionPartyAdditionalForm)
        step4_forms = dict(
            election_party_description_form=ElectionPartyDescriptionForm)

        initial = copy.deepcopy(self.eip.party.__dict__)
        initial.update({'list_length': self.eip.list_length})
        initial.update({'address': self.eip.party.address})

        step1 = Step('party_contact',
                     forms=step1_forms,
                     template='backoffice/wizard/partycontact/step1.html',
                     initial={'party_contact': self.user_profile_dict},
                     extra_context={
                         'instance': self.election_instance,
                         'eip': self.eip
                     })
        step2 = Step('election_party_contact_form',
                     forms=step2_forms,
                     initial={'election_party_contact_form': initial},
                     template='backoffice/wizard/partycontact/step2.html',
                     extra_context={
                         'instance': self.election_instance,
                         'eip': self.eip
                     })
        step3 = Step(
            'election_party_additional_form',
            forms=step3_forms,
            initial={'election_party_additional_form': initial},
            template='backoffice/wizard/partycontact/step3.html',
            extra_context={
                'instance': self.election_instance,
                'eip': self.eip
            },
        )
        step4 = Step('election_party_description_form',
                     forms=step4_forms,
                     initial={'election_party_description_form': initial},
                     template='backoffice/wizard/partycontact/step4.html',
                     extra_context={
                         'instance': self.election_instance,
                         'eip': self.eip
                     })

        template = 'backoffice/wizard/partycontact/base.html',
        super(PartyContactWizard,
              self).__init__(step1.next(step2.next(step3.next(step4))),
                             template, *args, **kwargs)
Exemplo n.º 8
0
    def __init__(self, *args, **kwargs):
        # Getting "user_id"
        try:
            self.user_id = kwargs['user_id']
            self.eip_id = kwargs['eip_id']

            self.election_instance_party = get_object_or_404(
                ElectionInstanceParty, pk=self.eip_id)
            self.user = get_object_or_404(
                self.election_instance_party.candidates,
                candidate__pk=self.user_id).candidate

            if self.user.profile is None or self.user.profile.type != 'candidate':
                raise PermissionDeniedException('Wrong profile type')

            self.user_profile_dict = {
                'name': {
                    'first_name': self.user.profile.first_name,
                    'middle_name': self.user.profile.middle_name,
                    'last_name': self.user.profile.last_name,
                },
                'email': self.user.email,
                'initials': self.user.profile.initials,
                'dateofbirth': self.user.profile.dateofbirth,
                'introduction': self.user.profile.introduction,
                'gender': self.user.profile.gender,
                'picture': self.user.profile.picture,
                'movie': self.user.profile.movie,
                'marital_status': self.user.profile.marital_status,
                'num_children': self.user.profile.num_children,
                'religion': self.user.profile.religion,
                'religious_group': self.user.profile.religious_group,
                'province': self.user.profile.province,
                'smoker': self.user.profile.smoker,
                'diet': self.user.profile.diet,
                'fav_news': self.user.profile.fav_news,
                'transport': self.user.profile.transport,
                'charity': self.user.profile.charity,
                'fav_media': self.user.profile.fav_media,
                'fav_sport': self.user.profile.fav_sport,
                'hobby': self.user.profile.hobby,
                'fav_club': self.user.profile.fav_club,
                'fav_pet': self.user.profile.fav_pet,
            }

        except Exception:
            raise

        step1_forms = dict(initial_candidate=PoliticianProfileForm)
        step2_forms = dict(life_candidate=PoliticianProfileLifeForm)
        step3_forms = dict(extra_candidate=PoliticianProfileExtraForm)
        step4_forms = dict(political_candidate=PoliticianProfilePoliticalForm)
        step1 = Step(
            'initial_candidate',
            forms=step1_forms,
            template='backoffice/wizard/politician_profile/step1.html',
            initial={'initial_candidate': self.user_profile_dict},
            extra_context={
                'questions':
                range(0, get_question_count(self.election_instance_party)),
                'eip_id':
                self.eip_id,
                'user_id':
                self.user_id
            },
        )
        step2 = Step(
            'life_candidate',
            forms=step2_forms,
            template='backoffice/wizard/politician_profile/step2.html',
            initial={'life_candidate': self.user_profile_dict},
            extra_context={
                'questions':
                range(0, get_question_count(self.election_instance_party)),
                'eip_id':
                self.eip_id,
                'user_id':
                self.user_id
            },
        )
        step3 = Step(
            'extra_candidate',
            forms=step3_forms,
            template='backoffice/wizard/politician_profile/step3.html',
            initial={'extra_candidate': self.user_profile_dict},
            extra_context={
                'questions':
                range(0, get_question_count(self.election_instance_party)),
                'eip_id':
                self.eip_id,
                'user_id':
                self.user_id
            },
        )
        step4 = Step(
            'political_candidate',
            forms=step4_forms,
            template='backoffice/wizard/politician_profile/step4.html',
            initial={'political_candidate': self.user_profile_dict},
            extra_context={
                'questions':
                range(0, get_question_count(self.election_instance_party)),
                'eip_id':
                self.eip_id,
                'user_id':
                self.user_id
            },
        )

        scenario_tree = step1.next(step2.next(step3.next(step4)))
        #default template is the base, each step can override it as needed (for buttons)

        template = 'backoffice/wizard/politician_profile/base.html',
        super(PoliticianProfileWizard, self).__init__(scenario_tree, template)