示例#1
0
 def toggle_bank_mandate(self, no, price, sub_type):
     l = list(
         con.execute(
             select([members.c.debit_order_signup_timestamp
                     ]).where(members.c.id == no)))
     if l[0][0]:
         val = 0
         tp = 'mandate'
         description = 'unsign mandate'
     else:
         val = int(time.time())
         tp = 'mandate'
         description = 'sign mandate'
     con.execute(transactions.insert().values({
         'member_id': no,
         'timestamp': int(time.time()),
         'price': 0,
         'type': tp,
         'description': description,
         'outcome': 'ok'
     }))
     con.execute(members.update().values(
         debit_order_signup_timestamp=val).where(members.c.id == no))
     if description == 'sign mandate':
         x = [
             x for x, in con.execute(
                 select([members.c.debit_order_charge_day]).where(
                     members.c.id == no))
         ]
         r = q.add_subscription_and_future_charges(con, no, x[0],
                                                   int(float(price)),
                                                   sub_type)
         if 'error' in r:
             return r
     return {'success': True}
示例#2
0
 def check_id(self, no, success):
     if success:
         con.execute(members.update().values(
             last_id_checked=int(time.time())).where(members.c.id == no))
     else:
         con.execute(failed_checks.insert().values(member_id=no,
                                                   timestamp=int(
                                                       time.time())))
     return {'success': True}
示例#3
0
def submit_details():
    con.execute(members.update().values({
        'phone':
        request.form['phone'],
        'emergency_phone':
        request.form['emergency-phone'],
        'spam_consent':
        request.form.get('spam', 'off') == u'on',
    }).where(members.c.id == int(request.form['user_id'])))
    return app.send_static_file('thankyou.html')
示例#4
0
    def get_mandate(self, request):
        request.responseHeaders.addRawHeader('content-type', 'application/pdf')
        member_id = int(request.args['member_id'][0])
        charge_day = int(request.args['charge_day'][0])
        price = int(float(request.args['price'][0]))
        gym_id = request.args.get('gym_id', [0])[0]
        name, address, branch_code, account_no, phone = list(
            main.con.execute(
                select([
                    members.c.account_holder_name, members.c.address,
                    members.c.branch_code, members.c.account_number,
                    members.c.phone
                ]).where(members.c.id == member_id)))[0]
        now = datetime.now()
        days_in_month = calendar.monthrange(now.year, now.month)[1]
        price_per_day = price / days_in_month
        first_charge = price_per_day * (days_in_month - now.day)
        main.con.execute(members.update().values(
            debit_order_charge_day=charge_day,
            debit_order_gym_id=gym_id,
            debit_order_first_charge=first_charge).where(
                members.c.id == member_id))
        bank = branch_code_lookup[int(branch_code)]
        if branch_code == "198765" or branch_code == "720026":
            if account_no[0] == "1":
                branch_code = "198765"
                account_type = "1"
            elif account_no[0] == "2":
                branch_code = "198765"
                account_type = "2"
            elif account_no[0] == "9":
                branch_code = "720026"
                account_type = "2"
        elif branch_code == "460005":
            account_type = "2"
        else:
            account_type = "1"

        return create_mandate(charge_day=charge_day,
                              member_id=member_id,
                              name=name,
                              address=address,
                              account_number=account_no,
                              bank=bank,
                              branch_code=branch_code,
                              account_type=account_type,
                              price=price,
                              phone=phone)
示例#5
0
 def upload_photo(self, request):
     d = request.content.read()
     args = {}
     l = request.uri.split("?")[1].split("&")
     for item in l:
         k, v = item.split("=")
         args[k] = v
     member_id = args['member_id']
     what_for = args['what_for']
     prefix = "data:image/png;base64,"
     assert d.startswith(prefix)
     store_dir = get_config().get('data', 'store_dir')
     # invent new filename
     base_no = member_id
     no = base_no
     fname = os.path.join(store_dir, "photo_%s.png" % no)
     count = 1
     while os.path.exists(fname):
         no = base_no + "_" + str(count)
         fname = os.path.join(store_dir, "photo_%s.png" % no)
         count += 1
     d = d[len(prefix):]
     if (len(d) % 4) != 0:
         d += "=" * (4 - (len(d) % 4))
     with open(fname, "w") as f:
         f.write(base64.b64decode(d, " /"))
     if what_for == 'yourself':
         d = {'photo': fname}
     else:
         d = {
             'id_photo': fname,
             'last_id_update': int(time.time()),
             'last_id_checked': int(time.time())
         }
     main.con.execute(
         members.update().where(members.c.id == member_id).values(**d))
     return json.dumps({
         'success': True,
         'filename': fname,
         'what_for': what_for,
         'member_id': member_id
     })
示例#6
0
""" Upgrade DB with taking the most recent subscription and adding
it to subscription_type on members
"""

from authsys_common.queries import visits_daily, visits_per_client_agg
from authsys_common.model import members, subscriptions
from authsys_common.scripts import get_db_url

from sqlalchemy import create_engine, select
from datetime import datetime

eng = create_engine(get_db_url())
con = eng.connect()

l = [(a, b, c, d) for a, b, c, d in con.execute(select([members.c.id, members.c.name, subscriptions.c.type, subscriptions.c.end_timestamp]).where(members.c.id == subscriptions.c.member_id).order_by(subscriptions.c.end_timestamp))]
print l
d = {}
for memb_id, name, subscr_type, tstamp in l:
    if memb_id not in d or d[memb_id][2] < tstamp:
        d[memb_id] = (subscr_type, name, tstamp)
for k, v in d.iteritems():
    assert list(con.execute(select([members.c.name]).where(members.c.id == k)))[0][0] == v[1]
    con.execute(members.update().where(members.c.id == k).values(subscription_type=v[0]))
示例#7
0
from authsys_common.model import members, subscriptions, meta, tokens
from authsys_common.scripts import get_db_url, get_config
from sqlalchemy import create_engine, select, outerjoin, and_
from pprint import pprint

eng = create_engine(get_db_url())
con = eng.connect()
meta.reflect(bind=eng)

lst = list(con.execute(select([members, tokens]).where(
and_(tokens.c.valid, members.c.id == tokens.c.member_id))))
for item in lst:
    con.execute(members.update().where(members.c.id == item[0]).values(member_type='ondemand'))