示例#1
0
    def post(self, member_id):
        import constants
        member = Member.get(member_id)
        if member.status.name == constants.SIGNUP_STATUS_NAME:
            member.status = self.get_status(constants.WELCOME_LETTER_NAME)
            # update the status to paid membership due.
            dues = MembershipDues.all().ancestor(member).fetch(25)

            current_year = datetime.datetime.now().year
            # Set next year if this at the end of the previous.
            if (datetime.datetime.now().month >= 11):
                current_year = current_year + 1

            found = False
            for due in dues:
                if due.year == current_year:
                    due.paid = True
                    found = True
                    print 'Updated existing due'
                    due.put()
            if not found:
                print 'Due not found, created new'
                due = MembershipDues(parent=member, year=current_year, paid=True)
                due.put()
            member.put()
        elif member.status.name == constants.WELCOME_LETTER_NAME:
            member.status = self.get_status(constants.DEFAULT_MEMBER_STATUS_NAME)
            member.put()
        destination = self.request.get('return')
        return self.redirect(destination)
示例#2
0
    def post(self, member_id):
        import constants
        member = Member.get(member_id)
        if member.status.name == constants.SIGNUP_STATUS_NAME:
            member.status = self.get_status(constants.WELCOME_LETTER_NAME)
            # update the status to paid membership due.
            dues = MembershipDues.all().ancestor(member).fetch(25)

            current_year = datetime.datetime.now().year
            # Set next year if this at the end of the previous.
            if (datetime.datetime.now().month >= 11):
                current_year = current_year + 1

            found = False
            for due in dues:
                if due.year == current_year:
                    due.paid = True
                    found = True
                    print('Updated existing due')
                    due.put()
            if not found:
                print('Due not found, created new')
                due = MembershipDues(parent=member,
                                     year=current_year,
                                     paid=True)
                due.put()
            member.put()
        elif member.status.name == constants.WELCOME_LETTER_NAME:
            member.status = self.get_status(
                constants.DEFAULT_MEMBER_STATUS_NAME)
            member.put()
        destination = self.request.get('return')
        return self.redirect(destination)
示例#3
0
 def add_missing_dues(self, dues, start, stop):
     years = range(start, stop + 1)
     for due in dues:
         if due.year in years:
             years.remove(due.year)
     for year in years:
         dues.append(MembershipDues(year=year, paid=False))
示例#4
0
def expire_members():
    types = MemberType.all().fetch(30)
    expired_type = None
    for mt in types:
        if mt.name == MEMBER_TYPE_EXPIRED:
            expired_type = mt
            break
    if not expired_type:
        print 'Could not find member type for expired members'

    members = Member.all().fetch(3000)
    expired_count = 0
    last_year = datetime.datetime.now().year - 1
    for member in members:
        dues = MembershipDues.all().ancestor(member).fetch(30)
        all_paid = False
        for due in dues:
            if due.year >= last_year and due.paid:
                all_paid = True
                break
        if not all_paid and member.membertype.name == DEFAULT_MEMBER_NAME and member.status.name == DEFAULT_MEMBER_STATUS_NAME:
            print 'Member no', member.number, 'has an expired membership'
            member.membertype = expired_type
            member.put()
            expired_count = expired_count + 1

    print expired_count, 'memberships have been ended'
示例#5
0
def expire_members():
    types = MemberType.all().fetch(30)
    expired_type = None
    for mt in types:
        if mt.name == MEMBER_TYPE_EXPIRED:
            expired_type = mt
            break
    if not expired_type:
        print 'Could not find member type for expired members'

    members = Member.all().fetch(3000)
    expired_count = 0
    last_year = datetime.datetime.now().year - 1
    for member in members:
        dues = MembershipDues.all().ancestor(member).fetch(30)
        all_paid = False
        for due in dues:
            if due.year >= last_year and due.paid:
                all_paid = True
                break
        if not all_paid and member.membertype.name == DEFAULT_MEMBER_NAME and member.status.name == DEFAULT_MEMBER_STATUS_NAME:
            print 'Member no', member.number, 'has an expired membership'
            member.membertype = expired_type
            member.put()
            expired_count = expired_count + 1

    print expired_count, 'memberships have been ended'
