def adduser(): try: conn = db.create_connection(config.DBFile()) if request.form['name'] and request.form['tag'] and request.form[ 'email'] and request.form['phone']: retval = db.new_user(conn, request.form['tag'], request.form['email'], request.form['phone'], request.form['name']) if retval == -1: return render_template( 'message.html', message=_('Are you sure you\'re not already registered?')) elif retval == -2: return render_template( 'message.html', message=_('Something went wrong, try again later')) else: return render_template('message.html', message=_('Welcome, ') + request.form['tag']) else: return render_template('message.html', message=_('Missing some items...')) except: return render_template( 'message.html', message=_('Something wrong happened!<br />Already registered?'))
def add_guest(): try: conn = db.create_connection(config.DBFile()) if request.form['name'] and request.form['email'] and request.form[ 'phone']: retval = db.insert_guest_checkin(conn, request.form['email'], request.form['phone'], request.form['name']) js = render_js('static/scripts.js', a=60000) return render_template('message.html', message=_('Welcome, ') + request.form['name'], guest=True, returnscript=js) else: return render_template('message.html', message=_('Missing some items...')) except: return render_template('message.html', message=_('Something wrong happened!'))
def csv(): start = None count = None try: start = int(request.form['start']) except: start = 0 try: count = int(request.form['count']) except: count = 25 conn = db.create_connection(config.DBFile()) response = db.get_entries(conn, start=start, count=count) conn.close() csv = 'Tag, Checkin, Checkout\n' for row in response: csv += row[0] + ", " + str(time.ctime(row[1])) + ", " + str( time.ctime(row[2])) + '\n' response = Response(csv) response.headers['Content-Type'] = 'text/csv' return response
def checkin(): if request.form.get('Checkin'): try: conn = db.create_connection(config.DBFile()) id = db.insert_checkin(conn, tag=request.form['tag']) if id > 0: js = render_js('static/scripts.js', a=3000) return render_template('message.html', message=_('Welcome back, ') + request.form['tag'], returnscript=js) elif id == -2: return render_template( 'message.html', message=_('Are you sure you\'re registered?'), fault=True) else: js = render_js('static/scripts.js', a=30000) return render_template( 'message.html', message=_('Are you already checked in?'), returnscript=js, fault=True) except: js = render_js('static/scripts.js', a=30000) return render_template( 'message.html', fault=True, message=_('Something went wrong. Are you registered?'), returnscript=js) elif request.form.get('Checkout'): try: conn = db.create_connection(config.DBFile()) id = db.insert_checkout(conn, tag=request.form['tag']) name = db.get_name(conn, request.form['tag']) if id > 0: js = render_js('static/scripts.js', a=3000) return render_template('message.html', message=_('See you soon, ') + request.form['tag'], returnscript=js) else: js = render_js('static/scripts.js', a=30000) return render_template( 'message.html', message=_('Are you already checked out?'), fault=True, returnscript=js) except: js = render_js('static/scripts.js', a=30000) return render_template('message.html', fault=True, message=_('Something went wrong!'), returnscript=js) else: js = render_js('static/scripts.js', a=30000) return render_template('message.html', fault=True, message=_('Invalid parameter?'), returnscript=js)
def list_checkedin(): conn = db.create_connection(config.DBFile()) visits = db.get_entries(conn, start=0, count=200, checkedin=True) conn.close() return render_template('list.html', visits=visits, checkedin=True)
def list(): conn = db.create_connection(config.DBFile()) visits = db.get_entries(conn, start=0, count=15) conn.close() return render_template('list.html', visits=visits)
except: count = 25 conn = db.create_connection(config.DBFile()) response = db.get_entries(conn, start=start, count=count) conn.close() csv = 'Tag, Checkin, Checkout\n' for row in response: csv += row[0] + ", " + str(time.ctime(row[1])) + ", " + str( time.ctime(row[2])) + '\n' response = Response(csv) response.headers['Content-Type'] = 'text/csv' return response if __name__ == '__main__': if not os.path.isfile(config.DBFile()): conn = db.create_connection(config.DBFile()) sql_users = '''CREATE TABLE "users" ( "id" INTEGER NOT NULL UNIQUE, "email" TEXT, "tag" TEXT NOT NULL UNIQUE, "phone" TEXT, "name" TEXT, PRIMARY KEY("id" AUTOINCREMENT) ); ''' sql_checkins = '''CREATE TABLE "checkins" ( "id" INTEGER NOT NULL UNIQUE, "user" INTEGER, "checkin" INTEGER, "checkout" INTEGER,
import db import config db_file = config.DBFile() conn = db.create_connection(db_file) #new_user = db.new_user(conn,'HAG','*****@*****.**','+12345678901') checkin = db.insert_checkin(conn, 'HAG') checkout = db.insert_checkout(conn,'HAG') #print(new_user) print(checkin) print(checkout)