def connect(front_end_id, user_id): print('Skapar connection') print(current_user.id) exhibitor = Exhibitor.get_exhibitor(session, current_user.id) attendant = Attendant.get_user_multi(session, front_end_id, user_id) if attendant: if exhibitor.got_connection(session, attendant.get_id(session)): connection = Connection.get_connection_by_users(session, exhibitor.get_id(), attendant.get_id(session)) data = connection.get_data(session) labels = get_all_labels(session) connection_info = {'connections':data, 'labels':labels} session.expunge_all() session.close() return json.dumps(connection_info) else: connection = Connection(exhibitor.get_id(), attendant.get_id(session)) session.add(connection) session.commit() connection_data = connection.get_data(session) session.expunge_all() labels = get_all_labels(session) session.close() connection_info = {'connections':connection_data, 'labels':labels} return json.dumps(connection_info) else: session.close() return json.dumps(False)
def connect_by_frontend_id(front_end_id): attendants = Attendant.get_from_front_id(session, front_end_id) session.expunge_all() session.close() if len(attendants) == 0: return json.dumps(False) else: return json.dumps(attendants)
def thanks(front_end_id, user_id): createSession() attendant = Attendant.get_user_multi(session, front_end_id, user_id) session.expunge_all() session.close() if attendant: return render_template('tack.html', name=attendant.first_name, qrUrl=attendant.qr, front_end_id=attendant.front_end_id) else: return abort(404)
def check_email(): createSession() email = request.form['mejl'] email = json.loads(email) response = {} response['email'] = Attendant.is_attending(session, email) session.expunge_all() session.close() return json.dumps(response)
def create_attendant(): createSession() created, returned_data = create_new_attendant() session.expunge_all() session.close() if created: return json.dumps({'attend':'True', 'url':'/thanks/'+str(returned_data['front_end_id'])+'/'+str(returned_data['id'])}) else: return json.dumps({'attend':'False','errors':returned_data})
def get_exhibitor_contacts(): connections = Connection.get_all_connections(session, current_user.id) connection_data = [] for connection in connections: connection_data.append(connection.get_data(session)) labels = get_all_labels(session) labels = {'connections':connection_data, 'labels':labels} session.expunge_all() session.close() return json.dumps(labels)
def wrapper(self, *args, **kwargs): session = self.Session() try: result = f(self, session, *args, **kwargs) return result except IntegrityError: session.rollback() raise Exception("Error") finally: session.expunge_all() session.close()
def session_scope(): """Provide a transactional scope around a series of operations.""" session = Session() session.expire_on_commit = False try: yield session session.commit() except: print('LS: Roll back.') session.rollback() raise finally: print('LS: Expunge all and close') session.expunge_all() session.close()
def log_in_user(): ''' Call log_in user and return True or False if logged in or not ''' createSession() email = request.form.get('username') user_psw = request.form.get('password') hashed = User.hash_password(user_psw) user = User.get_user(session, email) if user: if user.get_password() == hashed: key = user.generate_key(session) user_id = user.id session.expunge_all() session.close() return json.dumps({'logged_in':True, 'id':user_id, 'key':key }) else: session.close() return json.dumps({'logged_in':False}) else: session.close() return json.dumps({'logged_in':False})
def save_to_excel(): exhibitor = Exhibitor.get_exhibitor(session, current_user.id) excel_file = exhibitor.create_excel(session) session.expunge_all() session.close() return send_file('excel/kontaktuppgifter' + str(current_user.id) + '.xlsx', as_attachment=True, attachment_filename='kontaktuppgifter.xlsx')
def qr(): exhibitor = Exhibitor.get_exhibitor(session, current_user.id) labels = exhibitor.get_labels(session) session.expunge_all() session.close() return render_template("Web QR.html", labels = labels)
def admin(): exhibitor = Exhibitor.get_exhibitor(session, current_user.id) labels = exhibitor.get_labels(session) session.expunge_all() session.close() return render_template("utstallare_inloggad.html", lables = labels)