Skip to content

Commit c1272e9

Browse files
committed
Merge pull request #32 from uw-it-aca/qa
In prep for a release.
2 parents 1cd4182 + edf86b0 commit c1272e9

File tree

110 files changed

+2553
-1199
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+2553
-1199
lines changed

.jshintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
myuw_mobile/static/js/vendor/**

.travis.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ before_script:
77
- pip install coverage
88
- pip install python-coveralls
99
- pip install pep8
10+
- npm install jshint
1011
- cp travis-ci/manage.py manage.py
1112
- python manage.py syncdb --noinput
1213
script:
13-
- pep8 myuw_mobile/ --exclude=migrations,myuw_mobile/test,myuw_mobile/restclients,myuw_mobile/logger,myuw_mobile/dao,myuw_mobile/management
14+
- pep8 myuw_mobile/ --exclude=migrations,myuw_mobile/test,myuw_mobile/management
15+
- jshint myuw_mobile/static/js/ --verbose
1416
- coverage run --source=myuw_mobile/ manage.py test myuw_mobile
1517
after_script:
1618
- coveralls

myuw_mobile/context_processors.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
def has_less_compiled(request):
55
""" See if django-compressor is being used to precompile less
66
"""
7-
key = getattr(settings, "COMPRESS_PRECOMPILERS", None)
8-
return {'has_less_compiled': key != ()}
7+
key = getattr(settings, "COMPRESS_PRECOMPILERS", ())
8+
9+
has_less_precompiler = False
10+
for entry in key:
11+
if entry[0] == "text/less":
12+
has_less_precompiler = True
13+
return {'has_less_compiled': has_less_precompiler}
914

1015

1116
def less_not_compiled(request):

myuw_mobile/dao/affiliation.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
logger = logging.getLogger(__name__)
1515

1616

17-
def get_all_affiliations():
17+
def get_all_affiliations(request):
1818
"""
1919
return a dictionary of affiliation indicators.
2020
["grad"]: True if the user is currently an UW graduate student.
@@ -24,7 +24,7 @@ def get_all_affiliations():
2424
["seattle"]: True if the user is an UW Seattle student
2525
in the current quarter.
2626
["bothell"]: True if the user is an UW Bothell student
27-
in the current quarter.
27+
in the current quarter.
2828
["tacoma"]: True if the user is an UW Tacoma student
2929
in the current quarter.
3030
["official_seattle"]: True if the user is an UW Seattle student
@@ -35,7 +35,7 @@ def get_all_affiliations():
3535
according to the SWS Enrollment.
3636
"""
3737

38-
enrolled_campuses = get_current_quarter_course_campuses()
38+
enrolled_campuses = get_current_quarter_course_campuses(request)
3939
data = {"grad": is_grad_student(),
4040
"undergrad": is_undergrad_student(),
4141
"pce": is_pce_student(),
@@ -44,8 +44,8 @@ def get_all_affiliations():
4444
"bothell": enrolled_campuses["bothell"] or is_bothell_student(),
4545
"tacoma": enrolled_campuses["tacoma"] or is_tacoma_student(),
4646
}
47-
#add 'official' campus info
48-
official_campuses = _get_official_campuses(get_main_campus())
47+
# add 'official' campus info
48+
official_campuses = _get_official_campuses(get_main_campus(request))
4949
data = dict(data.items() + official_campuses.items())
5050
# Note:
5151
# As the UW Affiliation group (gws) only knows about one campus,
@@ -59,9 +59,9 @@ def _get_campuses_by_schedule(schedule):
5959
"""
6060
Returns a dictionary indicating the campuses that the student
6161
has enrolled in the given schedule:
62-
{ seattle: false|true,
62+
{ seattle: false|true,
6363
bothell: false|true,
64-
tacoma: false|true }
64+
tacoma: false|true }
6565
True if the user is registered on that campus.
6666
"""
6767
campuses = {"seattle": False,
@@ -71,11 +71,11 @@ def _get_campuses_by_schedule(schedule):
7171
if schedule is not None and len(schedule.sections) > 0:
7272
for section in schedule.sections:
7373
if section.course_campus == "Seattle":
74-
campuses["seattle"]=True
74+
campuses["seattle"] = True
7575
elif section.course_campus == "Bothell":
76-
campuses["bothell"]=True
76+
campuses["bothell"] = True
7777
elif section.course_campus == "Tacoma":
78-
campuses["tacoma"]=True
78+
campuses["tacoma"] = True
7979
else:
8080
pass
8181
return campuses
@@ -97,21 +97,21 @@ def _get_official_campuses(campuses):
9797
return official_campuses
9898

9999

100-
def get_current_quarter_course_campuses():
100+
def get_current_quarter_course_campuses(request):
101101
"""
102102
Returns a dictionary indicating the campuses that the student
103103
has enrolled in the current quarter.
104104
"""
105-
return _get_campuses_by_schedule(get_current_quarter_schedule())
105+
return _get_campuses_by_schedule(get_current_quarter_schedule(request))
106106

107107

108-
def get_base_campus():
108+
def get_base_campus(request):
109109
"""
110110
Return one currently enrolled campus.
111111
If not exist, return one affiliated campus.
112112
"""
113113
campus = ""
114-
affiliations = get_all_affiliations()
114+
affiliations = get_all_affiliations(request)
115115
try:
116116
if affiliations["official_seattle"]:
117117
campus = "seattle"

myuw_mobile/dao/building.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
"""
2-
This module gives access to building data
2+
This module gives access to building data
33
"""
4-
54
import json
65
import os
76
from myuw_mobile.models import Building
87

8+
99
def get_building_by_code(code):
1010
"""
11-
Returns a Building model for the given code, or None
11+
Returns a Building model for the given code, or None
1212
"""
1313
path = os.path.join(
14-
os.path.dirname( __file__ ),
14+
os.path.dirname(__file__),
1515
'..', 'data', 'buildings.json')
1616

1717
f = open(path)
@@ -39,17 +39,15 @@ def get_buildings_by_schedule(schedule):
3939
for section in schedule.sections:
4040
if section.final_exam and section.final_exam.building:
4141
code = section.final_exam.building
42-
if not code in buildings:
42+
if code not in buildings:
4343
building = get_building_by_code(code)
4444
buildings[code] = building
4545

4646
for meeting in section.meetings:
4747
if not meeting.building_to_be_arranged:
48-
if not meeting.building in buildings:
48+
if meeting.building not in buildings:
4949
code = meeting.building
5050
building = get_building_by_code(code)
5151
buildings[code] = building
5252

5353
return buildings
54-
55-

myuw_mobile/dao/canvas.py

+33-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from restclients.canvas.enrollments import Enrollments as CanvasEnrollments
2+
from restclients.canvas.sections import Sections
3+
from restclients.canvas.courses import Courses
24
from myuw_mobile.dao.pws import get_regid_of_current_user
35
from myuw_mobile.logger.timer import Timer
46
from myuw_mobile.logger.logback import log_resp_time, log_exception
@@ -16,14 +18,9 @@ def get_canvas_enrolled_courses():
1618
timer = Timer()
1719
try:
1820
regid = get_regid_of_current_user()
19-
return _indexed_by_course_id(
20-
CanvasEnrollments().get_enrollments_for_regid(
21-
regid,
22-
{'state': "active",
23-
'as_user': CanvasEnrollments().sis_user_id(regid)})
24-
)
21+
return get_indexed_data_for_regid(regid)
2522
except AttributeError:
26-
#If course is not in canvas, skip
23+
# If course is not in canvas, skip
2724
pass
2825
except Exception as ex:
2926
log_exception(logger,
@@ -36,6 +33,35 @@ def get_canvas_enrolled_courses():
3633
return []
3734

3835

36+
def get_indexed_data_for_regid(regid):
37+
return _indexed_by_course_id(
38+
CanvasEnrollments().get_enrollments_for_regid(
39+
regid,
40+
{'state': "active",
41+
'as_user': CanvasEnrollments().sis_user_id(regid)})
42+
)
43+
44+
45+
def get_indexed_by_decrosslisted(by_primary, sws_sections):
46+
47+
for section in sws_sections:
48+
alternate_id = None
49+
try:
50+
sis_id = section.canvas_section_sis_id()
51+
canvas_section = Sections().get_section_by_sis_id(sis_id)
52+
primary_course = Courses().get_course(canvas_section.course_id)
53+
alternate_id = primary_course.sws_course_id()
54+
except Exception as ex:
55+
alternate_id = section.section_label()
56+
57+
base_id = section.section_label()
58+
59+
if base_id not in by_primary:
60+
if alternate_id in by_primary:
61+
by_primary[base_id] = by_primary[alternate_id]
62+
return by_primary
63+
64+
3965
def _indexed_by_course_id(enrollments):
4066
"""
4167
return a dictionary of SWS course id to enrollment.

myuw_mobile/dao/card_display_dates.py

+37-37
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,37 @@
22
Generates the 7 booleans used to determine card visibility, based on dates in
33
either the current, next, or previous term.
44
5-
https://docs.google.com/a/uw.edu/document/d/14q26auOLPU34KFtkUmC_bkoo5dAwegRzgpwmZEQMhaU/edit
5+
https://docs.google.com/document/d/14q26auOLPU34KFtkUmC_bkoo5dAwegRzgpwmZEQMhaU
66
"""
77

88
from restclients.sws import term
99
from django.conf import settings
1010
from datetime import datetime, timedelta
11+
from myuw_mobile.dao.term import get_comparison_date, get_current_quarter
12+
from myuw_mobile.dao.term import get_next_quarter
1113

12-
def get_card_visibilty_date_values():
13-
current_term = term.get_current_term()
1414

15-
# Doing this instead of get_next/get_previous,
16-
# because of this in get_current_term:
17-
# if datetime.now() > term.grade_submission_deadline:
18-
# return get_next_term()
19-
last_term = term.get_term_before(current_term)
20-
next_term = term.get_term_after(current_term)
15+
def get_card_visibilty_date_values(request=None):
16+
now = get_comparison_date(request)
17+
n2 = datetime(now.year, now.month, now.day, 0, 0, 0)
18+
values = get_values_by_date(n2, request)
19+
set_js_overrides(request, values)
20+
return values
21+
22+
23+
def get_values_by_date(now, request):
24+
current_term = get_current_quarter(request)
25+
next_term = get_next_quarter(request)
2126

2227
is_after_grade_submission_deadline = False
2328
is_after_last_day_of_classes = False
2429
is_after_start_of_registration_display_period = False
25-
is_before_first_day_of_current_term = False
2630
is_before_end_of_finals_week = False
2731
is_before_last_day_of_classes = False
2832
is_before_end_of_registration_display_period = False
2933

30-
now = get_comparison_date()
31-
32-
if now > last_term.grade_submission_deadline:
33-
is_after_start_of_registration_display_period = True
34+
if now > current_term.grade_submission_deadline:
35+
is_after_grade_submission_deadline = True
3436

3537
raw_date = current_term.last_day_instruction
3638
d = datetime(raw_date.year, raw_date.month, raw_date.day)
@@ -40,17 +42,12 @@ def get_card_visibilty_date_values():
4042
# XXX - this will be a bug when summer quarter comes around
4143
# because there will need to be a summer term + a next non-summer term
4244
# version of this. We're holding off on the summer term card though...
43-
if now - timedelta(days=7) > next_term.registration_services_start:
45+
if now >= next_term.registration_services_start - timedelta(days=7):
4446
is_after_start_of_registration_display_period = True
4547

4648
if now < next_term.registration_period2_start + timedelta(days=7):
4749
is_before_end_of_registration_display_period = True
4850

49-
raw_date = current_term.first_day_quarter
50-
d = datetime(raw_date.year, raw_date.month, raw_date.day)
51-
if now < d:
52-
is_before_first_day_of_current_term = True
53-
5451
raw_date = current_term.last_final_exam_date
5552
d = datetime(raw_date.year, raw_date.month, raw_date.day)
5653
if now < d:
@@ -61,27 +58,30 @@ def get_card_visibilty_date_values():
6158
if now < d + timedelta(days=1):
6259
is_before_last_day_of_classes = True
6360

61+
after_submission = is_after_grade_submission_deadline
62+
after_registration = is_after_start_of_registration_display_period
63+
before_reg_end = is_before_end_of_registration_display_period
6464
return {
65-
"is_after_grade_submission_deadline": is_after_grade_submission_deadline,
65+
"is_after_grade_submission_deadline": after_submission,
6666
"is_after_last_day_of_classes": is_after_last_day_of_classes,
67-
"is_after_start_of_registration_display_period": is_after_start_of_registration_display_period,
68-
"is_before_first_day_of_current_term": is_before_first_day_of_current_term,
67+
"is_after_start_of_registration_display_period": after_registration,
6968
"is_before_end_of_finals_week": is_before_end_of_finals_week,
7069
"is_before_last_day_of_classes": is_before_last_day_of_classes,
71-
"is_before_end_of_registration_display_period": is_before_end_of_registration_display_period,
70+
"is_before_end_of_registration_display_period": before_reg_end,
7271
}
7372

7473

75-
def get_comparison_date():
76-
"""
77-
Allows us to pretend we're at various points in the term,
78-
so we can test against live data sources at various points in the year.
79-
"""
80-
81-
override_date = getattr(settings, "MYUW_CARD_DISPLAY_DATE_OVERRIDE", None)
82-
83-
if override_date:
84-
return datetime.strptime(override_date, "%Y-%m-%d")
85-
86-
return datetime.now()
87-
74+
def set_js_overrides(request, values):
75+
after_reg = 'is_after_start_of_registration_display_period'
76+
before_reg = 'is_before_end_of_registration_display_period'
77+
MAP = {'myuw_after_submission': 'is_after_grade_submission_deadline',
78+
'myuw_after_last_day': 'is_after_last_day_of_classes',
79+
'myuw_after_reg': after_reg,
80+
'myuw_before_finals_end': 'is_before_end_of_finals_week',
81+
'myuw_before_last_day': 'is_before_last_day_of_classes',
82+
'myuw_before_end_of_reg_display': before_reg,
83+
}
84+
85+
for key, value in MAP.iteritems():
86+
if key in request.session:
87+
values[value] = request.session[key]

myuw_mobile/dao/category_links.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
from django.db.models import Q
22
from myuw_mobile.models import CategoryLinks
3-
from myuw_mobile.dao.affiliation import get_all_affiliations, get_base_campus
3+
from myuw_mobile.dao.affiliation import get_base_campus
44
import csv
55
import os
66

77

8-
def get_links_for_category(search_category_id):
9-
campus = get_base_campus()
8+
def get_links_for_category(search_category_id, request):
9+
return _get_links_by_category_and_campus(search_category_id,
10+
get_base_campus(request))
1011

12+
13+
def _get_links_by_category_and_campus(search_category_id, campus):
1114
links = []
1215
path = os.path.join(
13-
os.path.dirname( __file__ ),
16+
os.path.dirname(__file__),
1417
'..', 'data', 'category_links_import.csv')
1518
with open(path, 'rbU') as csvfile:
1619
reader = csv.reader(csvfile, delimiter=',', quotechar='"')

0 commit comments

Comments
 (0)