Пример #1
0
def change_member_type_by_age():
    message = []
    message += ['standard to senior']
    query_clauses = [
        ('Member', 'status', [s.value
                              for s in MemberStatus.all_active()], 'in', None),
        ('Member', 'member_type', MembershipType.standard, '=', None),
        ('Member', 'birth_date', 65, '>=', 'age()'),
    ]
    members = get_members_for_query(query_clauses)
    count_senior = 0
    for member in members:
        if member.member_type != MembershipType.senior:
            message += [member.dt_number()]  # member_type_change(member)
            member.member_type = MembershipType.senior
            count_senior += 1
            save_member(member)

    message += ['junior to intermediate']
    query_clauses = [
        ('Member', 'status', [s.value
                              for s in MemberStatus.all_active()], 'in', None),
        ('Member', 'member_type', MembershipType.junior, '=', None),
        ('Member', 'birth_date', 16, '>', 'age()'),
    ]
    members = get_members_for_query(query_clauses)
    count_junior = 0
    for member in members:
        new = member.member_type_at_renewal()
        if new == MembershipType.intermediate:
            message += [member.dt_number()]  # member_type_change(member)
            member.member_type = MembershipType.intermediate
            count_junior += 1
            save_member(member)

    message += ['Intermediates to standard']
    query_clauses = [
        ('Member', 'status', [s.value
                              for s in MemberStatus.all_active()], 'in', None),
        ('Member', 'member_type', MembershipType.intermediate, '=', None),
        ('Member', 'birth_date', 20, '>', 'age()'),
    ]
    members = get_members_for_query(query_clauses)
    count_intermediate = 0
    for member in members:
        new = member.member_type_at_renewal()
        if new == MembershipType.standard:
            message += [member.dt_number()]  # member_type_change(member)
            member.member_type = MembershipType.standard
            count_intermediate += 1
            save_member(member)
    totals = '{} senior records processed, {} junior, {} intermediate'.format(
        count_senior, count_junior, count_intermediate)
    return '\n'.join([totals] + message)
Пример #2
0
 def extract_certificates(page, type):
     # new member packs, type is std/plus/junior
     if type == "std":
         sel = [('Member', 'status', MemberStatus.plus, '!=', None),
                ('Member', 'member_type', MembershipType.junior.value, '!=',
                 None)]
     if type == "plus":
         sel = [('Member', 'status', MemberStatus.plus, '=', None),
                ('Member', 'member_type', MembershipType.junior.value, '!=',
                 None)]
     if type == "junior":
         sel = [
             ('Member', 'member_type', MembershipType.junior, '=', None),
         ]
     query_clauses = sel + [
         ('Member', 'status', [s.value for s in MemberStatus.all_active()
                               ], 'in', None),
         ('Action', 'status', ActionStatus.open.value, '=', None),
         ('Action', 'action',
          [a.value for a in MemberAction.send_certificates()], 'in', None)
     ]
     display_fields = [
         'number', 'status', 'member type', 'full name', 'address (line 1)',
         'address (line 2)', 'address (line 3)', 'city', 'county', 'state',
         'post code', 'country for post', 'fan id', 'certificate date',
         'upgrade', 'comment', 'card start year', 'first name', 'last name'
     ]
     return Query.show_found_do(query_clauses,
                                display_fields,
                                action='cert_' + type,
                                page=page)
Пример #3
0
 def extract_email_junior():
     query_clauses = [
         ('Member', 'member_type', MembershipType.junior.value, '=', None),
         ('Member', 'status', [s.value for s in MemberStatus.all_active()
                               ], 'in', None),
         ('Member', 'comms', CommsType.email.value, '=', None),
         ('Member', 'comms_status', CommsStatus.all_ok.value, '=', None)
     ]
     display_fields = ['number', 'first name', 'email', 'junior email']
     return Query.show_found_do(query_clauses, display_fields)
Пример #4
0
def status_choices():
    # set choices for membership status according to current user's access rights
    lapsed = current_user.has_lapsed_access()
    choices = MemberStatus.choices(
        extra=[(99, 'all active (<lapsed)')] if lapsed else None, blank=True)
    limit = current_user.access_limit()
    if lapsed:
        choices = [c for c in choices if c[0] <= limit or c[0] in [8, 99]]
    else:
        choices = [c for c in choices if c[0] <= limit or c[0] == 8]
    return choices
