Ejemplo n.º 1
0
    def register(self, request, **kwargs):
        email, password = kwargs['email'], kwargs['password']
        if Site._meta.installed:
            site = Site.objects.get_current()
        else:
            site = RequestSite(request)
        username = self._generate_username()
        new_user = RegistrationProfile.objects.create_inactive_user(username, email, password, site, send_email=False)
   
        reg_profile = RegistrationProfile.objects.get(user=new_user)

        send_email(
                _('Wiekiesjij - User Registration'),
                '*****@*****.**',
                email,
                {'site': site, 'activation_key': reg_profile.activation_key },
                {'plain': 'registration/activation_email.txt','html': 'registration/_activation_email.html'},
        )

 
        ProfileModel = get_profile_model('visitor')
        
        ProfileModel.objects.create(
            first_name=kwargs['first_name'],
            middle_name=kwargs['middle_name'],
            last_name=kwargs['last_name'],
            user=new_user,
        )
        
        signals.user_registered.send(sender=self.__class__, user=new_user, request=request)
        
        return new_user
Ejemplo n.º 2
0
    def register(self, request, **kwargs):
        email, password = kwargs['email'], kwargs['password']
        if Site._meta.installed:
            site = Site.objects.get_current()
        else:
            site = RequestSite(request)
        username = self._generate_username()
        new_user = RegistrationProfile.objects.create_inactive_user(
            username, email, password, site, send_email=False)

        reg_profile = RegistrationProfile.objects.get(user=new_user)

        send_email(
            _('Wiekiesjij - User Registration'),
            '*****@*****.**',
            email,
            {
                'site': site,
                'activation_key': reg_profile.activation_key
            },
            {
                'plain': 'registration/activation_email.txt',
                'html': 'registration/_activation_email.html'
            },
        )

        ProfileModel = get_profile_model('visitor')

        ProfileModel.objects.create(
            first_name=kwargs['first_name'],
            middle_name=kwargs['middle_name'],
            last_name=kwargs['last_name'],
            user=new_user,
        )

        signals.user_registered.send(sender=self.__class__,
                                     user=new_user,
                                     request=request)

        return new_user
Ejemplo n.º 3
0
    def __init__(self, *args, **kwargs):
        self.user_id, self.election_instance_party_id = kwargs[
            'user_id'], kwargs['election_instance_party_id']
        self.election_instance_party = ElectionInstanceParty.objects.get(
            id=self.election_instance_party_id)

        self.user = User.objects.get(id=self.user_id)

        self.candidate_profile = self.user.profile

        # Candidacy to whom the answers are coupled.
        self.candidacy = Candidacy.objects.get(
            election_party_instance=self.election_instance_party,
            candidate=self.user)

        candidate_question_answers = self.candidacy.answers.all()
        candidate_question_answers = map(lambda x: (x.id, x.question_id),
                                         candidate_question_answers)

        CandidateProfileClass = get_profile_model('candidate')
        if CandidateProfileClass.__name__ != self.user.profile.__class__.__name__:
            raise Exception

        # Getting all the questions applicable
        questions = self.election_instance_party.election_instance.questions.filter(
            question_type__in=BACKOFFICE_QUESTION_TYPES).order_by(
                '-electioninstancequestion__position')

        steps_tree = []

        # Looping through the questions
        idx = 1
        for question in questions:
            try:
                # Here we need to get the answer given for the step
                question_answers = []
                for answer_id, question_id in candidate_question_answers:
                    if question_id == question.id:
                        # I realise that it's kind of stupid loop, 'cause I could use simply filter on the initial list
                        # TODO: rewrite when have time, but it works so as well, although it could be done nicer.
                        # In case of multiple answers we make a list of those.
                        if question.question_type in MULTIPLE_ANSWER_TYPES:
                            question_answers.append(answer_id)
                        else:
                            question_answers = answer_id

            except Exception:

                # Otherwise we shall specify an initial value for it
                question_answers = ''

            if not question.question_type in FRONTOFFICE_QUESTION_TYPES:
                secret = 'secret'
            else:
                secret = 'not secret'

            step = Step(
                str(question.id),
                forms={str(question.id): AnswerQuestionForm},
                template='backoffice/wizard/question/answer_add/step.html',
                initial={str(question.id): {
                             'value': question_answers
                         }},  # TODO: Fix this = load the data!
                extra_context={
                    'questions': range(0, questions.count()),
                    'current_question': questions.count() - idx,
                    'question_title': question.title,
                    'initial': question_answers,
                    'secret': secret
                },
                form_kwargs={
                    str(question.id): {
                        'question_instance_id': question.id
                    }
                })
            steps_tree.append(step)
            idx += 1

        scenario_tree = None
        for step in steps_tree:
            if None == scenario_tree:
                scenario_tree = step.next()
            else:
                scenario_tree = step.next(scenario_tree)

        template = 'backoffice/wizard/council/edit/base.html',
        super(AnswerQuestion, self).__init__(scenario_tree, template)