示例#6
0
 def save_dues(self, member):
     current_dues = MembershipDues.all().ancestor(member).fetch(25)
     current_year = datetime.datetime.now().year
     for year in range(current_year + config.DUES_AHEAD, config.FIRST_YEAR_WITH_DUES, -1):
         due_value = self.request.get('due' + str(year))
         if not due_value:
             continue
         paid = True if due_value == 'True' else False
         exists = False
         for due in current_dues:
             if due.year == year:
                 exists = True
                 if due.paid != paid:
                     due.paid = paid
                     due.put()
         if not exists:
             new_due = MembershipDues(parent=member, year=year, paid=paid)
             new_due.put()
示例#7
0
def task_member_restore(items):

    for item in items:
        member = Member()
        member.number = item['number']
        member.address = item['address']
        if item['email'] != '' and item['email'] != None:
            member.email = db.Email(item['email'])
        member.name = item['name']
        member.member_since = string_to_date(item['memberSince'])
        if item['phone'] != '' and item['phone'] != None:
            member.phone = db.PhoneNumber(item['phone'])
        if item['phoneWork'] != '' and item['phoneWork'] != None:
            member.phone_work = item['phoneWork']
        if item['phoneHome'] != '' and item['phoneHome'] != None:
            member.phone_home = item['phoneHome']
        member.notes = item['notes']
        member.zipcode = item['zipcode']
        member.city = item['city']
        member.county = item['county']
        member.country = db.get(db.Key.from_path('Country', item['countryId']))
        member.status = db.get(db.Key.from_path('Status', item['statusId']))
        member.membertype = db.get(
            db.Key.from_path('MemberType', item['typeId']))
        member.put()

        for itemdue in item['membershipDues']:
            due = MembershipDues(parent=member,
                                 year=itemdue['year'],
                                 paid=itemdue['paid'])
            due.put()

        for itemcar in item['cars']:
            car = Car()
            car.member = member
            car.registration = itemcar['registration']
            car.model = db.get(db.Key.from_path('CarModel',
                                                itemcar['modelId']))
            car.bought_year = itemcar['boughtYear']
            car.sold_year = itemcar['soldYear']
            car.year = itemcar['year']
            car.notes = itemcar['notes']
            car.serial_no = itemcar['serialNo']
            car.put()
示例#8
0
 def save_dues(self, member):
     current_dues = MembershipDues.all().ancestor(member).fetch(25)
     current_year = datetime.datetime.now().year
     for year in range(current_year + config.DUES_AHEAD,
                       config.FIRST_YEAR_WITH_DUES, -1):
         due_value = self.request.get('due' + str(year))
         if not due_value:
             continue
         paid = True if due_value == 'True' else False
         exists = False
         for due in current_dues:
             if due.year == year:
                 exists = True
                 if due.paid != paid:
                     due.paid = paid
                     due.put()
         if not exists:
             new_due = MembershipDues(parent=member, year=year, paid=paid)
             new_due.put()
示例#9
0
def task_member_restore(items):

    for item in items:
        member = Member()
        member.number = item['number']
        member.address = item['address']
        if item['email'] != '' and item['email'] != None:
            member.email = db.Email(item['email'])
        member.name = item['name']
        member.member_since = string_to_date(item['memberSince'])
        if item['phone'] != '' and item['phone'] != None:
            member.phone = db.PhoneNumber(item['phone'])
        if item['phoneWork'] != '' and item['phoneWork'] != None:
            member.phone_work = item['phoneWork']
        if item['phoneHome'] != '' and item['phoneHome'] != None:
            member.phone_home = item['phoneHome']
        member.notes = item['notes']
        member.zipcode = item['zipcode']
        member.city = item['city']
        member.county = item['county']
        member.country = db.get(db.Key.from_path('Country', item['countryId']))
        member.status = db.get(db.Key.from_path('Status', item['statusId']))
        member.membertype = db.get(db.Key.from_path('MemberType', item['typeId']))
        member.put()

        for itemdue in item['membershipDues']:
            due = MembershipDues(parent=member, year=itemdue['year'],paid=itemdue['paid'])
            due.put()

        for itemcar in item['cars']:
            car = Car()
            car.member = member
            car.registration = itemcar['registration']
            car.model = db.get(db.Key.from_path('CarModel', itemcar['modelId']))
            car.bought_year = itemcar['boughtYear']
            car.sold_year = itemcar['soldYear']
            car.year = itemcar['year']
            car.notes = itemcar['notes']
            car.serial_no = itemcar['serialNo']
            car.put()