Пример #5
0
 def extract_cards_all():
     # annual replacement cards for printers
     query_clauses = [
         ('Member', 'status',
          [s.value
           for s in MemberStatus.all_active_including_life()], 'in', None)
     ]
     display_fields = [
         'status at renewal', 'type at renewal', 'number at renewal',
         'full name', 'card start year', 'fan id'
     ]
     return Query.show_found_do(query_clauses, display_fields)
Пример #6
0
 def extract_renewals():
     # for renewal notices at membership year end
     end_date = fmt_date(current_year_end())
     query_clauses = [('Member', 'end_date', end_date, '=', None),
                      ('Member', 'status',
                       [s.value
                        for s in MemberStatus.all_active()], 'in', None)]
     display_fields = \
         ['number', 'id number', 'full name', 'address (line 1)', 'address (line 2)', 'address (line 3)',
          'city', 'county', 'state', 'post code', 'country for post', 'fan id', 'status', 'member type',
          'type at renewal', 'email', 'comms', 'payment method', 'renewal notes', 'home phone', 'mobile phone',
          'birth date', 'junior email', 'AFCW access', '3rd pty access', 'recent new', 'recent resume']
     return Query.show_found_do(query_clauses, display_fields)
Пример #7
0
 def extract_juniors():
     query_clauses = [
         ('Member', 'member_type', MembershipType.junior.value, '=', None),
         ('Member', 'status', [s.value for s in MemberStatus.all_active()],
          'in', None)
     ]
     display_fields = [
         'number', 'status', 'full name', 'address (line 1)',
         'address (line 2)', 'address (line 3)', 'city', 'county', 'state',
         'post code', 'country for post', 'dues', 'age', 'use email',
         'email', 'email bounced', 'junior email', 'first name', 'last name'
     ]
     return Query.show_found_do(query_clauses, display_fields)
Пример #8
0
def lapse_expired():
    query_clauses = [
        ('Member', 'status', [s.value
                              for s in MemberStatus.all_active()], 'in', None),
        ('Member', 'end_date', fmt_date(previous_year_end()), '=', None)
    ]
    members = get_members_for_query(query_clauses)
    count = 0
    for member in members:
        member.status = MemberStatus.lapsed
        save_member(member)
        count += 1
    return '{} records processed'.format(count)
Пример #9
0
 def extract_comms():
     query_clauses = [('Member', 'status',
                       [s.value
                        for s in MemberStatus.all_active()], 'in', None)]
     display_fields = [
         'number', 'full name', 'member type', 'use email', 'email',
         'mobile phone', 'home phone', 'address (line 1)',
         'address (line 2)', 'address (line 3)', 'city', 'county', 'state',
         'post code', 'country for post', 'voter', 'AFCW access',
         'first name', 'last name', 'status', 'end'
     ]
     return Query.show_found_do(query_clauses,
                                display_fields,
                                action='query')
Пример #10
0
 def extract_debits():
     end_date = fmt_date(current_year_end())
     query_clauses = [
         ('Member', 'end_date', end_date, '=', None),
         ('Member', 'last_payment_method',
          [PaymentMethod.dd.value,
           PaymentMethod.dd_pending.value], 'in', None),
         ('Member', 'status', [s.value for s in MemberStatus.all_active()],
          'in', None)
     ]
     display_fields = \
         ['number', 'type at renewal', 'full name', 'dues pending', 'email', 'phone',
          'address (line 1)', 'address (line 2)', 'address (line 3)', 'city', 'county', 'state', 'post code',
          'country for post', 'title', 'first name', 'last name']
     return Query.show_found_do(query_clauses, display_fields)
Пример #11
0
 def extract_for_afcw():
     query_clauses = [('Member', 'status',
                       [s.value
                        for s in MemberStatus.all_active()], 'in', None)]
     display_fields = [
         'number', 'title', 'first name', 'last name', 'sex', 'status',
         'member type', 'start', 'end', 'birth date', 'email', 'home phone',
         'mobile phone', 'comms', 'payment method', 'address (line 1)',
         'address (line 2)', 'address (line 3)', 'city', 'county', 'state',
         'post code', 'country code', 'use email', 'fan id', 'AFCW access',
         'last updated'
     ]
     return Query.show_found_do(query_clauses,
                                display_fields,
                                action='query')
Пример #12
0
def set_region():
    query_clauses = [
        ('Member', 'status', [s.value
                              for s in MemberStatus.all_active()], 'in', None),
        ('Member', 'end_date', fmt_date(current_year_end()), '=', None)
    ]
    members = get_members_for_query(query_clauses)
    count = 0
    for member in members:
        region = get_region(member.address.country, member.address.post_code)
        if region:
            member.address.region = region
            save_member(member)
        count += 1
    return '{} records processed'.format(count)
