From 2fc1db6ee7f04a0dd9d17be86bf8fe26468fc4dc Mon Sep 17 00:00:00 2001 From: Aaron Rosen Date: Tue, 18 Nov 2014 17:59:21 -0500 Subject: [PATCH 001/165] format results page --- study_buddy/templates/search_results.html | 79 +++++------------------ 1 file changed, 16 insertions(+), 63 deletions(-) diff --git a/study_buddy/templates/search_results.html b/study_buddy/templates/search_results.html index 5966eaf..0db3430 100755 --- a/study_buddy/templates/search_results.html +++ b/study_buddy/templates/search_results.html @@ -16,68 +16,21 @@
Found {{count}} re - - - - - - - - - - - - - {% for i in range(count) %} - - - - - - - - - - - - {% endfor %} - -
Class Time Location Description
{{results[i].department}}{{results[i].courseNumber}}{{results[i].time}}{{results[i].location}}{{results[i].description}}
-
+
+
Class
+
Time
+
Location
+
Description
+
+ + {% for results in results: %} +
+
{{ result.department + result.course_no }}
+
{{ result.time }}
+
{{ result.location }}
+
{{ result.description }}
+
+ {% endfor %} + {% endblock %} \ No newline at end of file From 2b3a33a147a32ee9b156a2d89a3cf323218c58e6 Mon Sep 17 00:00:00 2001 From: denisefrancisco Date: Fri, 21 Nov 2014 14:40:19 -0500 Subject: [PATCH 002/165] fixed search function --- .DS_Store | Bin 6148 -> 6148 bytes study_buddy/templates/search_results.html | 34 +++++++++++++--------- study_buddy/views.py | 22 +++++++++----- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/.DS_Store b/.DS_Store index a154cb0766670052226290151f3377693c88f1ff..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 100755 GIT binary patch delta 70 zcmZoMXfc=|#>AjHu~2NHo+1YW5HK<@2yA9#Vq@DZz_f~SGdl-A2T%b}B`mF;Q%yo}wrd0|Nsi1A_nqLncFVQh9MfQcix-#Kh(GAPF{xVulii zL?A|z1d4A+D#*z!E-^5;#>m9X!pg?Z!O6+N6BC}9my%!ZlwX>cQXCzekzXF1nUb26 zSQHCpmn4>y7CR*tfn@>`OEQ2mV0K7;eh!cw163WKnNpGwpCuqsU2SM=sH0$HZc?kG zP;G8*prc@7Y*Aaw$-%)X$jHbcs-$P*5t3L_TUXxzbQBOU0(}AoyigiOH3Jzao+%41 y%FD^mO9zTGZcG$rn`|J$vYDHMn*$g!8xy}XPv#dFound {{count}} re - -
-
Class
-
Time
-
Location
-
Description
-
- - {% for results in results: %} + {% if results_exist: %}
-
{{ result.department + result.course_no }}
-
{{ result.time }}
-
{{ result.location }}
-
{{ result.description }}
+
Class
+
Time
+
Location
+
Description
- {% endfor %} + + {% for result in results: %} +
+
{{ result['department'] + result['course_no'] }}
+
{{ result.time }}
+
{{ result.location }}
+
{{ result.description }}
+
+ {% endfor %} + {% else: %} +
+ There are no sessions matching your search, click here to create a new one +
+ {% endif %} + {% endblock %} \ No newline at end of file diff --git a/study_buddy/views.py b/study_buddy/views.py index cb4d145..36e3f38 100755 --- a/study_buddy/views.py +++ b/study_buddy/views.py @@ -15,6 +15,7 @@ import random import time from dateutil.parser import parse +from bson.json_util import dumps ## # Constants for mongodb keys @@ -122,24 +123,31 @@ def search(): print "COURSE KEYWORD:",course_keyword search_results = None + results_exist = True if course_keyword and dept_keyword: - search_result = mongo_db.study_sessions.StudySession.find_one( + search_results = mongo_db.study_sessions.StudySession.find( {'course_no' : course_keyword, 'department' : dept_keyword}) + print search_results , "We are in if condition" elif dept_keyword and not course_keyword: - search_results = mongo_db.study_sessions.StudySession.find_one( + search_results = mongo_db.study_sessions.StudySession.find( {'dept_keyword' : dept_keyword}) else: search_results = mongo_db.study_sessions.StudySession.find() # else we have no results - if search_results: + search_results_list = list(search_results) + print search_results_list, "This is a list of search results" + if len(search_results_list) > 0: + print "Text" for result in search_results: - print result + print result, search_results[result] else: - return 'No results' - - return render_template('search_results.html',results = search_results) + results_exist = False + + search_results.rewind() + return render_template('search_results.html', results = search_results, + results_exist = results_exist) # @app.route('/') From fd3644cdd0c2c17bb1e98b3d2e830977e8c146de Mon Sep 17 00:00:00 2001 From: Aaron Rosen Date: Thu, 27 Nov 2014 09:10:28 -0500 Subject: [PATCH 003/165] fixed search all the way --- study_buddy/views.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/study_buddy/views.py b/study_buddy/views.py index 36e3f38..8e0fe3e 100755 --- a/study_buddy/views.py +++ b/study_buddy/views.py @@ -1,6 +1,6 @@ from . import app, db, mongo_db -from flask import Flask, url_for, redirect, session, render_template, request +from flask import Flask, url_for, redirect, session, render_template, request, flash from flask_login import (UserMixin, login_required, login_user, logout_user, current_user) from flask.ext.security import LoginForm @@ -130,18 +130,20 @@ def search(): {'course_no' : course_keyword, 'department' : dept_keyword}) print search_results , "We are in if condition" elif dept_keyword and not course_keyword: + print "only department entered" search_results = mongo_db.study_sessions.StudySession.find( - {'dept_keyword' : dept_keyword}) - else: + {'department' : dept_keyword}) + elif not dept_keyword and not course_keyword: search_results = mongo_db.study_sessions.StudySession.find() + else: + flash('Enter something to search!') + return render_template('index.html') # else we have no results - search_results_list = list(search_results) - print search_results_list, "This is a list of search results" - if len(search_results_list) > 0: + if search_results.count() > 0: print "Text" for result in search_results: - print result, search_results[result] + print result else: results_exist = False From ce6fab06b78a8e5a8940c567a0c88dd5ce3bac55 Mon Sep 17 00:00:00 2001 From: Aaron Rosen Date: Fri, 28 Nov 2014 09:13:13 -0500 Subject: [PATCH 004/165] fix search on search results page --- study_buddy/helpers.py | 49 +++++++++++++++++++++++ study_buddy/static/styles.css | 34 +++++++++++++++- study_buddy/templates/search_results.html | 15 +++---- study_buddy/views.py | 9 ++++- 4 files changed, 96 insertions(+), 11 deletions(-) create mode 100644 study_buddy/helpers.py diff --git a/study_buddy/helpers.py b/study_buddy/helpers.py new file mode 100644 index 0000000..3124f45 --- /dev/null +++ b/study_buddy/helpers.py @@ -0,0 +1,49 @@ +import re + +## +# @returns returns True if c is a number +## +def is_number(c): + try: + float(c) + return True + except ValueError: + return False + +## +# Given a string, query, this function parses it to find a +# department and a course number and returns a tuple of the two. +# @returns return (department : string, course_number : string) +## +def parse_new_find(query): + is_digit = False + department_end = -1 + number_end = -1 + for i in range(1, len(query)+1): + c = query[len(query) - i] + if is_number(c) and is_digit: + continue + if is_number(c): + is_digit = True + number_end = (len(query) + 1) - i + if not is_number(c): + is_digit = False + department_end = (len(query) + 1) - i + break + + if department_end >= 0 and number_end >= 0: + course_number = query[department_end : number_end] + department_name = query[0 : department_end] + elif department_end >= 0: + department_name = query[0 : department_end] + course_number = '' + else: + department_name = '' + course_number = '' + + print query + print "course number:", course_number + print "department name:", department_name + print "=================================================" + + return (department_name.strip(), course_number.strip()) diff --git a/study_buddy/static/styles.css b/study_buddy/static/styles.css index 23af63e..d392ed7 100755 --- a/study_buddy/static/styles.css +++ b/study_buddy/static/styles.css @@ -18,6 +18,35 @@ body { background-attachment: fixed; } +.center-elmt { + margin-left: auto; + margin-right: auto; +} + +.center-txt { + text-align: center; +} + +.search-row-odd { + padding-bottom: 5px; + padding-top: 5px; + background-color: rgba(51, 51, 51, 0.7); +} + +.search-row-even { + padding-bottom: 2px; + padding-top: 5px; + background-color: rgba(0, 51, 102, 0.7); +} + +#search-results-container { + color: white; +} + +#no-search-results { + margin: 15px 0; +} + #ui-datepicker-div { width: 20%; text-decoration: none; @@ -134,7 +163,6 @@ nav.top-bar { margin-right: auto; } - #searchresults { width: 80%; margin-left: 10%; @@ -222,13 +250,15 @@ nav.top-bar { margin-left: auto; margin-right: auto; text-shadow: 0.7px 0.7px #000000; - + position: fixed; + bottom: 0; } #bot { font-size: 16px; text-align: center; color: beige; margin-bottom: 0; + } .wrapper { diff --git a/study_buddy/templates/search_results.html b/study_buddy/templates/search_results.html index f59a5e1..ffea31f 100755 --- a/study_buddy/templates/search_results.html +++ b/study_buddy/templates/search_results.html @@ -11,11 +11,11 @@

