def get_daypass(): """Present a calendar to choose the daypass pariod (from/to) - default is today""" session = session_manager.get_session() if request.method == "POST": from_date = request.forms['from_date'] until_date = request.forms.get( 'until_date', from_date) # one day pass only --> no until_date _from_date = datetime.strptime(from_date, "%Y-%m-%d") _until_date = datetime.strptime(until_date, "%Y-%m-%d") if (_until_date - _from_date).days <= 7: admin = Member(id=1) qr_code = admin.encode_qrcode(version=3, from_date=_from_date, until_date=_until_date) img_qrcode = make_qrcode(qr_code) qr_code_file = "images/XCJ_{}.png".format(from_date) img_qrcode.save(qr_code_file) # print("QR code:", qr_code_file) if request.forms.get('email'): admin.email_qrcode( qr_code_file, "from {} until {}".format(from_date, until_date), request.forms['email']) else: qr_code_file = "images/emoji-not-happy.jpg" else: # GET qr_code_file = None from_date, until_date = date.today(), date.today() # only admin can set 'until date' period = (from_date, until_date if session['user'].is_admin else "") return template("daypass", qr_code=qr_code_file, period=period, session=session)
def email_my_qrcode(id): """Email a member its QR code""" member = Member(id=id) if member['email']: try: member.email_qrcode() except ValueError as err: redirect('/member/{}?msg=Error: No Email sent {}"'.format(id, err)) else: redirect('/member/{}?msg=Email sent"'.format(id)) redirect('/member/{}?msg=Error: No Email address"'.format(id))