Пример #13
0
 def extract_other_actions(page):
     # other actions
     query_clauses = [
         ('Member', 'status', [s.value for s in MemberStatus.all_active()],
          'in', None),
         ('Action', 'action', [a.value for a in MemberAction.send_other()],
          'in', None),
         ('Action', 'status', ActionStatus.open.value, '=', None)
     ]
     display_fields = [
         'number', 'member type', 'full name', 'action', 'action date',
         'action comment'
     ]
     return Query.show_found_do(query_clauses,
                                display_fields,
                                action='other',
                                page=page)
Пример #14
0
 def extract_pending_renewals(page):
     # pending renewals
     query_clauses = [
         ('Member', 'status', [s.value for s in MemberStatus.all_active()],
          'in', None),
         ('Payment', 'type', PaymentType.pending.value, '=', None)
     ]
     display_fields = [
         'number', 'member type', 'full name', 'use email', 'email',
         'action', 'action date', 'action comment', 'last payment date',
         'last payment amount', 'last payment type', 'payment type',
         'last payment method', 'last payment comment', 'end'
     ]
     return Query.show_found_do(query_clauses,
                                display_fields,
                                action='renewal',
                                payment='pending',
                                page=page)
Пример #15
0
 def extract_junior_birthdays(month=None):
     today = datetime.date.today()
     if not month:
         month = today.month % 12 + 1  # next month
     query_clauses = [
         ('Member', 'member_type', MembershipType.junior.value, '=', None),
         ('Member', 'status', [s.value for s in MemberStatus.all_active()],
          'in', None),
         ('Member', 'birth_date', month, '=', 'birth_month()'),
         # ('Member', 'age_next_birthday', 16, '<', None)
     ]
     display_fields = [
         'number', 'full name', 'address (line 1)', 'address (line 2)',
         'address (line 3)', 'city', 'county', 'state', 'post code',
         'country for post', 'use email', 'email', 'junior email',
         'home phone', 'mobile phone', 'birth date', 'age next bday',
         'first name', 'last name'
     ]
     return Query.show_found_do(query_clauses, display_fields)
Пример #16
0
 def extract_cards(page):
     # renewal acknowledgement
     query_clauses = [
         ('Member', 'status', [s.value for s in MemberStatus.all_active()],
          'in', None),
         ('Action', 'status', ActionStatus.open.value, '=', None),
         ('Action', 'action', [a.value for a in MemberAction.send_cards()],
          'in', None)
     ]
     display_fields = [
         'number', 'status', 'member type', 'full name', 'address (line 1)',
         'address (line 2)', 'address (line 3)', 'city', 'county', 'state',
         'post code', 'country for post', 'fan id', 'recent new',
         'recent resume', 'email', 'use email', 'email bounced',
         'card start year', 'first name', 'last name'
     ]
     return Query.show_found_do(query_clauses,
                                display_fields,
                                action='card',
                                page=page)
Пример #17
0
 def populate_member(self, member_id):
     new_member = member_id == 0
     if new_member:
         self.first_name.data = 'new'
         self.last_name.data = 'member'
         self.status_return.data = MemberStatus.full_member.value
         self.handicap_return.data = 0
         set_select_field_new(self.proposer,
                              get_member_select_choices(),
                              item_name='proposer')
     else:
         member = get_member(member_id)
         proposer = member.proposer_id if member.proposer else 0
         set_select_field_new(self.proposer,
                              get_member_select_choices(),
                              default_selection=proposer,
                              item_name='proposer')
         player = member.player
         contact = member.contact
         state = player.state_as_of(datetime.date.today())
         set_select_field_new(self.status,
                              MemberStatus.choices(),
                              default_selection=member.status)
         self.status_return.data = member.status.value
         self.first_name.data = player.first_name
         self.last_name.data = player.last_name
         self.name_return.data = self.first_name.data + ' ' + self.last_name.data
         self.email.data = contact.email
         self.address.data = contact.address
         self.post_code.data = contact.post_code
         self.phone.data = contact.phone
         self.accepted_date.data = member.accepted or datetime.date(
             1992, 6, 17)
         self.handicap_return.data = self.handicap.data = state.handicap
         self.as_of.data = state.date
         role = member.user.roles[-1].role if member.user else UserRole.user
         set_select_field_new(self.access,
                              UserRole.choices(),
                              default_selection=role)