Search Results

Found {{count}} results
-
- - -
+
+ +
+
{% if results_exist: %}
Class
@@ -23,9 +23,9 @@
Found {{count}} re
Location
Description
- + {% for result in results: %} -
+
{{ result['department'] + result['course_no'] }}
{{ result.time }}
{{ result.location }}
@@ -33,10 +33,11 @@
Found {{count}} re
{% endfor %} {% else: %} -
+
There are no sessions matching your search, click here to create a new one
{% endif %} +
{% endblock %} \ No newline at end of file diff --git a/study_buddy/views.py b/study_buddy/views.py index 8e0fe3e..8c75dcf 100755 --- a/study_buddy/views.py +++ b/study_buddy/views.py @@ -16,6 +16,7 @@ import time from dateutil.parser import parse from bson.json_util import dumps +from helpers import * ## # Constants for mongodb keys @@ -116,8 +117,12 @@ def home(): @app.route('/find') def search(): - course_keyword = request.args.get('course_no') - dept_keyword = request.args.get('dept_keyword') + if 'new_find' in request.args: # request coming from /find page + search_query = request.args.get('new_find') + dept_keyword, course_keyword = parse_new_find(search_query) + else: + course_keyword = request.args.get('course_no') + dept_keyword = request.args.get('dept_keyword') print "DEPT KEYWORD:",dept_keyword print "COURSE KEYWORD:",course_keyword From 3397a033991e6af09afe4cec47a17e976c8d02ca Mon Sep 17 00:00:00 2001 From: Aaron Rosen Date: Fri, 28 Nov 2014 09:44:34 -0500 Subject: [PATCH 005/165] clean up search results page header --- study_buddy/templates/search_results.html | 30 +++++++++++++++++------ 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/study_buddy/templates/search_results.html b/study_buddy/templates/search_results.html index ffea31f..274a54a 100755 --- a/study_buddy/templates/search_results.html +++ b/study_buddy/templates/search_results.html @@ -7,15 +7,29 @@ {% endblock %} {% block content %} -