Ejemplo n.º 4
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
Ejemplo n.º 5
0
    def __init__(self, *args, **kwargs):
        self.user_id, self.election_instance_party_id = kwargs['user_id'], kwargs['election_instance_party_id']
        self.election_instance_party = ElectionInstanceParty.objects.get(id=self.election_instance_party_id)

        self.user = User.objects.get(id=self.user_id)

        self.candidate_profile = self.user.profile

        # Candidacy to whom the answers are coupled.
        self.candidacy = Candidacy.objects.get(election_party_instance=self.election_instance_party,
                                               candidate=self.user)

        candidate_question_answers = self.candidacy.answers.all()
        candidate_question_answers = map(lambda x: (x.id, x.question_id), candidate_question_answers)

        CandidateProfileClass = get_profile_model('candidate')
        if CandidateProfileClass.__name__ != self.user.profile.__class__.__name__:
            raise Exception

        # Getting all the questions applicable
        questions = self.election_instance_party.election_instance.questions.filter(question_type__in=BACKOFFICE_QUESTION_TYPES).order_by('-electioninstancequestion__position')

        steps_tree = []

        # Looping through the questions
        idx = 1;
        for question in questions:
            try:
                # Here we need to get the answer given for the step
                question_answers = []
                for answer_id, question_id in candidate_question_answers:
                    if question_id == question.id:
                        # I realise that it's kind of stupid loop, 'cause I could use simply filter on the initial list
                        # TODO: rewrite when have time, but it works so as well, although it could be done nicer.
                        # In case of multiple answers we make a list of those.
                        if question.question_type in MULTIPLE_ANSWER_TYPES:
                            question_answers.append(answer_id)
                        else:
                            question_answers = answer_id

            except Exception:

                # Otherwise we shall specify an initial value for it
                question_answers = ''

            if not question.question_type in FRONTOFFICE_QUESTION_TYPES:
                secret = 'secret'
            else:
                secret = 'not secret'

            step = Step(str(question.id),
                     forms={str(question.id): AnswerQuestionForm},
                     template='backoffice/wizard/question/answer_add/step.html',
                     initial={str(question.id): {'value': question_answers}}, # TODO: Fix this = load the data!
                     extra_context={'questions': range(0, questions.count()), 'current_question': questions.count() - idx, 'question_title': question.title, 'initial': question_answers, 'secret': secret},
                     form_kwargs={str(question.id): {'question_instance_id': question.id}})
            steps_tree.append(step)
            idx += 1

        scenario_tree = None
        for step in steps_tree:
            if None == scenario_tree:
                scenario_tree = step.next()
            else:
                scenario_tree = step.next(scenario_tree)

        template = 'backoffice/wizard/council/edit/base.html',
        super(AnswerQuestion, self).__init__(scenario_tree, template)