def ab3_address(): form = FormAB3( addr = g.registrant.try_value('addr'), unit = g.registrant.try_value('unit'), city = g.registrant.try_value('city'), state = g.registrant.try_value('state', 'FLORIDA'), zip = g.registrant.try_value('zip'), has_mail_addr = g.registrant.try_value('has_mail_addr'), mail_addr = g.registrant.try_value('mail_addr'), mail_unit = g.registrant.try_value('mail_unit'), mail_city = g.registrant.try_value('mail_city'), mail_state = g.registrant.try_value('mail_state'), mail_zip = g.registrant.try_value('mail_zip'), ) if request.method == "POST" and form.validate_on_submit(): step = Step_AB_3(form.data) if step.run(): update_data = form.data update_data['validated_addresses'] = step.validated_addresses g.registrant.update(update_data) g.registrant.addr_lookup_complete = step.addr_lookup_complete # override initial county guess with best guess based on validated address zip5 = g.registrant.best_zip5() county = ZIPCode.guess_county(zip5) current_app.logger.info("Lookup county %s based on ZIP5 %s" %(county, zip5)) g.registrant.county = county db.session.commit() session_manager = SessionManager(g.registrant, step) return redirect(session_manager.get_redirect_url()) return render_template('/ab/address.html', form=form)
def ab1_election_picker(): reg = g.registrant form = FormAB1(party=reg.try_value('party'), perm_reason=reg.try_value('perm_reason')) if request.method == 'GET': # must assign at run time for date math. form.elections.choices = list_of_elections() form.elections.data = reg.elections() if request.method == "POST" and form.validate_on_submit(): step = Step_AB_1(form.data) if step.run(): reg.update(form.data) if 'permanent' in reg.elections(): reg.ab_permanent = True else: reg.ab_permanent = False reg.save(db.session) session_manager = SessionManager(reg, step) return redirect(session_manager.get_redirect_url()) return render_template('ab/election_picker.html', form=form, is_even_year=is_even_year())
def vr7_affirmation(): reg = g.registrant clerk = reg.try_clerk() form = FormVR7() county_picker = CountyPicker() # if we don't have a VR form to affirm, redirect to Step 0 if not reg.try_value('vr_form', False): return redirect(url_for('main.index')) vr_form = reg.try_value('vr_form') if request.method == "POST" and form.validate_on_submit(): step = Step_VR_7(form.data) if step.run(): reg.update(form.data) reg.save(db.session) mailer = CountyMailer(reg, clerk, 'vr_form') r = mailer.send() # any error gets a special page for k in ['clerk', 'receipt']: if k not in r or 'MessageId' not in r[k] or not r[k]['MessageId']: # TODO log New Relic event return render_template('email_error.html', clerk=clerk) reg.update({'vr_form_message_id': r['clerk']['MessageId']}) reg.vr_completed_at = datetime.utcnow() reg.save(db.session) session_manager = SessionManager(reg, step) return redirect(session_manager.get_redirect_url()) return render_template('vr/affirmation.html', clerk=clerk, preview_img=vr_form, form=form, county_picker=county_picker)
def vr6_preview_sign(): reg = g.registrant form = FormVR6(signature_string=reg.try_value('signature_string')) nvris_client = NVRISClient(reg) if request.method == "POST" and form.validate_on_submit(): step = Step_VR_6(form.data) if step.run(): # add signature img but do not save till we have signed form too. reg.update(form.data) # sign the form and cache the image for next step signed_vr_form = nvris_client.get_vr_form() if signed_vr_form: reg.update({'vr_form': signed_vr_form}) reg.signed_at = datetime.utcnow() reg.save(db.session) session_manager = SessionManager(reg, step) return redirect(session_manager.get_redirect_url()) # always generate a new unsigned form for preview preview_img = nvris_client.get_vr_form() return render_template('vr/preview-sign.html', preview_img=preview_img, registrant=reg, form=form)
def ab6_preview_sign(): reg = g.registrant form = FormAB6( signature_string = reg.try_value('signature_string') ) nvris_client = NVRISClient(reg) county_picker = CountyPicker() clerk = reg.try_clerk() if request.method == "POST" and form.validate_on_submit(): step = Step_AB_6(form.data) if step.run(): # add signature img but do not save till we have signed form too. reg.update(form.data) # sign the form and cache the image for next step ab_forms = reg.sign_ab_forms() if ab_forms and len(ab_forms) > 0: reg.save(db.session) session_manager = SessionManager(reg, step) return redirect(session_manager.get_redirect_url()) # always generate a new unsigned form for preview preview_imgs = [] for election in reg.elections(): preview_img = nvris_client.get_ab_form(election) if preview_img: preview_imgs.append(preview_img) return render_template('ab/preview-sign.html', preview_imgs=preview_imgs, registrant=reg, form=form, county_picker=county_picker, clerk=clerk)
def test_non_previous_step_non_complete_step(app, db_session, client): """ A non complete step should return the current steps endpoint """ registrant = create_registrant(db_session) step = Step_0() session_manager = SessionManager(registrant, step) assert session_manager.get_redirect_url() == step.endpoint
def vr8_submission(): reg = g.registrant session_manager = SessionManager(reg, Step_VR_7()) if not session_manager.vr_completed(): return redirect(session_manager.get_redirect_url()) clerk = reg.try_clerk() return render_template('vr/submission.html', registrant=reg, clerk=clerk)
def test_registrant_doesnt_have_values(app, db_session, client): """ A registrant should be redirected to previous step if missing values of that step """ registrant = create_registrant(db_session) form_payload = {'is_citizen': True} step = Step_VR_1(form_payload) step.run() session_manager = SessionManager(registrant, step) assert session_manager.get_redirect_url() == '/'
def vr5_identification(): form = FormVR5(identification=g.registrant.registration_value.get( 'identification', ''), ) if request.method == "POST" and form.validate_on_submit(): step = Step_VR_5(form.data) step.run() g.registrant.update(form.data) db.session.commit() session_manager = SessionManager(g.registrant, step) return redirect(session_manager.get_redirect_url()) return render_template('vr/identification.html', form=form)
def vr4_party(): form = FormVR4(party=g.registrant.party, ) if request.method == "POST" and form.validate_on_submit(): step = Step_VR_4(form.data) step.run() g.registrant.update(form.data) g.registrant.save(db.session) session_manager = SessionManager(g.registrant, step) return redirect(session_manager.get_redirect_url()) return render_template('vr/party.html', form=form)
def test_no_previous_step_is_complete(app, db_session, client): """ A complete step should return the next steps endpoint """ registrant = create_registrant(db_session) step = Step_0() #mock step actions step.is_complete = True step.next_step = 'Step_VR_1' session_manager = SessionManager(registrant, step) assert session_manager.get_redirect_url() == '/vr/citizenship'
def ab5_identification(): ab_id = g.registrant.try_value('ab_identification') form = FormAB5(ab_identification=ab_id) clerk = g.registrant.try_clerk() if request.method == "POST" and form.validate_on_submit(): step = Step_AB_5(form.data) if step.run(): g.registrant.update(form.data) db.session.commit() session_manager = SessionManager(g.registrant, step) return redirect(session_manager.get_redirect_url()) return render_template('ab/identification.html', form=form, clerk=clerk)
def ab7_affirmation(): reg = g.registrant form = FormAB7() clerk = reg.try_clerk() county_picker = CountyPicker() # if we don't have a signed AB form to affirm, redirect if not reg.try_value('ab_forms', False): if not reg.try_value('signature_string', False): return redirect(url_for('main.index')) else: return redirect(url_for('main.ab6_preview_sign')) ab_forms = reg.try_value('ab_forms') if request.method == "POST" and form.validate_on_submit(): step = Step_AB_7(form.data) if step.run(): reg.update(form.data) reg.save(db.session) mailer = CountyMailer(reg, clerk, 'ab_forms') r = mailer.send() # if there was no ID string defined, send the action-needed email if not reg.ab_permanent and not reg.try_value('ab_identification'): id_action_mailer = IdActionMailer(reg, clerk) resp = id_action_mailer.send() reg.update({'ab_id_action_email_sent': resp['MessageId']}) # any error gets a special page for k in ['clerk', 'receipt']: if k not in r or 'MessageId' not in r[ k] or not r[k]['MessageId']: # TODO log New Relic event return render_template('email_error.html', clerk=clerk) reg.update({'ab_forms_message_id': r['clerk']['MessageId']}) reg.ab_completed_at = datetime.utcnow() reg.save(db.session) session_manager = SessionManager(reg, step) return redirect(session_manager.get_redirect_url()) return render_template('ab/affirmation.html', preview_imgs=ab_forms, form=form, clerk=clerk, county_picker=county_picker)
def vr1_citizenship(): reg = g.registrant form = FormVR1( is_citizen=reg.is_citizen, is_eighteen=reg.is_eighteen, ) if request.method == "POST" and form.validate_on_submit(): step = Step_VR_1(form.data) if step.run(): reg.update(form.data) reg.save(db.session) session_manager = SessionManager(reg, step) return redirect(session_manager.get_redirect_url()) return render_template('vr/citizenship.html', form=form)
def vr2_name(): form = FormVR2( prefix = g.registrant.registration_value.get('prefix', ''), name_first = g.registrant.registration_value.get('name_first', ''), name_middle = g.registrant.registration_value.get('name_middle', ''), name_last = g.registrant.registration_value.get('name_last', ''), suffix = g.registrant.registration_value.get('suffix', ''), has_prev_name = g.registrant.registration_value.get('has_prev_name', ''), prev_prefix = g.registrant.registration_value.get('prev_prefix', ''), prev_name_first = g.registrant.registration_value.get('prev_name_first', ''), prev_name_middle = g.registrant.registration_value.get('prev_name_middle', ''), prev_name_last = g.registrant.registration_value.get('prev_name_last', ''), prev_suffix = g.registrant.registration_value.get('prev_suffix', ''), ) if request.method == "POST" and form.validate_on_submit(): step = Step_VR_2(form.data) step.run() g.registrant.update(form.data) db.session.commit() session_manager = SessionManager(g.registrant,step) return redirect(session_manager.get_redirect_url()) return render_template('vr/name.html', form=form)
def index(): registrant = g.registrant form = FormStep0() if http_session.get('ref'): form = FormStep0(ref=http_session.get('ref')) elif request.cookies.get('ref'): form = FormStep0(ref=request.cookies.get('ref')) if registrant: form = FormStep0( ref=http_session.get('ref'), name_first=registrant.try_value('name_first'), name_last=registrant.try_value('name_last'), dob=registrant.try_value('dob'), zip=registrant.try_value('zip'), email=registrant.try_value('email'), phone=registrant.try_value('phone') ) if request.method == "POST" and form.validate_on_submit(): step = Step_0(form.data) if registrant: registrant.update(form.data) else: sid = UUID(http_session.get('session_id'), version=4) zipcode = form.data.get('zip') registrant = Registrant( county=ZIPCode.guess_county(zipcode), ref=form.data.get('ref'), registration_value=form.data, session_id=sid, lang=g.lang_code, ) registrant.set_value('zip', zipcode) db.session.add(registrant) skip_sos = request.values.get('skip-sos') step.run(skip_sos) registrant.reg_lookup_complete = step.reg_lookup_complete registrant.dob_year = registrant.get_dob_year() sos_reg = None sos_failure = None if step.reg_found: sos_reg = [] for rec in step.reg_found: rec2save = {'tree': rec['tree']} if 'sample_ballots' in rec: rec2save['sample_ballot'] = rec['sample_ballots'] if 'districts' in rec: rec2save['districts'] = rec['districts'] if 'elections' in rec: rec2save['elections'] = rec['elections'] # prepopulate address and party, if possible try: registrant.populate_address(rec2save['tree']) except: # just swallow errors for now err = sys.exc_info()[0] current_app.logger.error(str(err)) sos_reg.append(rec2save) else: sos_failure = step.voter_view_fail registrant.update({'sos_reg': sos_reg, 'skip_sos': skip_sos, 'sos_failure': sos_failure}) registrant.save(db.session) # small optimization for common case. if skip_sos and not current_app.config['ENABLE_AB']: return redirect(url_for('main.vr1_citizenship')) session_manager = SessionManager(registrant, step) return redirect(session_manager.get_redirect_url()) else: has_announcements = False if lazy_gettext('announce') != "announce": has_announcements = True return render_template('index.html', form=form, has_announcements=has_announcements)