Esempio n. 1
0
def candidate_edit(request, id):
    candidacy = get_object_or_404(Candidacy, pk=id)
    if candidacy.candidate.is_active:
        request.user.message_set.create(message=ugettext('De kandidaat die u wilt wijzigen heeft zijn/haar account al geactiveerd.'))
        return redirect('bo.election_party_view', id=candidacy.election_party_instance.id)

    FormClass = get_profile_forms('candidate', 'edit')[0]

    if request.method == 'POST':
        form = FormClass(user=candidacy.candidate, data=request.POST)

        if form.is_valid():
            candidacy.candidate.email = form.cleaned_data['email']
            candidacy.candidate.profile.first_name = form.cleaned_data['name']['first_name']
            candidacy.candidate.profile.middle_name = form.cleaned_data['name']['middle_name']
            candidacy.candidate.profile.last_name = form.cleaned_data['name']['last_name']
            candidacy.candidate.profile.gender = form.cleaned_data['gender']
            candidacy.candidate.save()
            candidacy.candidate.profile.save()

            request.user.message_set.create(message=ugettext('De kandidaat is gewijzigd.'))
            return redirect('bo.election_party_view', id=candidacy.election_party_instance.id)
    else:
        initial = {
            'name': {
                'first_name': candidacy.candidate.profile.first_name,
                'middle_name': candidacy.candidate.profile.middle_name,
                'last_name': candidacy.candidate.profile.last_name,
            },
            'email': candidacy.candidate.email,
            'gender': candidacy.candidate.profile.gender,
        }
        form = FormClass(user=candidacy.candidate, initial=initial)

    return render_to_response('backoffice/edit_candidate.html', {'form': form, 'candidacy': candidacy}, context_instance=RequestContext(request))
Esempio n. 2
0
 def __init__(self, *args, **kwargs):
     step1_forms = dict(
         initial_ei=InitialElectionInstanceForm,
     )
     # Get the form(s) for inviting a council admin and add them to step1_forms
     idx = 0;
     for profile_form in get_profile_forms('council_admin', 'invite'):
         step1_forms.update({'invite_contact_%s' % idx : profile_form})
         idx += 1
     
     #add step1
     step1 = Step('electioninstance', 
         forms=step1_forms,
         template='backoffice/wizard/addelection/step1.html',
     )
     #default template is the base, each step can override it as needed (for buttons)
     template = 'backoffice/wizard/addelection/base.html',
     super(AddElectionInstanceWizard, self).__init__(step1, template, *args, **kwargs)
Esempio n. 3
0
    def __init__(self, id, pos, *args, **kwargs):
        self.election_instance_party_id = id
        self.position = pos
        self.eip = get_object_or_404(ElectionInstanceParty, pk=self.election_instance_party_id)

        step1_forms = dict()
        idx = 0;
        for profile_form in get_profile_forms('candidate', 'invite'):
            step1_forms.update({'invite_contact_%s' % idx : profile_form})
            idx += 1

        step1 = Step('candidate',
            forms = step1_forms,
            template = 'backoffice/wizard/addcandidate/step1.html',
            extra_context={'instance':self.eip.election_instance, 'eip': self.eip }
        )
        template = 'backoffice/wizard/addcandidate/base.html'
        super(AddCandidateWizard, self).__init__(step1, template)
Esempio n. 4
0
 def __init__(self, instance, position, *args, **kwargs):
     self.election_instance = instance
     step1_forms = dict(
         initial_ep=InitialElectionPartyForm,
     )
     self.position = position
     idx = 0;
     for profile_form in get_profile_forms('party_admin', 'invite'):
         step1_forms.update({'invite_contact_%s' % idx : profile_form})
         idx += 1
     step1 = Step('electionparty', 
         forms=step1_forms,
         template='backoffice/wizard/addelectionparty/step1.html',
         initial={'initial_ep': {'position': position}},
         extra_context={'instance':self.election_instance, }
     )
     #default template is the base, each step can override it as needed (for buttons)
     template = 'backoffice/wizard/addelectionparty/base.html',
     super(AddElectionPartyWizard, self).__init__(step1, template, *args, **kwargs)
Esempio n. 5
0
    def __init__(self, id, pos, *args, **kwargs):
        self.election_instance_party_id = id
        self.position = pos
        self.eip = get_object_or_404(ElectionInstanceParty,
                                     pk=self.election_instance_party_id)

        step1_forms = dict()
        idx = 0
        for profile_form in get_profile_forms('candidate', 'invite'):
            step1_forms.update({'invite_contact_%s' % idx: profile_form})
            idx += 1

        step1 = Step('candidate',
                     forms=step1_forms,
                     template='backoffice/wizard/addcandidate/step1.html',
                     extra_context={
                         'instance': self.eip.election_instance,
                         'eip': self.eip
                     })
        template = 'backoffice/wizard/addcandidate/base.html'
        super(AddCandidateWizard, self).__init__(step1, template)