示例#10
0
    def report_task(self):
        filename = self.get_filename(self.id())
        member_list = Member.all().fetch(LIMIT_ALL)
        current_year = datetime.datetime.now().year
        final_list = list()

        for member in member_list:
            # Skip if the member doesn't pay fees
            if member.membertype.fee == 0:
                continue

            # Retrieve dues and check if status is set to paid
            dues = MembershipDues.all().ancestor(member).fetch(YEAR_MAX)
            paid = False
            for due in dues:
                if due.year == current_year:
                    paid = due.paid
                    break
            if not paid:
                final_list.append(member)

        # Make CSV file
        lines = list()
        lines.append(
            'number;name;address;zip;city;country;email;phone;member_since;type;status\n'
        )
        for member in final_list:
            datestr = ''
            if member.member_since:
                datestr = member.member_since.strftime('%Y-%m-%d')
            phonestr = ''
            if member.phone and member.phone != 'None':
                phonestr = unicode(member.phone)
            emailstr = ''
            if member.email and member.email != 'None':
                emailstr = unicode(member.email)
            lines.append(
                '"%s";"%s";"%s";"%s";"%s";"%s";"%s";"%s";%s;"%s";"%s"\n' %
                (unicode(member.number), unicode(member.name),
                 unicode(member.address), unicode(member.zipcode),
                 unicode(member.city), unicode(
                     member.country.name), emailstr, phonestr, datestr,
                 unicode(member.membertype.name), unicode(member.status.name)))

        self.write_report(filename, lines)
示例#11
0
    def report_task(self):
        filename = self.get_filename(self.id())
        member_list = Member.all().fetch(LIMIT_ALL)
        current_year = datetime.datetime.now().year
        final_list = list()

        for member in member_list:
            # Skip if the member doesn't pay fees
            if member.membertype.fee == 0:
                continue

            # Retrieve dues and check if status is set to paid
            dues = MembershipDues.all().ancestor(member).fetch(YEAR_MAX)
            paid = False
            for due in dues:
                if due.year == current_year:
                    paid = due.paid
                    break
            if not paid:
                final_list.append(member)

        # Make CSV file
        lines = list()
        lines.append(
            'number;name;address;zip;city;country;email;phone;member_since;type;status\n')
        for member in final_list:
            datestr = ''
            if member.member_since:
                datestr = member.member_since.strftime('%Y-%m-%d')
            phonestr = ''
            if member.phone and member.phone != 'None':
                phonestr = unicode(member.phone)
            emailstr = ''
            if member.email and member.email != 'None':
                emailstr = unicode(member.email)
            lines.append('"%s";"%s";"%s";"%s";"%s";"%s";"%s";"%s";%s;"%s";"%s"\n' % (
                unicode(member.number), unicode(
                    member.name), unicode(member.address),
                unicode(member.zipcode), unicode(
                    member.city), unicode(member.country.name),
                emailstr, phonestr, datestr,
                unicode(member.membertype.name), unicode(member.status.name)))

        self.write_report(filename, lines)
示例#12
0
 def get(self, member_id):
     template = JINJA_ENVIRONMENT.get_template('templates/members/member_detail.html')
     countries = Country.all().order('order').fetch(LIMIT)
     statuses = Status.all().order('order').fetch(LIMIT)
     types = MemberType.all().order('order').fetch(LIMIT)
     member = Member.get(member_id)
     dues = MembershipDues.all().ancestor(member).fetch(25)
     current_year = datetime.datetime.now().year
     self.add_missing_dues(dues, max(config.FIRST_YEAR_WITH_DUES, member.member_since.year), current_year + config.DUES_AHEAD)
     dues = sorted(dues, key=lambda item: item.year, reverse=True)
     data = {
         'countries': countries,
         'statuses': statuses,
         'types': types,
         'member': member,
         'dues': dues,
         'current_year': current_year
     }
     self.response.write(template.render(data))