Пример #18
0
 def extract_debits_for_ptx():
     end_date = fmt_date(current_year_end())
     query_clauses = [
         ('Member', 'end_date', end_date, '=', None),
         ('Member', 'last_payment_method',
          [PaymentMethod.dd.value,
           PaymentMethod.dd_pending.value], 'in', None),
         ('Member', 'status', [s.value for s in MemberStatus.all_active()],
          'in', None)
     ]
     display_fields = [(None, 'Contact Reference'),
                       ('fmt id number', 'Mandate Reference'),
                       (None, 'Mandate Status'), ('title for ptx', 'Title'),
                       ('first name', 'First Name'),
                       ('last name', 'Last Name'), (None, 'Company'),
                       ('address (line 1)', 'Street1'),
                       ('address (line 2)', 'Street2'),
                       ('address (line 3)', 'Street3'), ('city', 'City'),
                       ('post code', 'Post Code'), ('county', 'County'),
                       ('country for post', 'Country'),
                       ('phone', 'Telephone'), ('email', 'Email'),
                       ('number at renewal', 'Alternative Reference'),
                       (None, 'Account Name'), (None, 'Sort Code'),
                       (None, 'Account Number'), (None, 'Plan Index'),
                       (None, 'Frequency Type', '{YEARLY}'),
                       (None, 'Start Date', '{2021-08-11}'),
                       (None, 'End Date'), (None, 'Number of Occurrences'),
                       (None, 'Recurrence'),
                       (None, 'Frequency Details1', '{DAY11}'),
                       (None, 'Frequency Details2', '{AUGUST}'),
                       ('fmt dues pending', 'Regular Amount'),
                       (None, 'First Amount'), (None, 'Last Amount'),
                       (None, 'Total Amount'),
                       ('extended type at renewal', 'Comments'),
                       (None, 'Profile Name'),
                       ('comms for ptx', 'Communication Preference')]
     return Query.show_found_do(query_clauses, display_fields)
Пример #19
0
def save_member_details(member_number, details):
    if member_number > 0:
        member = get_member(member_number)
    else:
        member = get_new_member()
    update_member_details(member, details)
    if not member.user:
        member.user = User(role = UserRole.member, user_name=str(member_number))
    member.user.set_password(User.member_password(details['post_code']))
    member.status = MemberStatus(details['status'])
    member.start_date = details['start_date']
    member.end_date = details['end_date']
    update_member_payments(member, details)
    update_member_actions(member, details)
    update_member_comments(member, details)

    member.last_updated = datetime.date.today()

    if member.number == 0:
        member.number = next_member_number()
        db.session.add(member)

    db.session.commit()
    return member
Пример #20
0
 def is_active(self):
     return self.status in MemberStatus.all_active()
Пример #21
0
 def regions():
     query_clauses = [
         ('Member', 'status', [s.value for s in MemberStatus.all_active()], 'in', None),
         ('Country', 'code', 'UK', '=', None)
     ]
     return Reports.show_regions_report(query_clauses)
Пример #22
0
def get_members_for_query(query_clauses, default_table='Member', limit=None):
    clauses = []
    tables = tables_needed_for_query(default_table, query_clauses)
    engine = db.session.bind.engine.name
    for field in query_clauses:
        if len(field) == 5:
            field = field + (default_table,)
        table, column, value, condition, func, field_name = field
        type, values = field_type(table, column)
        table = class_name_to_table_name(table)
        null = value == 'null'
        if null:
            c = condition
            if condition == '=':
                c = 'is'
            elif condition == '!=':
                c = 'is not'
            condition = c
            s = '{}.{} {} {}'.format(table, column, condition, value)
        elif type == 'string':
            if condition == '=':
                s = 'lower({}.{}) like lower("%{}%")'.format(table, column, value)
            else:
                s = '{}.{} {} "{}"'.format(table, column, condition, value)
        elif type == 'enum':
            if field_name == 'status' and condition == '<' and value == 4:  # status = all active
                condition = 'in'
                value = [s.value for s in MemberStatus.all_active()]
            s = '{}.{} {} {}'.format(table, column, condition, value)
        elif type == 'date':
            if not func:
                date = sql_fmt_date(parse_date(value, reverse=True))
                s = '{}.{} {} {}'.format(table, column, condition, date)
            if func == 'birth_month()':
                if engine == 'sqlite':
                    s = 'strftime("%m", {}.{}){} "{:02}"'.format(table, column, condition, value)
                elif engine == 'mysql':
                    s = 'MONTH({}.{}){}{}'.format(table, column, condition, value)
                else:
                    s = 'Unknown engine: ' + engine
            if func in ['age()', 'age_at_renewal()']:
                if func == 'age()':
                    date = 'current_date()'
                else:
                    date = sql_fmt_date(current_year_end())
                if '>' in condition:
                    condition = condition.replace('>', '<')
                elif '<' in condition:
                    condition = condition.replace('<', '>')
                if engine == 'sqlite':
                    s = '{}.{} {} date("now", "-{} years")'.format(table, column, condition, value)
                elif engine == 'mysql':
                    s = '{}.{} {} date_add({}, interval -{} year)'.format(table, column, condition, date, value)
                else:
                    s = 'Unknown engine: ' + engine
        else:
            s = '{}.{} {} {}'.format(table, column, condition, value)
        if isinstance(value, list):
            s = s.replace('[', '(').replace(']', ')')
        clauses.append(s)
    q = db.session.query(tables[0])

    for table in tables[1:]:
        q = q.join(table)
    if len(clauses) > 0:
        statement = ' and '.join(clauses)
        q = q.filter(text(statement))
    if globals()['Member'] in tables:
        q = q.order_by('number')
    if limit:
        q = q.limit(limit)
    return q