Esempio 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)
Esempio n. 7
0
    def wizard_fast_action(self, request, action, step, step_path, url_step, url_action, *args, **kwargs):
        """Loads correct models"""

        if action == "init":
            if 'election_instance_id' not in kwargs:
                raise

            user_id = kwargs['user_id'] if 'user_id' in kwargs else request.user.id
            election_instance_id = kwargs['election_instance_id']

            # Checking if user really exists and if election_instanc exists. Getting those and passing it to the wizard.
            election_instance = get_object_or_404(ElectionInstance, id=election_instance_id)
            user = get_object_or_404(User, id=user_id)

            ChanceryProfileClass = get_profile_model('council_admin')
            if user.profile.__class__ is not ChanceryProfileClass:
                raise HttpResponseForbidden("Wrong user profile")

            # reload data
            data = {}
            # [FIXME: adress field should be prefixed in data, automatic prefixing will not work]
            # will be fixed later

            # step 1 data
            stepdata = {}
            for (idx, profile_form) in enumerate(get_profile_forms('council_admin', 'edit')):
                if idx == 0:            
                    data.update({'chancery_registration': {'chancery_registration%d' % idx: {
                        'name': {
                            'first_name': user.profile.first_name,
                            'last_name': user.profile.last_name,
                            'middle_name': user.profile.middle_name,
                        },
                        'gender': user.profile.gender,
                        'telephone': user.profile.telephone or '',
                        'workingdays': user.profile.workingdays or '',
                    }}})
                    
            # step 2 data
            form = GStep.new_form(form = ElectionInstanceForm, initial = election_instance)
            data['election_details'] = {'election_details' : getattr(form, 'cleaned_data', {})}

            # step 3 data
            form = GStep.new_form(form = CouncilContactInformationForm, initial = election_instance.council.__dict__)
            data['council_contact_information'] = {'council_contact_information': getattr(form, 'cleaned_data', {})}
            
            # step 4 data
            form = GStep.new_form(form = CouncilForm, initial = election_instance.council)
            data['council_additional_information'] = {'council_additional_information': getattr(form, 'cleaned_data', {})}

            # step 5 data
            stepdata = {}
            for (idx, profile_form) in enumerate(get_profile_forms('council_admin', 'contact_information')):
                form = GStep.new_form(form = profile_form, initial = user.profile)
                stepdata['chancery_contact_information%s' % idx] = getattr(form, 'cleaned_data', {})

            data['chancery_contact_information'] = stepdata

            # step 6 data
            form = GStep.new_form(form = CouncilStylingSetupForm, initial = election_instance.council)
            data['council_styling_setup'] = {'council_styling_setup': getattr(form, 'cleaned_data', {})}

            # step 7 data
            form = GStep.new_form(form = ElectionInstanceSelectPartiesForm, initial = election_instance.parties.all())
            data['election_select_parties'] = {'election_select_parties': getattr(form, 'cleaned_data', {})}

            # store instances, we will use it in done()
            meta = {
                'user_id': user.id,
                'election_instance_id': election_instance.id,
            }
            # store data
            self.save_data(request, data, meta, *args, **kwargs)

            return redirect(url_step[0], *url_step[1], **dict(url_step[2], path = ''))

        # end of init
        raise Http404