示例#13
0
    def report_task(self):
        filename = self.get_filename(self.id())
        member_list = Member.all().fetch(LIMIT_ALL)

        current_year = datetime.datetime.now().year
        year_range = range(current_year - 3, current_year + 3)

        lines = list()
        lines.append('number;name;address;zip;city;country;type;email;phone')
        for year in year_range:
            lines.append(';fee' + str(year))
        lines.append('\n')

        for member in member_list:
            typename = member.membertype.name
            emailstr = ''
            if member.email and member.email != 'None':
                emailstr = unicode(member.email)
            phonestr = ''
            if member.phone and member.phone != 'None':
                phonestr = unicode(member.phone)

            lines.append('"%s";"%s";"%s";"%s";"%s";"%s";"%s";"%s";"%s"' %
                         (unicode(member.number), unicode(member.name),
                          unicode(member.address), unicode(member.zipcode),
                          unicode(member.city), unicode(member.country.name),
                          typename, emailstr, phonestr))
            due_list = {}
            for year in year_range:
                due_list['year' + str(year)] = 0

            for due in MembershipDues.all().ancestor(member).fetch(YEAR_MAX):
                key = 'year' + str(due.year)
                if key in due_list:
                    if due.paid:
                        due_list[key] = 1

            for year in year_range:
                lines.append(';' + str(due_list['year' + str(year)]))

            lines.append('\n')

        self.write_report(filename, lines, 'cp1252')
示例#14
0
def expire_members():
    logging.info('Expiring memberships')
    types = MemberType.all().fetch(10000)
    expired_type = None
    for mt in types:
        if mt.name == MEMBER_TYPE_EXPIRED:
            expired_type = mt
            break
    if not expired_type:
        logging.info(
            'Could not find member type for expired members. Exiting.')
        return

    members = Member.all().fetch(10000)
    expired_count = 0
    this_year = datetime.datetime.now().year
    total = 0
    for member in members:
        total = total + 1
        dues = MembershipDues.all().ancestor(member).filter(
            'year', this_year).fetch(100)
        all_paid = False
        for due in dues:
            #logging.info('%s: Y: %s, paid: %s' % (member.number, due.year, due.paid))
            if not all_paid and due.year == this_year and due.paid:
                all_paid = True
                # print 'All paid for %s ' % (member.number)

        if not all_paid:
            if member.membertype.name == DEFAULT_MEMBER_NAME:
                if member.status.name == DEFAULT_MEMBER_STATUS_NAME:
                    print(
                        'Member no %s has an expired membership (type is %s, status is %s); new type will be %s'
                        % (member.number, member.membertype.name,
                           member.status.name, expired_type.name))

                    member.membertype = expired_type
                    member.put()
                    expired_count = expired_count + 1

    print('%d memberships of %d will be expired' % (expired_count, total))
示例#15
0
 def get(self, member_id):
     template = JINJA_ENVIRONMENT.get_template(
         'templates/members/member_detail.html')
     countries = Country.all().order('order').fetch(LIMIT)
     statuses = Status.all().order('order').fetch(LIMIT)
     types = MemberType.all().order('order').fetch(LIMIT)
     member = Member.get(member_id)
     dues = MembershipDues.all().ancestor(member).fetch(25)
     current_year = datetime.datetime.now().year
     self.add_missing_dues(
         dues, max(config.FIRST_YEAR_WITH_DUES, member.member_since.year),
         current_year + config.DUES_AHEAD)
     dues = sorted(dues, key=lambda item: item.year, reverse=True)
     data = {
         'countries': countries,
         'statuses': statuses,
         'types': types,
         'member': member,
         'dues': dues,
         'current_year': current_year
     }
     self.response.write(template.render(data))
