Exemplo n.º 1
0
def add2malformed(record, club=None):
    """
    Populates club.malformed (which must be set up by client.)
    Checks that that for each record:
    1. there are N_FIELDS per record.
    2. the money fields are blank or evaluate to an integer.
    3. the email field contains "@"
    club.__init__ sets club.previous_name to "".
    (... used for comparison re correct ordering.)
    Client must set up a club.malformed[] empty list to be populated.
    """
    record = helpers.Rec(record)
    name = record(fstrings['last_first'])
    if len(record) != N_FIELDS:
        club.malformed.append("{}: Wrong # of fields.".format(name))
    for key in MONEY_KEYS:
        value = record[key]
        if value:
            try:
                res = int(value)
            except ValueError:
                club.malformed.append("{}, {}:{}".format(name, key, value))
    if record["email"] and '@' not in record["email"]:
        club.malformed.append("{}: {} Problem /w email.".format(
            name, record['email']))
    if name < club.previous_name:
        club.malformed.append("Record out of order: {}".format(name))
    club.previous_name = name
Exemplo n.º 2
0
def add2demographics(record, club):
    """
    Appends a record to club.demographics:
        Each key is a member name in last_first format
        Each value is the record in format specified
            by club.format
    """
    record = helpers.Rec(record)
    club.demographics[record(fstrings['last_first'])] = (record(club.format))
Exemplo n.º 3
0
def add2email_by_m(record, club):
    """
    Populates dict- club.email_by_name.
    """
    record = helpers.Rec(record)
    name = record(fstrings['last_first'])
    email = record['email']
    if email:
        club.email_by_m[name] = email
Exemplo n.º 4
0
def add_sponsors(rec, sponsors):
    """
    Returns a record with sponsor fields added.
    """
    first_last = [member.names_reversed(sponsor) for sponsor in sponsors]
    ret = helpers.Rec(rec)
    ret['sponsor1'] = first_last[0]
    ret['sponsor2'] = first_last[1]
    return ret
Exemplo n.º 5
0
def credit_payment_func(record, club):
    """
    Returns the <record>, modified by crediting payment(s)
    specified in club.statement_data
    """
    record = helpers.Rec(record)
    name = record(fstrings['last_first'])
    if name in club.statement_data.keys():
        apply_credit2record(club.statement_data[name], record)
    return record
Exemplo n.º 6
0
def add2ms_by_email(record, club):
    """
    Populates club.ms_by_email, a dict keyed by emails one of which
    is NO_EMAIL_KEY to capture members without an email address.
    """
    record = helpers.Rec(record)
    name = record(fstrings['last_first'])
    email = record['email']
    if not email:
        email = NO_EMAIL_KEY
    _ = club.ms_by_email.setdefault(email, [])
    club.ms_by_email[email].append(name)
Exemplo n.º 7
0
def rec_w_total_in_status(record, club):
    """
    Consults club.statement_data and returns a copy of the record
    with the appropriate total in its 'status' field.
    """
    rec = helpers.Rec(record)
    key = rec(fstrings['last_first'])
    if key in club.statement_data_keys:
        rec['status'] = club.statement_data[key]['total']
    else:
        print("Warning: expected to find '{}' in club.statement_data_keys")
        rec['status'] = 'Payment not found'
    return rec
Exemplo n.º 8
0
def add2member_with_email_set(record, club):
    """
    Appends a record to club.member_with_email_set if record
    is that of a member and the member has an email address.
    ## Proposal: rename 'add2has_email_set' and store in 
                        'club.has_email_set'.
    """
    record = helpers.Rec(record)
    entry = record(fstrings['last_first'])
    if record['email'] and is_member(record):
        club.member_with_email_set.add(entry)
    else:
        club.no_email_set.add(entry)
Exemplo n.º 9
0
def add2ms_by_status(record, club):
    """
    Appends a record to club.ms_by_status:
        Each key is a status
        Each value is a list of strings:
            member names in last_first format
            of those having that status.
    """
    if record['status']:
        stati = get_status_set(record)
        for status in stati:
            _ = club.ms_by_status.setdefault(status, [])
            record = helpers.Rec(record)
            club.ms_by_status[status].append(record(fstrings['last_first']))
Exemplo n.º 10
0
def add2db_emails(record, club):
    """
    Populates club.db_emails
    'ex' for experimental
    db_emails is a dict with all members included but
    with a special key for those without email
    """
    #   print("called add2db_emails")
    record = helpers.Rec(record)
    name = record(fstrings['last_first'])
    email = record['email']
    if not email:
        email = NO_EMAIL_KEY
    club.db_emails[name] = email
Exemplo n.º 11
0
def populate_non0balance_func(record, club):
    """
    Reads the MONEY_KEYS fields and, if any are not zero,
    populates the club.non0balance dict keyed by member name
    with values keyed by MONEY_KEYS.
    """
    total = 0
    record = helpers.Rec(record)
    name = record(fstrings['last_first'])
    for key in MONEY_KEYS:
        try:
            money = int(record[key])
        except ValueError:
            money = 0
        if money:
            _ = club.non0balance.setdefault(name, {})
            club.non0balance[name][key] = money
Exemplo n.º 12
0
def thank_func(record, club):
    """
    Must assign "payment" and extra" to record.
    """
    record = helpers.Rec(record)
    name = record(fstrings['last_first'])
    if name in club.statement_data_keys:
        payment = club.statement_data[name]['total']
        statement_dict = get_statement_dict(record)
        try:
            apply_credit2statement(statement_dict, club.statement_data[name])
        except KeyError:
            print("error processing {}".format(record['first'] +
                                               record['last']))
            raise
        record['extra'] = get_statement(statement_dict)
        record['payment'] = payment
        q_mailing(record, club)