Пример #23
0
class MemberDetailsForm(FlaskForm):
    full_name = StringField(label='Full Name')
    return_url = HiddenField(label='Return URL')
    member_number = HiddenField(label='Member Number')
    dt_number = StringField(label='Id')
    status = MySelectField(label='Status',
                           choices=MemberStatus.choices(),
                           coerce=MemberStatus.coerce)
    type = MySelectField(label='Type',
                         choices=MembershipType.choices(),
                         coerce=MembershipType.coerce)
    start_date = DateField(label='Start')
    end_date = DateField(label='End')
    birth_date = DateField(label='DoB', validators=[Optional()])
    age = HiddenField(label='Age')
    last_updated = StringField(label='Updated')
    access = MySelectField(label='Access',
                           choices=UserRole.choices(blank=False, ),
                           coerce=UserRole.coerce)
    fan_id = StringField(label='AFCW Fan ID')
    external_access = MySelectField(label='External access',
                                    choices=ExternalAccess.choices(),
                                    coerce=ExternalAccess.coerce)
    payment_method = MySelectField(label='Pay method',
                                   choices=PaymentMethod.choices(blank=True),
                                   coerce=PaymentMethod.coerce)
    title = MySelectField(label='Title',
                          choices=Title.choices(blank=True),
                          coerce=Title.coerce)
    first_name = StringField(label='First', validators=[InputRequired()])
    last_name = StringField(label='Last', validators=[InputRequired()])
    sex = MySelectField(label='Sex',
                        choices=Sex.choices(blank=True),
                        coerce=int)

    line1 = StringField(label='Address line 1')
    line2 = StringField(label='Address line 2')
    line3 = StringField(label='Address line 3')
    city = StringField(label='City')
    state = MySelectField(label='State',
                          choices=state_choices(blank=True),
                          coerce=int)
    post_code = StringField(label='Post Code')
    county = MySelectField(label='County',
                           choices=county_choices(blank=True),
                           coerce=int)
    country = MySelectField(label='Country',
                            choices=country_choices(),
                            coerce=int)

    home_phone = StringField(label='Home Phone')
    mobile_phone = StringField(label='Mobile')
    email = StringField(
        label='Email ',
        validators=[Optional(), Email("Invalid email address")])
    comms = MySelectField(label='Comms ',
                          choices=CommsType.choices(),
                          coerce=CommsType.coerce)
    comms_status = MySelectField(label='Status ',
                                 choices=CommsStatus.choices(),
                                 coerce=CommsStatus.coerce)

    submit = SubmitField(label='Save')

    payment_list = FieldList(FormField(PaymentItemForm))
    action_list = FieldList(FormField(ActionItemForm))
    comment_list = FieldList(FormField(CommentItemForm))

    jd_email = StringField(
        label='JD Email ',
        validators=[Optional(), Email("Invalid email address")])
    jd_gift = MySelectField(label='JD Gift',
                            choices=JuniorGift.choices(blank=True),
                            coerce=JuniorGift.coerce)

    def populate_member(self, member_number, return_url, copy=False):
        self.return_url.data = return_url
        new_member = member_number == 0
        if new_member or copy:
            member = get_new_member()
        else:
            member = get_member(member_number)
        if copy:
            base_member = get_member(member_number)
            new_member = True
            member.last_name = base_member.last_name
            member.address = base_member.address
            member.home_phone = base_member.home_phone
            member.mobile_phone = base_member.mobile_phone
            member.email = base_member.email
            member.comms = base_member.comms
        address = member.address
        self.member_number.data = str(member.number)
        self.dt_number.data = member.dt_number()
        self.status.data = member.status.value
        self.type.data = member.member_type.value
        self.start_date.data = member.start_date
        self.end_date.data = member.end_date
        self.birth_date.data = member.birth_date
        self.age.data = str(member.age()) if member.age() is not None else None
        self.last_updated.data = fmt_date(member.last_updated)
        self.access.data = member.user.role.value if member.user else 0

        self.fan_id.data = member.season_ticket_id if member.season_ticket_id else ''
        self.external_access.data = (member.external_access
                                     or ExternalAccess.none).value
        self.payment_method.data = member.last_payment_method.value if member.last_payment_method else ''

        self.full_name.data = member.full_name()
        self.title.data = member.title.value if member.title else ''
        self.first_name.data = member.first_name
        self.last_name.data = member.last_name
        self.sex.data = member.sex.value if member.sex else ''

        self.line1.data = address.line_1
        self.line2.data = address.line_2
        self.line3.data = address.line_3
        self.city.data = address.city
        self.state.data = address.state.id if address.state else 0
        self.post_code.data = address.post_code
        self.county.data = address.county.id if address.county else 0
        self.country.data = address.country.id

        self.home_phone.data = member.home_phone
        self.mobile_phone.data = member.mobile_phone
        self.email.data = member.email
        self.comms.data = member.comms.value
        self.comms_status.data = member.comms_status.value if member.comms_status else CommsStatus.all_ok

        for payment in [get_new_payment()] + member.payments:
            item_form = PaymentItemForm()
            item_form.date = payment.date
            item_form.pay_type = payment.type.value  ## nb: don't set the data attribute for select fields in a fieldlist!
            item_form.amount = payment.amount
            item_form.method = payment.method.value if payment.method else None
            item_form.comment = payment.comment or ''
            self.payment_list.append_entry(item_form)

        for action in [get_new_action(new_member)] + member.actions:
            item_form = ActionItemForm()
            if action.action:
                item_form.action = action.action.value
            if action.status:
                item_form.status = action.status.value
            item_form.date = action.date
            item_form.comment = action.comment or ''
            self.action_list.append_entry(item_form)

        for comment in [get_new_comment()] + member.comments:
            item_form = CommentItemForm()
            item_form.date = comment.date
            item_form.comment = comment.comment or ''
            self.comment_list.append_entry(item_form)

        if new_member or member.member_type == MembershipType.junior:
            if not member.junior:
                member.junior = get_junior()
            self.jd_email.data = member.junior.email or ''
            self.jd_gift.data = member.junior.gift.value if member.junior.gift else ''
        else:
            self.jd_email = self.jd_gift = None

    def validate(self):
        result = True
        new_member = int(self.member_number.data) == 0
        if not super(MemberDetailsForm, self).validate():
            return False
        if new_member:
            name = self.first_name.data + ' ' + self.last_name.data
            existing = get_members_by_name(name)
            if len(existing) > 0:
                self.first_name.errors.append('{} is already member {}'.format(
                    name, existing[0].dt_number()))
                result = False
        return result

    def save_member(self, member_number):
        member_details = {
            'title': self.title.data,
            'first_name': self.first_name.data.strip(),
            'last_name': self.last_name.data.strip(),
            'sex': self.sex.data,
            'member_type': self.type.data,
            'status': self.status.data,
            'start_date': self.start_date.data,
            'end_date': self.end_date.data,
            'birth_date': self.birth_date.data,
            'access': self.access.data,
            'external_access': self.external_access.data,
            'fan_id': self.fan_id.data,
            'payment_method': self.payment_method.data,
            'home_phone': self.home_phone.data.strip(),
            'mobile_phone': self.mobile_phone.data.strip(),
            'email': self.email.data.strip(),
            'comms': self.comms.data,
            'comms_status': self.comms_status.data,
            'line_1': self.line1.data.strip(),
            'line_2': self.line2.data.strip(),
            'line_3': self.line3.data.strip(),
            'city': self.city.data.strip(),
            'state': get_state(self.state.data),
            'post_code': self.post_code.data.strip(),
            'county': get_county(self.county.data),
            'country': get_country(self.country.data),
            'payments': [],
            'actions': [],
            'comments': []
        }
        if self.type.data == MembershipType.junior.value:
            member_details['jd_mail'] = self.jd_email.data.strip()
            member_details['jd_gift'] = self.jd_gift.data

        for payment in self.payment_list.data:
            if payment['amount']:
                member_details['payments'].append(payment)

        for action in self.action_list.data:
            if action['action'] > 0:
                member_details['actions'].append(action)

        for comment in self.comment_list.data:
            if comment['comment']:
                member_details['comments'].append(comment)

        return save_member_details(member_number, member_details)