示例#16
0
    def report_task(self):
        filename = self.get_filename(self.id())
        member_list = Member.all().fetch(LIMIT_ALL)

        current_year = datetime.datetime.now().year
        year_range = range(current_year - 3, current_year + 3)

        lines = list()
        lines.append('number;name;address;zip;city;country;type;email')
        for year in year_range:
            lines.append(';fee' + str(year))
        lines.append('\n')

        for member in member_list:
            typename = member.membertype.name
            emailstr = ''
            if member.email and member.email != 'None':
                emailstr = unicode(member.email)
            lines.append('"%s";"%s";"%s";"%s";"%s";"%s";"%s";"%s"' % (
                unicode(member.number), unicode(member.name), unicode(member.address),
                unicode(member.zipcode), unicode(member.city), unicode(member.country.name),
                typename, emailstr))
            due_list  = {}
            for year in year_range:
                due_list['year' + str(year)] = 0

            for due in MembershipDues.all().ancestor(member).fetch(YEAR_MAX):
                key = 'year' + str(due.year)
                if key in due_list:
                    if due.paid:
                        due_list[key] = 1

            for year in year_range:
                lines.append(';' + str(due_list['year' + str(year)]))

            lines.append('\n')

        self.write_report(filename, lines, 'cp1252')
示例#17
0
def expire_members():
    logging.info('Expiring memberships')
    types = MemberType.all().fetch(10000)
    expired_type = None
    for mt in types:
        if mt.name == MEMBER_TYPE_EXPIRED:
            expired_type = mt
            break
    if not expired_type:
        logging.info(
            'Could not find member type for expired members. Exiting.')
        return

    members = Member.all().fetch(10000)
    expired_count = 0
    this_year = datetime.datetime.now().year
    total = 0
    for member in members:
        total = total + 1
        dues = MembershipDues.all().ancestor(member).filter('year', this_year).fetch(100)
        all_paid = False
        for due in dues:
            #logging.info('%s: Y: %s, paid: %s' % (member.number, due.year, due.paid))
            if not all_paid and due.year == this_year and due.paid:
                all_paid = True
                # print 'All paid for %s ' % (member.number)

        if not all_paid:
            if member.membertype.name == DEFAULT_MEMBER_NAME:
                if member.status.name == DEFAULT_MEMBER_STATUS_NAME:
                    print ('Member no %s has an expired membership (type is %s, status is %s); new type will be %s' %
                           (member.number, member.membertype.name, member.status.name, expired_type.name))

                    member.membertype = expired_type
                    member.put()
                    expired_count = expired_count + 1

    print ('%d memberships of %d will be expired' % (expired_count, total))
示例#18
0
    def get_json_dump(self):
        """ Dump everything as JSON """
        data_dump = {}
        #data_dump['members'] = self.get_members()

        data_dump['config'] = self.__to_list(
            ConfigTuple, lambda item: {
                'name': unicode(item.key().name()),
                'value': item.value
            })

        data_dump['users'] = self.__to_list(
            User, lambda item: {'email': unicode(item.email)})

        data_dump['status'] = self.__to_list(
            Status, lambda item: {
                'statusId': unicode(item.key()),
                'order': item.order,
                'name': item.name
            })
        data_dump['types'] = self.__to_list(
            MemberType, lambda item: {
                'typeId': unicode(item.key()),
                'order': item.order,
                'name': item.name,
                'fee': item.fee
            })

        data_dump['countries'] = self.__to_list(
            Country, lambda item: {
                'countryId': unicode(item.key()),
                'order': item.order,
                'name': item.name
            })

        data_dump['modelRanges'] = self.__to_list(
            ModelRange, lambda item: {
                'name':
                item.name,
                'yearStart':
                item.year_start,
                'yearEnd':
                item.year_end,
                'notes':
                item.notes,
                'carModels':
                self.__get_collection(
                    item.models, lambda item: {
                        'modelId': unicode(item.key()),
                        'name': item.name,
                        'engineCode': item.engine_code,
                        'typeNo': item.typeno,
                        'imageUrl': item.image_url,
                        'yearFrom': item.year_from,
                        'yearTo': item.year_to,
                        'notes': item.notes
                    })
            })

        # TODO: Options
        data_dump['members'] = self.__to_list(
            Member, lambda item: {
                'number':
                unicode(item.number),
                'address':
                unicode(item.address),
                'email':
                item.email,
                'name':
                unicode(item.name),
                'county':
                unicode(item.county),
                'memberSince':
                unicode(item.member_since),
                'countryId':
                unicode(item.country.key()),
                'typeId':
                unicode(item.membertype.key()),
                'statusId':
                unicode(item.status.key()),
                'phone':
                item.phone,
                'notes':
                item.notes,
                'zipcode':
                unicode(item.zipcode),
                'city':
                unicode(item.city),
                'phoneWork':
                item.phone_work,
                'phoneHome':
                item.phone_home,
                'cars':
                self.__get_collection(
                    item.cars, lambda item: {
                        'modelId': unicode(item.model.key()),
                        'registration': item.registration,
                        'boughtYear': item.bought_year,
                        'soldYear': item.sold_year,
                        'year': item.year,
                        'notes': item.notes,
                        'serialNo': item.serial_no
                    }),
                'membershipDues':
                self.__get_collection(
                    MembershipDues.all().ancestor(item).fetch(100), lambda
                    item: {
                        'year': item.year,
                        'paid': item.paid
                    })
            })

        return json.dumps(data_dump)
