Beispiel #1
0
def get_precinct(d):
    jwp = '%s:%s:%s' % (
        d['jurisdiction_code'], d['ward'], d['precinct']
    )
    if jwp not in precincts:
        pid = Precinct.add(dao, d)
        p = Precinct(d)
        p.id = pid
        precincts[jwp] = p.serialize()
        return pid
    return precincts[jwp]['id']
Beispiel #2
0
def assign_precinct():
    from models.precinct import Precinct

    if request.method == 'GET':
        precincts = Precinct.get_all()
        contacts = Contact.get_with_missing_precinct()
        return render_template('contacts/con_precinct.html',
                               title='Unassigned Precinct',
                               precincts=precincts,
                               contacts=contacts)

    params = json.loads(request.form['params'])
    contact = Contact(params)
    dao = Dao(stateful=True)
    if 'voter_id' in params and params['voter_id']:
        voter = Voter.get_one(dao, params['voter_id'])
        nickname = contact.name.first
        contact.name = voter.name
        contact.name.nickname = nickname
        contact.address = voter.address
        contact.reg_date = voter.reg_date
    try:
        contact.update(dao)
        return jsonify(msg="Update successful!")
    except Exception as ex:
        return jsonify(error=str(ex))
    finally:
        dao.close()
Beispiel #3
0
def user_mgt():
    from models.precinct import Precinct

    dao = Dao(stateful=True)
    jurisdictions = Precinct.get_jurisdictions(dao)
    precincts = Precinct.get_all(dao)
    roles = User.get_roles(dao)
    users = User.get_users(dao)
    precinct_admins = User.get_precinct_admins(dao)
    dao.close()
    return render_template(
        'users.html',
        title='Bluestreets users',
        jurisdictions=jurisdictions,
        precincts=[precinct.serialize() for precinct in precincts],
        roles=roles,
        users=users,
        precinct_admins=precinct_admins)
Beispiel #4
0
def crewboard():
    if request.method == 'GET':
        dao = Dao(stateful=True)
        contacts = Contact.get_activists(dao)
        precincts = Precinct.get_all(dao)
        return render_template(
            'con_crewboard.html',
            title='Battle Stations',
            contacts=[contact.serialize() for contact in contacts],
            precincts=[precinct.serialize() for precinct in precincts])
Beispiel #5
0
def user_mgt():
    from models.precinct import Precinct

    dao = Dao(stateful=True)
    jurisdictions = Precinct.get_jurisdictions(dao)
    precincts = Precinct.get_all(dao)
    roles = User.get_roles(dao)
    users = User.get_users(dao)
    precinct_admins = User.get_precinct_admins(dao)
    dao.close()
    return render_template(
        'users.html',
        title='Bluestreets users',
        jurisdictions=jurisdictions,
        precincts=[precinct.serialize() for precinct in precincts],
        roles=roles,
        users=users,
        precinct_admins=precinct_admins
    )
Beispiel #6
0
def crewboard():
    if request.method == 'GET':
        dao = Dao(stateful=True)
        contacts = Contact.get_activists(dao)
        precincts = Precinct.get_all(dao)
        return render_template(
            'con_crewboard.html',
            title='Battle Stations',
            contacts=[contact.serialize() for contact in contacts],
            precincts=[precinct.serialize() for precinct in precincts]
        )
def execute():
    precincts = Precinct.get_all(dao)
    precinct_dict = Utils.to_dict(precincts)
    groups = Group.get_all(dao)
    for group in groups:
        contacts = Contact.get_by_group(dao, group.id)
        if not contacts:
            continue
        csv_file = open(group.code + '.csv', "w", newline='')
        wrt = csv.writer(csv_file)
        wrt.writerow(first_row)
        for contact in contacts:
            row = [
                str(contact.name), contact.info.email, contact.info.phone1,
                contact.info.phone2,
                str(contact.address), contact.address.city,
                contact.address.zipcode,
                precinct_dict[contact.precinct_id].jurisdiction_name,
                precinct_dict[contact.precinct_id].ward,
                precinct_dict[contact.precinct_id].precinct, contact.gender,
                contact.birth_year
            ]
            wrt.writerow(row)
        csv_file.close()
