Ejemplo n.º 1
0
def csv_import_candidates_step3(request, ep_id):
    check_permissions(request, ep_id, 'party_admin')
    eip_obj = get_object_or_404(ElectionInstanceParty, pk=ep_id)
    try:
        positions = Candidacy.objects.filter(
            election_party_instance=eip_obj).values_list('position', flat=True)
        candidate_emails = Candidacy.objects.filter(
            election_party_instance=eip_obj).values_list('candidate__email',
                                                         flat=True)
        candidates = functions.get_candidates_from_csv(request.session,
                                                       positions,
                                                       candidate_emails)
    except:

        path = settings.TMP_ROOT + '/'
        if not os.path.isdir(path):
            os.remove(path + request.session['csv_candidate_filename'])
        request.session['csv_candidate_filename'] = ''
        return redirect('bo.csv_candidates_step2', ep_id=ep_id, error='true')

    if request.method == 'POST':
        form = CsvConfirmForm(request.POST)
        if form.is_valid():
            for candidate in candidates.values():
                try:
                    #Store data
                    tmp_data = {
                        'first_name': candidate['first_name'],
                        'middle_name': candidate['middle_name'],
                        'last_name': candidate['last_name'],
                        'initials': candidate['initials'],
                        'email': candidate['email'],
                        'gender': candidate['gender'],
                    }
                    created, candidate_obj = create_profile(
                        'candidate', tmp_data)

                    if candidate_obj is None:
                        continue

                    #Link candidate to party
                    Candidacy.objects.create(
                        election_party_instance=eip_obj,
                        candidate=candidate_obj.user,
                        position=candidate['position'],
                    )

                    #Create invitation TODO: view and text etc.
                    templates = profile_invite_email_templates('candidate')
                    Invitation.create(
                        user_from=request.user,
                        user_to=candidate_obj.user,
                        view=reverse('bo.politician_welcome',
                                     kwargs={'eip_id': eip_obj.id}),
                        text=
                        '<p>Wiekiesjij is de voorkeurstemhulp van Nederland. Middels het beantwoorden een vijftiental vragen zullen bezoekers gekoppeld worden aan hun favoriete kandidaten. Middels de informatie die u hier invult zullen wij daarnaast in staat zijn om de bezoekers de mogelijkheid te bieden om te browsen tussen alle kandidaten, de partijen en is het mogelijk om de uitgebreide profielen van alle politici te bekijken.</p>',
                        subject=ugettext('Invitation Wiekiesjij'),
                        html_template=templates['html'],
                        plain_template=templates['plain'],
                    )

                    position = int(candidate['position'])
                    if position > eip_obj.list_length:
                        eip_obj.list_length = position
                        eip_obj.save()

                except:
                    transaction.rollback()
                    raise

            transaction.commit()
            os.remove(settings.TMP_ROOT + '/' +
                      request.session['csv_candidate_filename'])
            request.session['csv_candidate_filename'] = ''
            return redirect('bo.election_party_view', id=ep_id)
    else:
        form = CsvConfirmForm()
    eip = get_object_or_404(ElectionInstanceParty, pk=ep_id)
    forms = dict({'csv_confirm': form})
    return render_to_response('backoffice/csv_candidates_3.html', {
        'candidates': candidates,
        'forms': forms,
        'ep_id': ep_id,
        'instance': eip.election_instance
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 2
0
def csv_import_parties_step3(request, ei_id):
    check_permissions(request, ei_id, 'council_admin')
    ei_obj = get_object_or_404(ElectionInstance, pk=ei_id)
    try:
        lists = ElectionInstanceParty.objects.filter(election_instance=ei_obj).values_list('position', flat=True)
        parties = functions.get_parties_from_csv(request.session, lists)
    except:
        path = settings.TMP_ROOT + '/'
        if not os.path.isdir(path):
            os.remove(path + request.session['csv_party_filename'])
        request.session['csv_party_filename'] = ''
        return redirect('bo.csv_parties_step2', ei_id = ei_id, error='true')

    if request.method == 'POST':
        form = CsvConfirmForm(request.POST)
        if form.is_valid():

            council = ei_obj.council
            region = council.region
            level = council.level

            for party in parties.values():
                try:
                    #Store data
                    tmp_data = {
                        'first_name': party['contact_first_name'],
                        'middle_name': party['contact_middle_name'],
                        'last_name': party['contact_last_name'],
                        'email': party['contact_email'],
                        'gender': party['contact_gender'],
                    }
                    created, contact = create_profile('party_admin', tmp_data)

                    if contact is None:
                        continue

                    party_obj = Party.objects.create(
                        region = region,
                        level = level,
                        name = party['name'],
                        abbreviation = party['abbreviation'],
                    )

                    eip_obj = ElectionInstanceParty.objects.create(
                        election_instance = ei_obj,
                        party = party_obj,
                        position = unicode(party['list']),
                        list_length = 10, #TODO, maybe add in CSV
                    )

                    party_obj.contacts.add(contact.user)
                    party_obj.save()

                    #Create invitation
                    templates = profile_invite_email_templates('party_admin')
                    Invitation.create(
                        user_from = request.user,
                        user_to = contact.user,
                        view=reverse('bo.party_contact_wizard', kwargs={'id': eip_obj.pk}),
                        text='<p>U bent aangekomen op de beheerderpagina van Wiekiesjij. Om Wiekiesjij gereed te maken voor uw partij volgen er nu een aantal schermen waarin u informatie kunt achterlaten. Wanneer deze informatie is ingevuld zullen we overgaan tot het uitnodigen van de kandidaten van uw partij.</p><p>We beginnen met het instellen van een wachtwoord voor Wiekiesjij door op <strong>Accepteer uitnodiging</strong> te klikken. Heeft u al eens eerder gebruik gemaakt van Wiekiesjij, drukt u dan op <strong>Ik heb al een account</strong>.</p><p>Om het gereedmaken van Wiekiesjij zo gemakkelijk mogelijk te laten verlopen hebben we een snelle start [link] handleiding [/link] beschikbaar gesteld die u kunt raadplegen.</p>',
                        subject = ugettext('Invitation Wiekiesjij'),
                        html_template = templates['html'],
                        plain_template = templates['plain'],
                    )

                    max_list = int(party['list'])
                    if max_list > ei_obj.num_lists:
                        ei_obj.num_lists = max_list
                        ei_obj.save()

                except:
                    transaction.rollback()
                    raise
                else:
                    transaction.commit()

            os.remove(settings.TMP_ROOT + '/' + request.session['csv_party_filename'])
            request.session['csv_party_filename'] = ''
            return redirect('bo.election_instance_view', id=ei_id)
    else:
        form = CsvConfirmForm()
    ei_obj = get_object_or_404(ElectionInstance, id=ei_id)
    forms = dict({'csv_confirm': form})
    return render_to_response('backoffice/csv_parties_3.html', {'parties':parties, 'forms':forms, 'ei_id': ei_id, 'instance':ei_obj}, context_instance=RequestContext(request))
Ejemplo n.º 3
0
def csv_import_parties_step3(request, ei_id):
    check_permissions(request, ei_id, 'council_admin')
    ei_obj = get_object_or_404(ElectionInstance, pk=ei_id)
    try:
        lists = ElectionInstanceParty.objects.filter(
            election_instance=ei_obj).values_list('position', flat=True)
        parties = functions.get_parties_from_csv(request.session, lists)
    except:
        path = settings.TMP_ROOT + '/'
        if not os.path.isdir(path):
            os.remove(path + request.session['csv_party_filename'])
        request.session['csv_party_filename'] = ''
        return redirect('bo.csv_parties_step2', ei_id=ei_id, error='true')

    if request.method == 'POST':
        form = CsvConfirmForm(request.POST)
        if form.is_valid():

            council = ei_obj.council
            region = council.region
            level = council.level

            for party in parties.values():
                try:
                    #Store data
                    tmp_data = {
                        'first_name': party['contact_first_name'],
                        'middle_name': party['contact_middle_name'],
                        'last_name': party['contact_last_name'],
                        'email': party['contact_email'],
                        'gender': party['contact_gender'],
                    }
                    created, contact = create_profile('party_admin', tmp_data)

                    if contact is None:
                        continue

                    party_obj = Party.objects.create(
                        region=region,
                        level=level,
                        name=party['name'],
                        abbreviation=party['abbreviation'],
                    )

                    eip_obj = ElectionInstanceParty.objects.create(
                        election_instance=ei_obj,
                        party=party_obj,
                        position=unicode(party['list']),
                        list_length=10,  #TODO, maybe add in CSV
                    )

                    party_obj.contacts.add(contact.user)
                    party_obj.save()

                    #Create invitation
                    templates = profile_invite_email_templates('party_admin')
                    Invitation.create(
                        user_from=request.user,
                        user_to=contact.user,
                        view=reverse('bo.party_contact_wizard',
                                     kwargs={'id': eip_obj.pk}),
                        text=
                        '<p>U bent aangekomen op de beheerderpagina van Wiekiesjij. Om Wiekiesjij gereed te maken voor uw partij volgen er nu een aantal schermen waarin u informatie kunt achterlaten. Wanneer deze informatie is ingevuld zullen we overgaan tot het uitnodigen van de kandidaten van uw partij.</p><p>We beginnen met het instellen van een wachtwoord voor Wiekiesjij door op <strong>Accepteer uitnodiging</strong> te klikken. Heeft u al eens eerder gebruik gemaakt van Wiekiesjij, drukt u dan op <strong>Ik heb al een account</strong>.</p><p>Om het gereedmaken van Wiekiesjij zo gemakkelijk mogelijk te laten verlopen hebben we een snelle start [link] handleiding [/link] beschikbaar gesteld die u kunt raadplegen.</p>',
                        subject=ugettext('Invitation Wiekiesjij'),
                        html_template=templates['html'],
                        plain_template=templates['plain'],
                    )

                    max_list = int(party['list'])
                    if max_list > ei_obj.num_lists:
                        ei_obj.num_lists = max_list
                        ei_obj.save()

                except:
                    transaction.rollback()
                    raise
                else:
                    transaction.commit()

            os.remove(settings.TMP_ROOT + '/' +
                      request.session['csv_party_filename'])
            request.session['csv_party_filename'] = ''
            return redirect('bo.election_instance_view', id=ei_id)
    else:
        form = CsvConfirmForm()
    ei_obj = get_object_or_404(ElectionInstance, id=ei_id)
    forms = dict({'csv_confirm': form})
    return render_to_response('backoffice/csv_parties_3.html', {
        'parties': parties,
        'forms': forms,
        'ei_id': ei_id,
        'instance': ei_obj
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 4
0
def csv_import_candidates_step3(request, ep_id):
    check_permissions(request, ep_id, 'party_admin')
    eip_obj = get_object_or_404(ElectionInstanceParty, pk=ep_id)
    try:
        positions = Candidacy.objects.filter(election_party_instance=eip_obj).values_list('position', flat=True)
        candidate_emails = Candidacy.objects.filter(election_party_instance=eip_obj).values_list('candidate__email', flat=True)
        candidates = functions.get_candidates_from_csv(request.session, positions, candidate_emails)
    except:

        path = settings.TMP_ROOT + '/'
        if not os.path.isdir(path):
            os.remove(path + request.session['csv_candidate_filename'])
        request.session['csv_candidate_filename'] = ''
        return redirect('bo.csv_candidates_step2', ep_id=ep_id, error='true')

    if request.method == 'POST':
        form = CsvConfirmForm(request.POST)
        if form.is_valid():
            for candidate in candidates.values():
                try:
                    #Store data
                    tmp_data = {
                        'first_name': candidate['first_name'],
                        'middle_name': candidate['middle_name'],
                        'last_name': candidate['last_name'],
                        'initials': candidate['initials'],
                        'email': candidate['email'],
                        'gender': candidate['gender'],
                    }
                    created, candidate_obj = create_profile('candidate', tmp_data)

                    if candidate_obj is None:
                        continue

                    #Link candidate to party
                    Candidacy.objects.create(
                        election_party_instance = eip_obj,
                        candidate = candidate_obj.user,
                        position = candidate['position'],
                    )

                    #Create invitation TODO: view and text etc.
                    templates = profile_invite_email_templates('candidate')
                    Invitation.create(
                        user_from = request.user,
                        user_to = candidate_obj.user,
                        view = reverse('bo.politician_welcome', kwargs={'eip_id': eip_obj.id}),
                        text = '<p>Wiekiesjij is de voorkeurstemhulp van Nederland. Middels het beantwoorden een vijftiental vragen zullen bezoekers gekoppeld worden aan hun favoriete kandidaten. Middels de informatie die u hier invult zullen wij daarnaast in staat zijn om de bezoekers de mogelijkheid te bieden om te browsen tussen alle kandidaten, de partijen en is het mogelijk om de uitgebreide profielen van alle politici te bekijken.</p>',
                        subject = ugettext('Invitation Wiekiesjij'),
                        html_template = templates['html'],
                        plain_template = templates['plain'],
                    )

                    position = int(candidate['position'])
                    if position > eip_obj.list_length:
                        eip_obj.list_length = position
                        eip_obj.save()

                except:
                    transaction.rollback()
                    raise

            transaction.commit()
            os.remove(settings.TMP_ROOT + '/' + request.session['csv_candidate_filename'])
            request.session['csv_candidate_filename'] = ''
            return redirect('bo.election_party_view', id=ep_id)
    else:
        form = CsvConfirmForm()
    eip = get_object_or_404(ElectionInstanceParty, pk=ep_id)
    forms = dict({'csv_confirm': form})
    return render_to_response('backoffice/csv_candidates_3.html', {'candidates':candidates, 'forms':forms, 'ep_id':ep_id, 'instance':eip.election_instance}, context_instance=RequestContext(request))