Example #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)
Example #2
0
 def populate_member_list(self, query_clauses, clauses, page_number=1):
     if not query_clauses:
         return
     query_to_select_fields(self.all_sels(), query_clauses)
     query = get_members_for_query(query_clauses)
     page = query.paginate(page=page_number, per_page=15)
     self.total.data = page.total
     self.current_page.data = page_number
     self.total_pages.data = page.pages
     self.first_url = url_for('members', page=1, query_clauses=clauses)
     self.next_url = url_for(
         'members', page=page_number +
         1, query_clauses=clauses) if page.has_next else None
     self.prev_url = url_for(
         'members', page=page_number -
         1, query_clauses=clauses) if page.has_prev else None
     self.last_url = url_for('members',
                             page=page.pages,
                             query_clauses=clauses)
     for member in page.items:  # get_all_members(select) :
         item_form = MemberItemForm()
         item_form.member_number = member.number
         item_form.number = member.dt_number()
         item_form.status = member.status.name
         item_form.is_active = member.is_active()
         item_form.member_type = member.member_type.name
         item_form.first_name = member.first_name
         item_form.last_name = member.last_name
         item_form.email = member.email or ''
         item_form.post_code = member.address.post_code
         item_form.country = member.address.country.name
         item_form.start_date = fmt_date(member.start_date)
         item_form.end_date = fmt_date(member.end_date)
         self.member_list.append_entry(item_form)
Example #3
0
def renew_recent_resumers():
    resume_date = fmt_date(datetime.date(current_year_end().year, 4, 1))
    end_date = fmt_date(datetime.date(current_year_end().year, 8, 1))
    query_clauses = [
        ('Payment', 'date', resume_date, '>=', None),
        ('Payment', 'type', PaymentType.dues, '=', None),
        ('Member', 'end_date', end_date, '=', None),
    ]
    members = get_members_for_query(query_clauses)
    count = 0
    message = []
    for member in members:
        if member.is_recent_resume():
            member.end_date = new_end_date
            item = first_or_default([
                a for a in member.actions if a.action == MemberAction.card
                and a.status == ActionStatus.open
            ], None)
            if not item:
                item = Action(member_id=member.id,
                              date=datetime.date.today(),
                              action=MemberAction.card,
                              comment='auto renew recent resumer',
                              status=ActionStatus.open)
                member.actions.append(item)
            message += [member.dt_number()]
            save_member(member)
            count += 1
    return '\n'.join(['{} members updated'.format(count)] + message)
Example #4
0
 def extract_do(query_clauses, display_fields):
     members = get_members_for_query(query_clauses)
     csv = []
     head = [extract_heading(f) for f in display_fields]
     fields = [map_extract_field(k)[1] for k in display_fields]
     csv.append(head)
     for member in members:
         row = [get_attr(member, field) for field in fields]
         csv.append(row)
     return csv
Example #5
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)
Example #6
0
 def show_districts_report(query_clauses):
     members = get_members_for_query(query_clauses)
     all_districts = get_all_districts()
     csv = []
     count = {r: 0 for r in sorted(set([d[1] for d in all_districts]))}
     for member in members:
         if member.address.region_id:
             count[member.address.region.district] += 1
     #count = OrderedDict(sorted(region_count.items(), key=lambda x: x[1], reverse = True))
     head = ['region', 'district', 'count']
     csv.append(head)
     for district in count:
         csv.append([district, count[district]])
     return csv
Example #7
0
 def show_regions_report(query_clauses):
     members = get_members_for_query(query_clauses)
     all_regions = get_all_regions()
     csv = []
     region_count = {r: 0 for r in sorted(set(all_regions.values()))}
     for member in members:
         if member.address.region_id:
             region_count[member.address.region.region] += 1
     #region_count = OrderedDict(sorted(region_count.items(), key=lambda x: x[1], reverse = True))
     head = ['region', 'count']
     csv.append(head)
     for region in region_count:
         csv.append([region, region_count[region]])
     return csv
Example #8
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)
Example #9
0
    def bulk_update():
        form = QueryForm()
        form.set_status_choices()
        if form.validate_on_submit():
            if form.submit.data:
                query_clauses = url_pickle_load(
                    request.args.get('query_clauses'))
                query = get_members_for_query(query_clauses)
                updates = form.get_updates()
                # ToDo: update here
                # flash updated
                return  ##redirect(url_for('extracts_bulk_update', query_clauses=query_clauses))
        elif form.errors:
            flash_errors(form)

        return render_template('query.html',
                               form=form,
                               render_link=render_link,
                               title='Bulk update')
Example #10
0
 def show_found_do(query_clauses,
                   display_fields,
                   page=1,
                   action='query',
                   payment=None,
                   show_fn='show_actions'):
     query = get_members_for_query(query_clauses)
     form = ExtractForm()
     page = form.populate_result(url_pickle_dump(query_clauses),
                                 url_pickle_dump(display_fields), query,
                                 action, show_fn, page)
     fields = OrderedDict([map_extract_field(k) for k in display_fields])
     if action:
         fields = extract_fields_action(fields, action)
     if payment:
         fields = extract_fields_payment(fields, payment)
     return render_template('extract.html',
                            form=form,
                            render_link=render_link,
                            data=page.items,
                            fields=fields,
                            get_attr=get_attr)
Example #11
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]