def get_recipient(santaEmail, db): cur = db.cursor() ownID = user.get_id(santaEmail, db) cur.execute('SELECT Recipient FROM SANTA WHERE Santa=?', (ownID, )) result = cur.fetchone() if result is not None: return user.get_email(result[0], db) else: return None
def ajax_get_interests(): cookie_secret = request.cookies.get('user_secret') user_id = session.get_session(cookie_secret, db) if user_id is not None: email = user.get_email(user_id, db).strip() results = interest.get_interest(email, db) totalInterests = len(results) return json.dumps({'success': True, 'outcome': results}), 200, { 'ContentType': 'application/json'}
def ajax_delete_interest(interestID): cookie_secret = request.cookies.get('user_secret') user_id = session.get_session(cookie_secret, db) if user_id is not None: email = user.get_email(user_id, db).strip() if interest.delete_interest(email, interestID, db): return json.dumps({'success': True}), 200, { 'ContentType': 'application/json'} else: return json.dumps({'success': False}), 200, { 'ContentType': 'application/json'}
def home(): cookie_secret = request.cookies.get('user_secret') user_id = session.get_session(cookie_secret, db) if user_id is not None: email = user.get_email(user_id, db).strip() first_name = user.get_name(email, db) if first_name is not None: recipient_email = santa.get_recipient(email, db) recipient_name = user.get_name(recipient_email, db) recipient_last_name = user.get_last_name(recipient_email, db) if recipient_name is not None and recipient_last_name is not None: recipient_name = recipient_name + " " + recipient_last_name return render_template('show-santa.html', firstName=None, recipient_name=recipient_name) return render_template('show-santa.html', firstName=first_name, recipient_name=None) else: return redirect(flask.url_for('logout')) else: return render_template('login.html')
def ajax_add_interest(): time.sleep(0.4) cookie_secret = request.cookies.get('user_secret') user_id = session.get_session(cookie_secret, db) if user_id is not None: email = user.get_email(user_id, db).strip() description = request.args.get('description') if description is "": return json.dumps({'success': False, 'reason': 'Please don\'t submit an empty interest'}), 200, { 'ContentType': 'application/json'} if interest.add_interest(email, description, db): return json.dumps({'success': True}), 200, { 'ContentType': 'application/json'} else: return json.dumps({'success': False, 'reason': 'Something went wrong adding interest, please email [email protected] if problem persists.'}), 200, { 'ContentType': 'application/json'}