Пример #24
0
class MemberDetailsForm(FlaskForm):
    member_id = HiddenField(label='Member Id')
    status = SelectField(label='Status',
                         choices=MemberStatus.choices(),
                         coerce=MemberStatus.coerce)
    first_name = StringField(label='First Name', validators=[InputRequired()])
    last_name = StringField(label='last_name', validators=[InputRequired()])
    proposer = SelectField(label='Proposer', coerce=int)
    email = StringField(label='Email', validators=[InputRequired()])
    address = StringField(label='Address')
    post_code = StringField(label='Post Code')
    phone = StringField(label='Phone')
    accepted_date = DateField(label='accepted')
    handicap = StringField(label='Handicap')
    as_of = DateField(label='as of', validators=[Optional()])
    access = SelectField(label='Access',
                         choices=UserRole.choices(),
                         coerce=UserRole.coerce)
    save = SubmitField(label='Save')
    member_id_return = HiddenField()
    name_return = HiddenField()
    status_return = HiddenField()
    handicap_return = HiddenField()

    def validate(self):
        new_member = self.member_id.data == 0
        self.member_id.data = self.member_id_return.data
        self.proposer.choices = get_member_select_choices()
        if not super(MemberDetailsForm, self).validate():
            return False
        result = True
        if new_member:
            current_members = [
                n.full_name().lower()
                for n in get_current_members_as_players()
            ]
            name = self.first_name.data + ' ' + self.last_name.data
            if name.lower() in current_members:
                self.first_name.errors.append(
                    '{} is already a member'.format(name))
                result = False
            date = datetime.date.today()
            current_guests = [
                n.full_name().lower()
                for n in get_players_as_of(date, PlayerStatus.guest)
            ]
            if not name.lower() in current_guests:
                self.first_name.errors.append(
                    '{} has not been a guest'.format(name))
                result = False
            else:
                player = get_player_by_name(name)
                self.handicap_return.data = player.handicaps[-1].handicap
                self.status_return.data = str(
                    player.handicaps[-1].status.value)

        return result

    def populate_member(self, member_id):
        new_member = member_id == 0
        if new_member:
            self.first_name.data = 'new'
            self.last_name.data = 'member'
            self.status_return.data = MemberStatus.full_member.value
            self.handicap_return.data = 0
            set_select_field_new(self.proposer,
                                 get_member_select_choices(),
                                 item_name='proposer')
        else:
            member = get_member(member_id)
            proposer = member.proposer_id if member.proposer else 0
            set_select_field_new(self.proposer,
                                 get_member_select_choices(),
                                 default_selection=proposer,
                                 item_name='proposer')
            player = member.player
            contact = member.contact
            state = player.state_as_of(datetime.date.today())
            set_select_field_new(self.status,
                                 MemberStatus.choices(),
                                 default_selection=member.status)
            self.status_return.data = member.status.value
            self.first_name.data = player.first_name
            self.last_name.data = player.last_name
            self.name_return.data = self.first_name.data + ' ' + self.last_name.data
            self.email.data = contact.email
            self.address.data = contact.address
            self.post_code.data = contact.post_code
            self.phone.data = contact.phone
            self.accepted_date.data = member.accepted or datetime.date(
                1992, 6, 17)
            self.handicap_return.data = self.handicap.data = state.handicap
            self.as_of.data = state.date
            role = member.user.roles[-1].role if member.user else UserRole.user
            set_select_field_new(self.access,
                                 UserRole.choices(),
                                 default_selection=role)

    def save_member(self, member_id):
        member = {
            'first_name': self.first_name.data,
            'last_name': self.last_name.data,
            'handicap': float(self.handicap.data or self.handicap_return.data),
            'status': self.status.data,
            'as_of': self.as_of.data,
            'proposer_id': self.proposer.data,
            'email': self.email.data,
            'address': self.address.data,
            'post_code': self.post_code.data,
            'phone': self.phone.data,
            'accepted': self.accepted_date.data,
            'orig_name': self.name_return.data,
            'orig_status': int(self.status_return.data),
            'orig_handicap': float(self.handicap_return.data),
            'access': self.access.data
        }
        save_member(member_id, member)
        return True