Esempio n. 8
0
class ElectionSetupWizard(GraphFormWizard):

    # init action reloads the data
    fast_actions = frozenset(['init'])

    # wizard scenario
    scenario = GStep("chancery_registration", header = _("Welcome Chancellery!"), title = _("Registration")) \
                .forms(dict( [ ('chancery_registration%d' % idx, cls) for idx, cls in enumerate(get_profile_forms('council_admin', 'edit'))] )) \
                .field(help = _("This wizard will lead you through the process of setting up Wiekiesjij? for your municipality.")) \
                .field(next_button = _("Proceed to instance setup")) \
                \
                .next('election_details', header = _("Details about this election"), title = _("This Election")) \
                .form('election_details1', ElectionInstanceForm) \
                .field(next_button = _("Proceed to Council Setup")) \
                \
                .next('council_contact_information', header = _("Council contact information"), title = _("The Council")) \
                .form('council_contact_information1', CouncilContactInformationForm) \
                .field(next_button = _("Proceed")) \
                \
                .next('council_additional_information', header = _("Council: additional information"), title = _("More Council")) \
                .form('council_additional_information1', CouncilForm) \
                .field(help = _("You can fill in this information later"), next_button = _("Proceed to Chancellery")) \
                \
                .next('council_styling_setup', header = _("Setup styling"), title=_("Styling")) \
                .form('council_styling_setup', CouncilStylingSetupForm) \
                .field(help = _("On this page you can setup the styling for the Wiekiesjij? instance for your council.")) \
                .field(next_button = _("Proceed to Party selection")) \
                \
                .next('election_select_parties', template = 'backoffice/wizard/election_setup/step7.html') \
                .field(header = _("Previous parties"), title = _("Finish")) \
                .field(next_button = _("Finish")) \
                .form('election_select_parties', ElectionInstanceSelectPartiesForm)


    def __init__(self, name = None, template = 'backoffice/wizard/election_setup/_base.html'):
        super(type(self), self).__init__(name, template)


    def done(self, request, wizard_data, meta, *args, **kwargs):
        # OK, I'm to tired to finish this thing
        # The wizard data contains dicts with all the data
        # meta contains user_id and election_instance_id
        # we should save the data here and redirecto "done" location
        print wizard_data
        print meta

        return None


    def wizard_fast_action(self, request, action, step, step_path, url_step, url_action, *args, **kwargs):
        """Loads correct models"""

        if action == "init":
            if 'election_instance_id' not in kwargs:
                raise

            user_id = kwargs['user_id'] if 'user_id' in kwargs else request.user.id
            election_instance_id = kwargs['election_instance_id']

            # Checking if user really exists and if election_instanc exists. Getting those and passing it to the wizard.
            election_instance = get_object_or_404(ElectionInstance, id=election_instance_id)
            user = get_object_or_404(User, id=user_id)

            ChanceryProfileClass = get_profile_model('council_admin')
            if user.profile.__class__ is not ChanceryProfileClass:
                raise HttpResponseForbidden("Wrong user profile")

            # reload data
            data = {}
            # [FIXME: adress field should be prefixed in data, automatic prefixing will not work]
            # will be fixed later

            # step 1 data
            stepdata = {}
            for (idx, profile_form) in enumerate(get_profile_forms('council_admin', 'edit')):
                if idx == 0:            
                    data.update({'chancery_registration': {'chancery_registration%d' % idx: {
                        'name': {
                            'first_name': user.profile.first_name,
                            'last_name': user.profile.last_name,
                            'middle_name': user.profile.middle_name,
                        },
                        'gender': user.profile.gender,
                        'telephone': user.profile.telephone or '',
                        'workingdays': user.profile.workingdays or '',
                    }}})
                    
            # step 2 data
            form = GStep.new_form(form = ElectionInstanceForm, initial = election_instance)
            data['election_details'] = {'election_details' : getattr(form, 'cleaned_data', {})}

            # step 3 data
            form = GStep.new_form(form = CouncilContactInformationForm, initial = election_instance.council.__dict__)
            data['council_contact_information'] = {'council_contact_information': getattr(form, 'cleaned_data', {})}
            
            # step 4 data
            form = GStep.new_form(form = CouncilForm, initial = election_instance.council)
            data['council_additional_information'] = {'council_additional_information': getattr(form, 'cleaned_data', {})}

            # step 5 data
            stepdata = {}
            for (idx, profile_form) in enumerate(get_profile_forms('council_admin', 'contact_information')):
                form = GStep.new_form(form = profile_form, initial = user.profile)
                stepdata['chancery_contact_information%s' % idx] = getattr(form, 'cleaned_data', {})

            data['chancery_contact_information'] = stepdata

            # step 6 data
            form = GStep.new_form(form = CouncilStylingSetupForm, initial = election_instance.council)
            data['council_styling_setup'] = {'council_styling_setup': getattr(form, 'cleaned_data', {})}

            # step 7 data
            form = GStep.new_form(form = ElectionInstanceSelectPartiesForm, initial = election_instance.parties.all())
            data['election_select_parties'] = {'election_select_parties': getattr(form, 'cleaned_data', {})}

            # store instances, we will use it in done()
            meta = {
                'user_id': user.id,
                'election_instance_id': election_instance.id,
            }
            # store data
            self.save_data(request, data, meta, *args, **kwargs)

            return redirect(url_step[0], *url_step[1], **dict(url_step[2], path = ''))

        # end of init
        raise Http404