Beispiel #8
0
def get_precinct(d):
    jwp = '%s:%s:%s' % (
        d['jurisdiction_code'], d['ward'], d['precinct']
    )
    if jwp not in precincts:
        pid = Precinct.add(dao, d)
        p = Precinct(d)
        p.id = pid
        precincts[jwp] = p.serialize()
        return pid
    return precincts[jwp]['id']


# def add_precinct(d):

if __name__ == '__main__':
    from models.precinct import Precinct

    fldnames = [
        'last_name', 'first_name', 'middle_name', 'name_suffix',
        'last_name_meta', 'first_name_meta', 'birth_year', 'gender',
        'house_number', 'pre_direction', 'street_name', 'street_type',
        'suf_direction', 'unit', 'street_name_meta', 'city', 'zipcode',
        'precinct_id', 'voter_id', 'reg_date',
        'permanent_absentee', 'status', 'uocava'
    ]

    dao = Dao(db_file='c:/bench/bluestreets/data/26161.db', stateful=True)
    precincts = Precinct.get_by_jwp(dao)
    do_it()
Beispiel #9
0
def con_get():
    from utils.utils import Utils

    dao = Dao(stateful=True)
    jurisdiction_code = request.args['jurisdiction_code']
    try:
        memberships = GroupMember.get_code_lists(dao)
        precincts = Precinct.get_by_jurisdiction(dao, jurisdiction_code)
        precinct_dict = Utils.to_dict(precincts)

        if 'ward_no' in request.args:
            precincts = [
                p for p in precincts if p.ward == request.args['ward_no']
            ]

        if 'precinct_no' in request.args:
            precincts = [
                p for p in precincts
                if p.precinct == request.args['precinct_no']
            ]

        precinct_ids = [p.id for p in precincts]
        contacts = Contact.get_by_precinct_list(precinct_ids)
    except Exception as ex:
        return jsonify(error=str(ex))
    finally:
        dao.close()

    if not contacts:
        return jsonify(error='No contacts!')

    if 'blocks' in request.args:
        blocks = json.loads(request.args['blocks'])
        result = []
        for contact in contacts:
            for block in blocks:
                if contact.address.get_street() == block['str']:
                    if contact.address.is_on_block(block['odd_even'],
                                                   block['low_addr'],
                                                   block['high_addr']):
                        result.append(contact)
        contacts = result

    contacts = [{
        'Name':
        str(contact.name),
        'Email':
        contact.info.email,
        'Phone 1':
        contact.info.phone1,
        'Phone 2':
        contact.info.phone2,
        'Address':
        str(contact.address),
        'City':
        contact.address.city,
        'Zip':
        contact.address.zipcode,
        'Jurisdiction':
        precinct_dict[contact.precinct_id].jurisdiction_name,
        'Ward':
        precinct_dict[contact.precinct_id].ward,
        'Precinct':
        precinct_dict[contact.precinct_id].precinct,
        'Groups':
        ':'.join(memberships[contact.id]) if contact.id in memberships else '',
        'Gender':
        contact.gender,
        'Birth Yr':
        contact.birth_year
    } for contact in contacts]

    return jsonify(contacts=contacts)
Beispiel #10
0
def get_precincts():
    rex = Precinct.get_all()
    pcts = [rec.serialize() for rec in rex]
    return jsonify(pcts)
Beispiel #11
0
    vtbl = PrettyTable()
    vtbl.field_names = [
        'Name', 'Birth Yr', 'Address', 'City', 'Zip', 'Juris', 'Ward', 'Pct',
        'Voter ID', 'Reg Date'
    ]
    for fn in vtbl.field_names:
        vtbl.align[fn] = 'l'

    htbl = PrettyTable()
    htbl.field_names = ['Voter ID', 'Juris', 'Date', 'Description']
    for fn in htbl.field_names:
        htbl.align[fn] = 'l'

    dao = Dao(db_file='c:/bench/bluestreets/data/26161.db', stateful=True)
    precincts = Precinct.get_dict(dao)
    jurisdictions = Precinct.get_jurisdictions(dao)
    jurisdictions = {j['code']: j['name'] for j in jurisdictions}

    dups = get_dups()

    cnt = 0
    for dup in dups:
        vrex = get_vrex(dup)
        addrs = set([str(vrec.address) for vrec in vrex])
        # do_same_pct_movers()
        do_new_pct_movers()
        # do_same_address()

    print(cnt)