def search(): if session.get('user_id', None) is None: return redirect(url_for('main_page')) user_info = db.get_user(session.get('user_id')) categories = db.get_activity_type() for cat in categories: print(cat) skills = {0: 'Any', 1: 'Beginner', 2: 'Intermediate', 3: 'Expert', 4: 'Master'} access = {0: 'Public', 1: 'Private'} user_activities = {} db_user_activities = db.get_all_user_activities() i = 0 for u_acts in db_user_activities: value = [u_acts['userid']] key = u_acts['activityid'] if len(user_activities) > 0: if user_activities.get(key) != None: user_activities[key].append(value) else: user_activities[key] = value else: user_activities[key] = value i += 1 if request.method == 'POST': if request.form.get('join', None) is None: activity_name = request.form['activity-name'] results = db.get_activity(name=activity_name) return render_template('SearchResultsPage.html', user=user_info, u_activities=user_activities, results=results, a=access, skills=skills, categories=categories, maps_key=utilities.get_key('google_maps')) else: db.add_user_activity(user_info[0]['id'], request.form['activity-id'], request.form['activity-private']) if request.form['activity-private'] == '0': utilities.send_email([user_info[0]['email']], 'Activity Joined', 'You successfully joined an activity!') return render_template('SearchResultsPage.html', user=user_info, u_activities=user_activities, categories=categories, a=access, skills=skills, maps_key=utilities.get_key('google_maps')) else: return render_template('SearchResultsPage.html', user=user_info, u_activities=user_activities, categories=categories, a=access, skills=skills, maps_key=utilities.get_key('google_maps'))
def create_event(): if session.get('user_id', None) is None: return redirect(url_for('main_page')) user_info = db.get_user(session.get('user_id')) categories = db.get_activity_type() if request.method == 'POST': activity_name = request.form['activity-name'] category = request.form['category'] private = request.form['private'] date = request.form['date'] time = request.form['time'] duration = request.form['duration'] latitude = request.form['lat'] longitude = request.form['lng'] num_of_players = request.form['num-of-players'] skill = request.form['skill-level'] datetime = utilities.combine_datetime(date, time) db.add_activity(name=activity_name, category=category, datetime=datetime, duration=duration, latitude=latitude, longitude=longitude, numplayers=num_of_players, skill=skill, private=private, leader=session.get ('user_id'), available=1) db.add_user_activity(session.get('user_id'), db.get_activity(name=activity_name, category=category, skill=skill, leader=session.get('user_id'))) redirect(url_for('home')) return render_template('create_event.html', key=utilities.get_key('google_maps'), user=user_info, categories=categories)
def rosters(): if session.get('user_id', None) is None: return redirect(url_for('main_page')) user_info = db.get_user(session.get('user_id')) act_list = [] activities = db.get_user_activity(user_id=user_info[0]['id']) for activity in activities: activity_details = db.get_activity(activity_id=activity['activityid'])[0] activity_details['latitude'] = float(activity_details['latitude']) activity_details['longitude'] = float(activity_details['longitude']) activity_details['time'] = int(time.mktime(activity_details['datetime'].timetuple())) * 1000 activity_details['date'] = activity_details['datetime'].date().strftime('%m/%d/%Y') act_list.append(activity_details) if request.method == 'GET': if request.args.get('loadActivityID') is not None: print(request.args['loadActivityID']) user_activity = db.get_user_activity(activity_id=request.args['loadActivityID']) users = [] for record in user_activity: user = db.get_user(user_id=record['userid'], select='id, uname')[0] user['approved'] = record['isApplicant'] users.append(user) print(users) return jsonify(users=users) return render_template('RostersPage.html', user=user_info, activities=act_list, maps_key=utilities.get_key('google_maps'))
def calender(): if session.get('user_id', None) is None: return redirect(url_for('main_page')) user_info = db.get_user(session.get('user_id')) date = calendar.Calendar(6).monthdatescalendar( datetime.datetime.utcnow().year, datetime.datetime.utcnow().month) if request.method == 'POST': u_id = request.form['use_id'] a_id = request.form['act_id'] db.leave_activity(u_id, a_id) act_list = [] activities = db.get_user_activity(user_id=user_info[0]['id']) for activity in activities: activity_details = db.get_activity( activity_id=activity['activityid'])[0] activity_details['latitude'] = float(activity_details['latitude']) activity_details['longitude'] = float(activity_details['longitude']) activity_details['time'] = int( time.mktime(activity_details['datetime'].timetuple())) * 1000 act_list.append(activity_details) return render_template('calender.html', user=user_info, date=date, activities=act_list, maps_key=utilities.get_key('google_maps'))
def rosters(): if session.get('user_id', None) is None: return redirect(url_for('main_page')) user_info = db.get_user(session.get('user_id')) act_list = [] activities = db.get_user_activity(user_id=user_info[0]['id']) for activity in activities: activity_details = db.get_activity( activity_id=activity['activityid'])[0] if user_info[0]['id'] == activity_details['leader']: activity_details['latitude'] = float(activity_details['latitude']) activity_details['longitude'] = float( activity_details['longitude']) activity_details['time'] = int( time.mktime(activity_details['datetime'].timetuple())) * 1000 activity_details['date'] = activity_details['datetime'].date( ).strftime('%m/%d/%Y') act_list.append(activity_details) if request.args.get('loadActivityID') is not None: user_activity = db.get_user_activity( activity_id=request.args['loadActivityID']) users = [] for record in user_activity: user = db.get_user(user_id=record['userid'], select='id, uname')[0] user['approved'] = record['isApplicant'] users.append(user) return jsonify(users=users) if request.method == 'POST': activityID = request.form['activityID'] playerID = request.form['playerID'] playerUsr = db.get_user(playerID) if request.form['action'] == 'add': db.edit_user_activity_is_applicant(playerID, activityID, 0) utilities.send_email(playerUsr[0]['email'], 'Activity Request Accepted', 'You were accepted to an activity!') else: db.leave_activity(user_id=playerID, activity_id=activityID) utilities.send_email(playerUsr[0]['email'], 'Removed From Activity', 'You were kicked from an activity!') return render_template('RostersPage.html', user=user_info, activities=act_list, maps_key=utilities.get_key('google_maps'))
def search(): if session.get('user_id', None) is None: return redirect(url_for('main_page')) user_info = db.get_user(session.get('user_id')) categories = db.get_activity_type() if request.method == 'POST': if request.form.get('join', None) is None: activity_name = request.form['activity-name'] results = db.get_activity(name=activity_name) return render_template('SearchResultsPage.html', user=user_info, results=results, categories=categories, maps_key=utilities.get_key('google_maps')) else: db.add_user_activity(user_info[0]['id'], request.form['activity-id']) utilities.send_email(user_info[0]['email'], 'Activity Joined', 'You joined: ' + request.form['activity-name-item']) return render_template('SearchResultsPage.html', user=user_info, categories=categories, maps_key=utilities.get_key('google_maps')) else: return render_template('SearchResultsPage.html', user=user_info, categories=categories, maps_key=utilities.get_key('google_maps'))
def calender(): if session.get('user_id', None) is None: return redirect(url_for('main_page')) user_info = db.get_user(session.get('user_id')) date = calendar.Calendar(6).monthdatescalendar(datetime.datetime.utcnow().year, datetime.datetime.utcnow().month) act_list = [] activities = db.get_user_activity(user_id=user_info[0]['id']) for activity in activities: activity_details = db.get_activity(activity_id=activity['activityid'])[0] activity_details['latitude'] = float(activity_details['latitude']) activity_details['longitude'] = float(activity_details['longitude']) activity_details['time'] = int(time.mktime(activity_details['datetime'].timetuple())) * 1000 act_list.append(activity_details) return render_template('calender.html', user=user_info, date=date, activities=act_list, maps_key=utilities.get_key('google_maps'))
def rosters(): if session.get('user_id', None) is None: return redirect(url_for('main_page')) user_info = db.get_user(session.get('user_id')) act_list = [] activities = db.get_user_activity(user_id=user_info[0]['id']) for activity in activities: activity_details = db.get_activity(activity_id=activity['activityid'])[0] activity_details['latitude'] = float(activity_details['latitude']) activity_details['longitude'] = float(activity_details['longitude']) activity_details['time'] = int(time.mktime(activity_details['datetime'].timetuple())) * 1000 activity_details['date'] = activity_details['datetime'].date().strftime('%m/%d/%Y') act_list.append(activity_details) if request.method == 'GET': if request.args.get('loadActivityID') is not None: print(request.args['loadActivityID']) user_activity = db.get_user_activity(activity_id=request.args['loadActivityID']) users = [] for record in user_activity: user = db.get_user(user_id=record['userid'], select='id, uname')[0] user['approved'] = record['isApplicant'] users.append(user) print(users) return jsonify(users=users) if request.method == 'POST': activityID = request.form['activityID'] playerID = request.form['playerID'] playerUsr = db.get_user(playerID) if request.form['action'] == 'add': db.edit_user_activity_is_applicant(playerID, activityID, 0) utilities.send_email(playerUsr[0]['email'], 'Activity Request Accepted', 'You were accepted to an activity!') elif request.form['action'] == 'kick': db.leave_activity(user_id=playerID, activity_id=activityID) utilities.send_email(playerUsr[0]['email'], 'Removed From Activity', 'You were kicked from an activity!') return render_template('RostersPage.html', user=user_info, activities=act_list, maps_key=utilities.get_key('google_maps'))
def create_event(): if session.get('user_id', None) is None: return redirect(url_for('main_page')) user_info = db.get_user(session.get('user_id')) categories = db.get_activity_type() if request.method == 'POST': activity_name = request.form['activity-name'] category = request.form['category'] private = request.form['private'] date = request.form['date'] time = request.form['time'] duration = request.form['duration'] latitude = request.form['lat'] longitude = request.form['lng'] num_of_players = request.form['num-of-players'] skill = request.form['skill-level'] datetime = utilities.combine_datetime(date, time) db.add_activity(name=activity_name, category=category, datetime=datetime, duration=duration, latitude=latitude, longitude=longitude, numplayers=num_of_players, skill=skill, private=private, leader=session.get('user_id'), available=1) utilities.send_email([user_info[0]['email']], 'Activity Created', 'You successfully created an activity!') redirect(url_for('home')) return render_template('create_event.html', key=utilities.get_key('google_maps'), user=user_info, categories=categories)
import unittest from amm_db import AmmDB import datetime from decimal import * import utilities import random from flask.ext import bcrypt global password password = utilities.get_key('db_pass') print(password) class TestAmmDB(unittest.TestCase): def test_conn_check(self): db = AmmDB(password) self.assertFalse(db.conn.closed, self) def test_get_where_stmnt(self): db = AmmDB(password) observed = db.get_where_stmnt("", "testCol", "testVal", "", 'like') expected = "WHERE testCol LIKE '%testVal%' " self.assertEqual(observed, expected) observed = db.get_where_stmnt("", "testCol", "testVal", "", '') expected = "WHERE testCol = 'testVal'" self.assertEqual(observed, expected) observed = db.get_where_stmnt("testWhere", "testCol", "testVal", ">", 'like') expected = " > testCol LIKE '%testVal%' "
import unittest from amm_db import AmmDB import datetime from decimal import * import utilities import random from flask.ext import bcrypt global password password = utilities.get_key('db_pass') print(password) class TestAmmDB(unittest.TestCase): def test_conn_check(self): db = AmmDB(password) self.assertFalse(db.conn.closed, self) def test_get_where_stmnt(self): db = AmmDB(password) observed = db.get_where_stmnt("", "testCol", "testVal", "", 'like') expected = "WHERE testCol LIKE '%testVal%' " self.assertEqual(observed, expected) observed = db.get_where_stmnt("", "testCol", "testVal", "", '') expected = "WHERE testCol = 'testVal'" self.assertEqual(observed, expected) observed = db.get_where_stmnt("testWhere", "testCol", "testVal", ">", 'like') expected = " > testCol LIKE '%testVal%' " self.assertEqual(observed, expected)
def search(): if session.get('user_id', None) is None: return redirect(url_for('main_page')) user_info = db.get_user(session.get('user_id')) categories = db.get_activity_type() skills = { 0: 'Any', 1: 'Beginner', 2: 'Intermediate', 3: 'Expert', 4: 'Master' } access = {0: 'Public', 1: 'Private'} user_activities = {} db_user_activities = db.get_all_user_activities() i = 0 for u_acts in db_user_activities: value = [u_acts['userid']] key = u_acts['activityid'] if len(user_activities) > 0: if user_activities.get(key) is not None: user_activities[key].append(value) else: user_activities[key] = value else: user_activities[key] = value i += 1 if request.method == 'POST': if request.form.get('join', None) is None: activity_name = request.form['activity-name'] results = db.get_act_type_join(name=activity_name) return render_template('SearchResultsPage.html', user=user_info, u_activities=user_activities, results=results, a=access, skills=skills, categories=categories, maps_key=utilities.get_key('google_maps')) else: db.add_user_activity(user_info[0]['id'], request.form['activity-id'], request.form['activity-private']) if request.form['activity-private'] == '0': utilities.send_email([user_info[0]['email']], 'Activity Joined', 'You successfully joined an activity!') return render_template('SearchResultsPage.html', user=user_info, u_activities=user_activities, categories=categories, a=access, skills=skills, maps_key=utilities.get_key('google_maps')) else: return render_template('SearchResultsPage.html', user=user_info, u_activities=user_activities, categories=categories, a=access, skills=skills, maps_key=utilities.get_key('google_maps'))