Пример #25
0
    def populate(self):
        query_clauses = [('Member', 'status', [s.value for s in MemberStatus.all_active()], 'in', None), ]
        query = get_members_for_query(query_clauses)
        member_totals = {
            MembershipType.standard: 0,
            MembershipType.senior: 0,
            MembershipType.student: 0,
            MembershipType.job_seeker: 0,
            MembershipType.incapacity: 0,
            MembershipType.honorary: 0,
            MembershipType.other_concession: 0,
            MembershipType.intermediate: 0,
            MembershipType.junior: 0,
            100: 0, # Life adult
            101: 0, # Life Junior
            102: 0, # DT plus standard
            103: 0, # DT plus concession
            104: 0, # DT plus young adult
            105: 0  # voter
        }
        payment_totals = {
            PaymentMethod.cash: 0,
            PaymentMethod.chq: 0,
            PaymentMethod.cc: 0,
            PaymentMethod.dd: 0,
            100: 0  # other
        }
        action_totals = {
            MemberAction.certificate: 0,
            MemberAction.card: 0,
            MemberAction.other: 0
        }

        def add_member(member, member_totals):
            member_type = member.member_type
            member_totals[member_type] += 1
            if member.status == MemberStatus.life:
                if member_type == MembershipType.junior:
                    member_totals[101] += 1
                else:
                    member_totals[100] += 1
            if member.status == MemberStatus.plus:
                if member_type in (MembershipType.concessions() + [MembershipType.senior]):
                    member_totals[103] += 1
                elif member_type == MembershipType.intermediate:
                    member_totals[104] += 1
                else:
                    member_totals[102] += 1
            if member.voter():
                member_totals[105] += 1
            return

        def add_payment(member, payment_totals):
            if member.last_payment_method:
                if member.last_payment_method.value > PaymentMethod.cash.value and member.last_payment_method != PaymentMethod.dd_pending:
                    payment_totals[100] += 1  # other
                else:
                    if member.last_payment_method == PaymentMethod.dd_pending:
                        member.last_payment_method = PaymentMethod.dd
                    payment_totals[member.last_payment_method] += 1
            else:
                payment_totals[PaymentMethod.chq] += 1
            return

        def add_action(member, action_totals):
            if member.has_open_action(MemberAction.certificate):
                action_totals[MemberAction.certificate] += 1
            if member.has_open_action(MemberAction.card):
                action_totals[MemberAction.card] += 1
            if member.has_open_action(MemberAction.other):
                action_totals[MemberAction.other] += 1
            return

        for member in query.all():
            add_member(member, member_totals)
            add_payment(member, payment_totals)
            add_action(member, action_totals)

        self.adults.data = member_totals[MembershipType.standard]
        self.life_adults.data = member_totals[100]
        self.life_juniors.data = member_totals[101]
        self.plus_standard.data = member_totals[102]
        self.plus_concession.data = member_totals[103]
        self.plus_young_adult.data = member_totals[104]
        self.voters.data = member_totals[105]
        self.seniors.data = member_totals[MembershipType.senior]
        self.students.data = member_totals[MembershipType.student]
        self.job_seekers.data = member_totals[MembershipType.job_seeker]
        self.incapacity.data = member_totals[MembershipType.incapacity]
        self.honorary.data = member_totals[MembershipType.honorary]
        self.others.data = member_totals[MembershipType.other_concession]
        self.young_adults.data = member_totals[MembershipType.intermediate]
        self.juniors.data = member_totals[MembershipType.junior]

        self.concessions.data = self.seniors.data + self.students.data + self.job_seekers.data + self.incapacity.data + self.honorary.data + self.others.data
        self.total.data = self.adults.data + self.concessions.data + self.young_adults.data + self.juniors.data

        self.cash.data = payment_totals[PaymentMethod.cash]
        self.chq.data = payment_totals[PaymentMethod.chq]
        self.cc.data = payment_totals[PaymentMethod.cc]
        self.dd.data = payment_totals[PaymentMethod.dd]
        self.other_payment.data = payment_totals[100]

        self.cert.data = action_totals[MemberAction.certificate]
        self.card.data = action_totals[MemberAction.card]
        self.other_action.data = action_totals[MemberAction.other]