示例#19
0
 def add_due(self, member, year, paid):
     due = MembershipDues(parent=member, year=year, paid=paid)
     due.put()
示例#20
0
 def add_due(self, member, year, paid):
     due = MembershipDues(parent=member, year=year, paid=paid)
     due.put()
示例#21
0
    def get_json_dump(self):
        """ Dump everything as JSON """
        data_dump = {}
        #data_dump['members'] = self.get_members()

        data_dump['config'] = self.__to_list(ConfigTuple, lambda item: {
                'name': unicode(item.key().name()),
                'value': item.value
            })

        data_dump['users'] = self.__to_list(User, lambda item: {
                'email': unicode(item.email)
            })

        data_dump['status'] = self.__to_list(Status, lambda item: {
                'statusId': unicode(item.key()),
                'order' : item.order,
                'name': item.name
            })
        data_dump['types'] = self.__to_list(MemberType, lambda item: {
                'typeId': unicode(item.key()),
                'order': item.order,
                'name': item.name,
                'fee': item.fee
            })

        data_dump['countries'] = self.__to_list(Country, lambda item: {
                'countryId': unicode(item.key()),
                'order': item.order,
                'name': item.name
            })

        data_dump['modelRanges'] = self.__to_list(ModelRange, lambda item: {
                'name': item.name,
                'yearStart': item.year_start,
                'yearEnd': item.year_end,
                'notes': item.notes,
                'carModels': self.__get_collection(item.models, lambda item: {
                        'modelId': unicode(item.key()),
                        'name': item.name,
                        'engineCode': item.engine_code,
                        'typeNo': item.typeno,
                        'imageUrl': item.image_url,
                        'yearFrom': item.year_from,
                        'yearTo': item.year_to,
                        'notes': item.notes
                    })
            })

        # TODO: Options
        data_dump['members'] = self.__to_list(Member, lambda item: {
                'number': unicode(item.number),
                'address': unicode(item.address),
                'email': item.email,
                'name': unicode(item.name),
                'county': unicode(item.county),
                'memberSince': unicode(item.member_since),
                'countryId': unicode(item.country.key()),
                'typeId': unicode(item.membertype.key()),
                'statusId': unicode(item.status.key()),
                'phone': item.phone,
                'notes': item.notes,
                'zipcode': unicode(item.zipcode),
                'city': unicode(item.city),
                'phoneWork': item.phone_work,
                'phoneHome': item.phone_home,
                'cars': self.__get_collection(item.cars, lambda item: {
                        'modelId': unicode(item.model.key()),
                        'registration': item.registration,
                        'boughtYear': item.bought_year,
                        'soldYear': item.sold_year,
                        'year': item.year,
                        'notes': item.notes,
                        'serialNo': item.serial_no
                    }),
                'membershipDues': self.__get_collection(MembershipDues.all().ancestor(item).fetch(100), lambda item: {
                        'year': item.year,
                        'paid': item.paid
                    })
            })

        return json.dumps(data_dump)