Exemplo n.º 13
0
def append_email(record, club):
    """
    club.which has already been assigned to one of the values
    of content.content_types
    Appends an email to club.json_data
    """
    #   print(club.email)
    body = club.email.format(**record)
    sender = club.which['from']['email']
    email = {
        'From': sender,  # Mandatory field.
        'Sender': sender,  # 0 or 1
        'Reply-To': club.which['from']['reply2'],  # 0 or 1
        'To': record['email'],  # at least one ',' separated address
        'Cc': '',  # O or 1 comma separated list.
        'Bcc': '',  # O or 1 comma separated list.
        'Subject': club.which['subject'],  # 0 or 1
        'attachments': [],
        'body': body,
    }
    sponsor_email_addresses = ''
    if club.cc_sponsors:
        record = helpers.Rec(record)
        name_key = record(fstrings['last_first'])
        if name_key in club.applicant_set:
            sponsors = club.sponsors_by_applicant[name_key]
            # Use list comprehension for the following:
            sponsor_email_addresses = []
            for sponsor in club.sponsors_by_applicant[name_key]:
                #               print('{} sponsor: {}'.format(name_key, sponsor))
                #               print('appending: {}'.format(
                #                               club.sponsor_emails[sponsor]))
                addr = club.sponsor_emails[sponsor]
                if addr:
                    sponsor_email_addresses.append(addr)
            sponsor_email_addresses = ','.join(sponsor_email_addresses)
    if club.cc: ccs = club.cc
    else: ccs = ''
    email['Cc'] = helpers.join_email_listings(sponsor_email_addresses, ccs)
    if club.bcc:
        email['Bcc'] = club.bcc
    club.json_data.append(email)
Exemplo n.º 14
0
def add2fee_data(record, club):
    """
    Populates club.fee_category_by_m  and
    club.ms_by_fee_category.
    Note: this gathers from main data base,
    _not_ from extra fees SPoTs. See
    data.populate_extra_fees(club) which populates
    club.by_name & club.by_category.
    Both produce dicts in the same formats respectively.
    Tested by Tests.xtra_fees.py
    """
    record = helpers.Rec(record)
    name = record(fstrings['last_first'])
    # print(repr(FEES_KEYS))
    for f_key in FEES_KEYS:
        try:
            fee = int(record[f_key])
        except ValueError:
            continue
        _ = club.ms_by_fee_category.setdefault(f_key, {})
        club.ms_by_fee_category[f_key][name] = fee
        _ = club.fee_category_by_m.setdefault(name, {})
        club.fee_category_by_m[name][f_key] = fee
Exemplo n.º 15
0
def populate_sponsor_data(club):
    """
    Reads sponsor & membership data files populating attributes:
        club.sponsors_by_applicant, 
        club.applicant_set,
        club.sponsor_emails,
        club.sponsor_set.
    All names (whether keys or values) are formated "last, first".
    """
    club.sponsor_set = set()  # eschew duplicates!
    club.sponsor_emails = dict()
    club.sponsors_by_applicant = dict()
    with open(club.sponsor_spot, 'r') as stream:
        print('Reading file "{}"...'.format(stream.name))
        for line in helpers.useful_lines(stream, comment='#'):
            parts = line.split(':')
            names = parts[0].split()  # applicant 1st and 2nd names
            name = "{}, {}".format(names[1], names[0])
            try:
                sponsors = parts[1].split(',')
            except IndexError:
                print("IndexError: {} sponsors???".format(name))
                sys.exit()
            sponsors = [helpers.tofro_first_last(name) for name in sponsors]
            for sponsor in sponsors:
                club.sponsor_set.add(sponsor)
            club.sponsors_by_applicant[name] = sponsors
            # key: applicant name
            # value: list of two sponsors in "last, first" format.
    with open(club.infile, 'r') as stream:
        dictreader = csv.DictReader(stream)
        for record in dictreader:
            record = helpers.Rec(record)
            name = record(member.fstrings['last_first'])
            if name in club.sponsor_set:
                club.sponsor_emails[name] = record['email']
    club.applicant_set = club.sponsors_by_applicant.keys()
Exemplo n.º 16
0
def populate_name_set_func(record, club):
    record = helpers.Rec(record)
    name = record(fstrings['last_first'])
    club.name_set.add(name)
Exemplo n.º 17
0
def add2stati_by_m(record, club):
    if record["status"]:
        record = helpers.Rec(record)
        club.stati_by_m[record(
            fstrings['first_last'])] = (get_status_set(record))
Exemplo n.º 18
0
def add2applicant_with_email_set(record, club):
    if is_applicant(record) and record['email']:
        record = helpers.Rec(record)
        club.applicant_with_email_set.add(record(fstrings['last_first']))
Exemplo n.º 19
0
def add2modified2thank_dict(record, club):
    rec = helpers.Rec(record)
    name = rec(fstrings['last_first'])
    rec['status'] = club.statement_data[name]["total"]
    club.modified2thank_dict[name] = rec
Exemplo n.º 20
0
def add2statement_data(record, club):
    rec = helpers.Rec(record)
    name = rec(fstrings['last_first'])
    club.statement_data_keys.append(name)
    club.statement_data[name] = get_statement_dict(rec)