Skip to content

Commit

Permalink
Merge pull request #32 from uw-it-aca/qa
Browse files Browse the repository at this point in the history
In prep for a release.
  • Loading branch information
vegitron committed Dec 15, 2014
2 parents 1cd4182 + edf86b0 commit c1272e9
Show file tree
Hide file tree
Showing 110 changed files with 2,553 additions and 1,199 deletions.
1 change: 1 addition & 0 deletions .jshintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
myuw_mobile/static/js/vendor/**
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ before_script:
- pip install coverage
- pip install python-coveralls
- pip install pep8
- npm install jshint
- cp travis-ci/manage.py manage.py
- python manage.py syncdb --noinput
script:
- pep8 myuw_mobile/ --exclude=migrations,myuw_mobile/test,myuw_mobile/restclients,myuw_mobile/logger,myuw_mobile/dao,myuw_mobile/management
- pep8 myuw_mobile/ --exclude=migrations,myuw_mobile/test,myuw_mobile/management
- jshint myuw_mobile/static/js/ --verbose
- coverage run --source=myuw_mobile/ manage.py test myuw_mobile
after_script:
- coveralls
Expand Down
9 changes: 7 additions & 2 deletions myuw_mobile/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
def has_less_compiled(request):
""" See if django-compressor is being used to precompile less
"""
key = getattr(settings, "COMPRESS_PRECOMPILERS", None)
return {'has_less_compiled': key != ()}
key = getattr(settings, "COMPRESS_PRECOMPILERS", ())

has_less_precompiler = False
for entry in key:
if entry[0] == "text/less":
has_less_precompiler = True
return {'has_less_compiled': has_less_precompiler}


def less_not_compiled(request):
Expand Down
28 changes: 14 additions & 14 deletions myuw_mobile/dao/affiliation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
logger = logging.getLogger(__name__)


def get_all_affiliations():
def get_all_affiliations(request):
"""
return a dictionary of affiliation indicators.
["grad"]: True if the user is currently an UW graduate student.
Expand All @@ -24,7 +24,7 @@ def get_all_affiliations():
["seattle"]: True if the user is an UW Seattle student
in the current quarter.
["bothell"]: True if the user is an UW Bothell student
in the current quarter.
in the current quarter.
["tacoma"]: True if the user is an UW Tacoma student
in the current quarter.
["official_seattle"]: True if the user is an UW Seattle student
Expand All @@ -35,7 +35,7 @@ def get_all_affiliations():
according to the SWS Enrollment.
"""

enrolled_campuses = get_current_quarter_course_campuses()
enrolled_campuses = get_current_quarter_course_campuses(request)
data = {"grad": is_grad_student(),
"undergrad": is_undergrad_student(),
"pce": is_pce_student(),
Expand All @@ -44,8 +44,8 @@ def get_all_affiliations():
"bothell": enrolled_campuses["bothell"] or is_bothell_student(),
"tacoma": enrolled_campuses["tacoma"] or is_tacoma_student(),
}
#add 'official' campus info
official_campuses = _get_official_campuses(get_main_campus())
# add 'official' campus info
official_campuses = _get_official_campuses(get_main_campus(request))
data = dict(data.items() + official_campuses.items())
# Note:
# As the UW Affiliation group (gws) only knows about one campus,
Expand All @@ -59,9 +59,9 @@ def _get_campuses_by_schedule(schedule):
"""
Returns a dictionary indicating the campuses that the student
has enrolled in the given schedule:
{ seattle: false|true,
{ seattle: false|true,
bothell: false|true,
tacoma: false|true }
tacoma: false|true }
True if the user is registered on that campus.
"""
campuses = {"seattle": False,
Expand All @@ -71,11 +71,11 @@ def _get_campuses_by_schedule(schedule):
if schedule is not None and len(schedule.sections) > 0:
for section in schedule.sections:
if section.course_campus == "Seattle":
campuses["seattle"]=True
campuses["seattle"] = True
elif section.course_campus == "Bothell":
campuses["bothell"]=True
campuses["bothell"] = True
elif section.course_campus == "Tacoma":
campuses["tacoma"]=True
campuses["tacoma"] = True
else:
pass
return campuses
Expand All @@ -97,21 +97,21 @@ def _get_official_campuses(campuses):
return official_campuses


def get_current_quarter_course_campuses():
def get_current_quarter_course_campuses(request):
"""
Returns a dictionary indicating the campuses that the student
has enrolled in the current quarter.
"""
return _get_campuses_by_schedule(get_current_quarter_schedule())
return _get_campuses_by_schedule(get_current_quarter_schedule(request))


def get_base_campus():
def get_base_campus(request):
"""
Return one currently enrolled campus.
If not exist, return one affiliated campus.
"""
campus = ""
affiliations = get_all_affiliations()
affiliations = get_all_affiliations(request)
try:
if affiliations["official_seattle"]:
campus = "seattle"
Expand Down
14 changes: 6 additions & 8 deletions myuw_mobile/dao/building.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
"""
This module gives access to building data
This module gives access to building data
"""

import json
import os
from myuw_mobile.models import Building


def get_building_by_code(code):
"""
Returns a Building model for the given code, or None
Returns a Building model for the given code, or None
"""
path = os.path.join(
os.path.dirname( __file__ ),
os.path.dirname(__file__),
'..', 'data', 'buildings.json')

f = open(path)
Expand Down Expand Up @@ -39,17 +39,15 @@ def get_buildings_by_schedule(schedule):
for section in schedule.sections:
if section.final_exam and section.final_exam.building:
code = section.final_exam.building
if not code in buildings:
if code not in buildings:
building = get_building_by_code(code)
buildings[code] = building

for meeting in section.meetings:
if not meeting.building_to_be_arranged:
if not meeting.building in buildings:
if meeting.building not in buildings:
code = meeting.building
building = get_building_by_code(code)
buildings[code] = building

return buildings


40 changes: 33 additions & 7 deletions myuw_mobile/dao/canvas.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from restclients.canvas.enrollments import Enrollments as CanvasEnrollments
from restclients.canvas.sections import Sections
from restclients.canvas.courses import Courses
from myuw_mobile.dao.pws import get_regid_of_current_user
from myuw_mobile.logger.timer import Timer
from myuw_mobile.logger.logback import log_resp_time, log_exception
Expand All @@ -16,14 +18,9 @@ def get_canvas_enrolled_courses():
timer = Timer()
try:
regid = get_regid_of_current_user()
return _indexed_by_course_id(
CanvasEnrollments().get_enrollments_for_regid(
regid,
{'state': "active",
'as_user': CanvasEnrollments().sis_user_id(regid)})
)
return get_indexed_data_for_regid(regid)
except AttributeError:
#If course is not in canvas, skip
# If course is not in canvas, skip
pass
except Exception as ex:
log_exception(logger,
Expand All @@ -36,6 +33,35 @@ def get_canvas_enrolled_courses():
return []


def get_indexed_data_for_regid(regid):
return _indexed_by_course_id(
CanvasEnrollments().get_enrollments_for_regid(
regid,
{'state': "active",
'as_user': CanvasEnrollments().sis_user_id(regid)})
)


def get_indexed_by_decrosslisted(by_primary, sws_sections):

for section in sws_sections:
alternate_id = None
try:
sis_id = section.canvas_section_sis_id()
canvas_section = Sections().get_section_by_sis_id(sis_id)
primary_course = Courses().get_course(canvas_section.course_id)
alternate_id = primary_course.sws_course_id()
except Exception as ex:
alternate_id = section.section_label()

base_id = section.section_label()

if base_id not in by_primary:
if alternate_id in by_primary:
by_primary[base_id] = by_primary[alternate_id]
return by_primary


def _indexed_by_course_id(enrollments):
"""
return a dictionary of SWS course id to enrollment.
Expand Down
74 changes: 37 additions & 37 deletions myuw_mobile/dao/card_display_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,37 @@
Generates the 7 booleans used to determine card visibility, based on dates in
either the current, next, or previous term.
https://docs.google.com/a/uw.edu/document/d/14q26auOLPU34KFtkUmC_bkoo5dAwegRzgpwmZEQMhaU/edit
https://docs.google.com/document/d/14q26auOLPU34KFtkUmC_bkoo5dAwegRzgpwmZEQMhaU
"""

from restclients.sws import term
from django.conf import settings
from datetime import datetime, timedelta
from myuw_mobile.dao.term import get_comparison_date, get_current_quarter
from myuw_mobile.dao.term import get_next_quarter

def get_card_visibilty_date_values():
current_term = term.get_current_term()

# Doing this instead of get_next/get_previous,
# because of this in get_current_term:
# if datetime.now() > term.grade_submission_deadline:
# return get_next_term()
last_term = term.get_term_before(current_term)
next_term = term.get_term_after(current_term)
def get_card_visibilty_date_values(request=None):
now = get_comparison_date(request)
n2 = datetime(now.year, now.month, now.day, 0, 0, 0)
values = get_values_by_date(n2, request)
set_js_overrides(request, values)
return values


def get_values_by_date(now, request):
current_term = get_current_quarter(request)
next_term = get_next_quarter(request)

is_after_grade_submission_deadline = False
is_after_last_day_of_classes = False
is_after_start_of_registration_display_period = False
is_before_first_day_of_current_term = False
is_before_end_of_finals_week = False
is_before_last_day_of_classes = False
is_before_end_of_registration_display_period = False

now = get_comparison_date()

if now > last_term.grade_submission_deadline:
is_after_start_of_registration_display_period = True
if now > current_term.grade_submission_deadline:
is_after_grade_submission_deadline = True

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

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

raw_date = current_term.first_day_quarter
d = datetime(raw_date.year, raw_date.month, raw_date.day)
if now < d:
is_before_first_day_of_current_term = True

raw_date = current_term.last_final_exam_date
d = datetime(raw_date.year, raw_date.month, raw_date.day)
if now < d:
Expand All @@ -61,27 +58,30 @@ def get_card_visibilty_date_values():
if now < d + timedelta(days=1):
is_before_last_day_of_classes = True

after_submission = is_after_grade_submission_deadline
after_registration = is_after_start_of_registration_display_period
before_reg_end = is_before_end_of_registration_display_period
return {
"is_after_grade_submission_deadline": is_after_grade_submission_deadline,
"is_after_grade_submission_deadline": after_submission,
"is_after_last_day_of_classes": is_after_last_day_of_classes,
"is_after_start_of_registration_display_period": is_after_start_of_registration_display_period,
"is_before_first_day_of_current_term": is_before_first_day_of_current_term,
"is_after_start_of_registration_display_period": after_registration,
"is_before_end_of_finals_week": is_before_end_of_finals_week,
"is_before_last_day_of_classes": is_before_last_day_of_classes,
"is_before_end_of_registration_display_period": is_before_end_of_registration_display_period,
"is_before_end_of_registration_display_period": before_reg_end,
}


def get_comparison_date():
"""
Allows us to pretend we're at various points in the term,
so we can test against live data sources at various points in the year.
"""

override_date = getattr(settings, "MYUW_CARD_DISPLAY_DATE_OVERRIDE", None)

if override_date:
return datetime.strptime(override_date, "%Y-%m-%d")

return datetime.now()

def set_js_overrides(request, values):
after_reg = 'is_after_start_of_registration_display_period'
before_reg = 'is_before_end_of_registration_display_period'
MAP = {'myuw_after_submission': 'is_after_grade_submission_deadline',
'myuw_after_last_day': 'is_after_last_day_of_classes',
'myuw_after_reg': after_reg,
'myuw_before_finals_end': 'is_before_end_of_finals_week',
'myuw_before_last_day': 'is_before_last_day_of_classes',
'myuw_before_end_of_reg_display': before_reg,
}

for key, value in MAP.iteritems():
if key in request.session:
values[value] = request.session[key]
11 changes: 7 additions & 4 deletions myuw_mobile/dao/category_links.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
from django.db.models import Q
from myuw_mobile.models import CategoryLinks
from myuw_mobile.dao.affiliation import get_all_affiliations, get_base_campus
from myuw_mobile.dao.affiliation import get_base_campus
import csv
import os


def get_links_for_category(search_category_id):
campus = get_base_campus()
def get_links_for_category(search_category_id, request):
return _get_links_by_category_and_campus(search_category_id,
get_base_campus(request))


def _get_links_by_category_and_campus(search_category_id, campus):
links = []
path = os.path.join(
os.path.dirname( __file__ ),
os.path.dirname(__file__),
'..', 'data', 'category_links_import.csv')
with open(path, 'rbU') as csvfile:
reader = csv.reader(csvfile, delimiter=',', quotechar='"')
Expand Down
Loading

0 comments on commit c1272e9

Please sign in to comment.