Skip to content

Commit

Permalink
Merge pull request #814 from uw-it-aca/qa
Browse files Browse the repository at this point in the history
Qa
  • Loading branch information
fanglinfang authored Jul 27, 2017
2 parents fd09677 + 4b59f12 commit 13fbbda
Show file tree
Hide file tree
Showing 276 changed files with 7,432 additions and 2,051 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,6 @@ db.sqlite3

# Mac OS
*.DS_Store

pip-selfcheck.json
share/
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
sudo: false
language: python
dist: precise
services:
- memcached
- mysql
Expand All @@ -10,7 +11,7 @@ env:
- DB=sqlite3
- DB=mysql
global:
- TRAVIS_NODE_VERSION="4"
- TRAVIS_NODE_VERSION="6"
install:
- pip install -r requirements.txt
before_script:
Expand Down
3 changes: 2 additions & 1 deletion myuw/dao/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os
from django.conf import settings
from restclients.dao import SWS_DAO
from uw_sws.dao import SWS_DAO
from userservice.user import UserService
from myuw.models import User
from uw_pws import PWS


def get_netid_of_current_user():
Expand Down
70 changes: 68 additions & 2 deletions myuw/dao/affiliation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
is_pce_student, is_student_employee, is_employee, is_faculty,\
is_seattle_student, is_bothell_student, is_tacoma_student,\
is_staff_employee
from myuw.dao.instructor_schedule import is_instructor
from myuw.dao.uwnetid import is_clinician
from myuw.dao.enrollment import get_main_campus
from myuw.dao.exceptions import IndeterminateCampusException
Expand Down Expand Up @@ -44,6 +45,8 @@ def get_all_affiliations(request):
according to the SWS Enrollment.
["official_tacoma"]: True if the user is an UW Tacoma student
according to the SWS Enrollment.
["official_pce"]: True if the user is an UW PCE student
according to the SWS Enrollment.
"""

if hasattr(request, 'myuw_user_affiliations'):
Expand All @@ -60,11 +63,13 @@ def get_all_affiliations(request):
"undergrad": is_undergrad_student(),
"student": is_student(),
"pce": is_pce_student(),
"staff_employee": is_staff_employee(),
"stud_employee": is_student_employee(),
"employee": is_employee(),
"fyp": is_fyp,
"faculty": is_faculty(),
"clinician": is_clinician(),
"instructor": is_instructor(request),
"seattle": is_seattle_student(),
"bothell": is_bothell_student(),
"tacoma": is_tacoma_student(),
Expand Down Expand Up @@ -105,7 +110,8 @@ def _get_campuses_by_schedule(schedule):
"""
campuses = {"seattle": False,
"bothell": False,
"tacoma": False}
"tacoma": False,
"pce": False}

if schedule is not None and len(schedule.sections) > 0:
for section in schedule.sections:
Expand All @@ -115,6 +121,8 @@ def _get_campuses_by_schedule(schedule):
campuses["bothell"] = True
elif section.course_campus == "Tacoma":
campuses["tacoma"] = True
elif section.course_campus == "PCE":
campuses["pce"] = True
else:
pass
return campuses
Expand All @@ -123,14 +131,17 @@ def _get_campuses_by_schedule(schedule):
def _get_official_campuses(campuses):
official_campuses = {'official_seattle': False,
'official_bothell': False,
'official_tacoma': False}
'official_tacoma': False,
'official_pce': False}
for campus in campuses:
if campus.lower() == "seattle":
official_campuses['official_seattle'] = True
if campus.lower() == "tacoma":
official_campuses['official_tacoma'] = True
if campus.lower() == "bothell":
official_campuses['official_bothell'] = True
if campus.lower() == "pce":
official_campuses['official_pce'] = True
return official_campuses


Expand All @@ -148,6 +159,8 @@ def get_base_campus(request):
campus = "bothell"
if affiliations["official_tacoma"]:
campus = "tacoma"
if affiliations["official_pce"]:
campus = "pce"
except KeyError:
try:
if affiliations["seattle"]:
Expand Down Expand Up @@ -189,6 +202,7 @@ def generated(request):
request_cached_is_pce_student = _build_cache_method("pce_student",
is_pce_student)


request_cached_is_student_employee = _build_cache_method("student_employee",
is_student_employee)

Expand All @@ -197,6 +211,10 @@ def generated(request):
is_employee)


request_cached_is_staff_employee = _build_cache_method("staff_employee",
is_staff_employee)


request_cached_is_faculty = _build_cache_method("faculty",
is_faculty)

Expand All @@ -217,16 +235,64 @@ def wrapped_is_clinician(request):
return is_clinician()


def wrapped_is_instructor(request):
return is_instructor(request)


def affiliation_prefetch():
return [request_cached_is_grad_student,
request_cached_is_undergrad,
request_cached_is_student,
request_cached_is_pce_student,
request_cached_is_student_employee,
request_cached_is_staff_employee,
request_cached_is_employee,
request_cached_is_faculty,
wrapped_is_seattle,
wrapped_is_tacoma,
wrapped_is_bothell,
wrapped_is_clinician,
wrapped_is_instructor,
]


def get_identity_log_str(request):
"""
Return "(Affiliations: <affiliations>, <campus codes>)"
"""
res = "(Affiliations:"
no_affiliation_lengthmark = len(res)
affi = get_all_affiliations(request)
if affi["grad"]:
res += ' Grad'
if affi["undergrad"]:
res += ' Undergrad'
if affi["pce"]:
res += ' PCE-student'
if affi["faculty"]:
res += ' Faculty'
if affi["staff_employee"]:
res += ' Staff'
if affi["instructor"]:
res += ' Instructor'
if affi["clinician"]:
res += 'Clinician'
if affi["employee"]:
res += ' Employee'
if len(res) == no_affiliation_lengthmark:
res += 'None'

res += ', Campuses:'
no_campus_lengthmark = len(res)
if affi["seattle"] or affi["official_seattle"]:
res += ' Seattle'
if affi["bothell"] or affi["official_bothell"]:
res += ' Bothell'
if affi["tacoma"] or affi["official_tacoma"]:
res += ' Tacoma'
if affi["official_pce"]:
res += ' PCE'
if len(res) == no_campus_lengthmark:
res += 'None'
res += ') '
return res
2 changes: 1 addition & 1 deletion myuw/dao/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.conf import settings
from django.utils import timezone
from restclients_core.exceptions import DataFailureException
from restclients.trumba import get_calendar_by_name
from uw_trumba import get_calendar_by_name
from myuw.dao.term import get_comparison_date
from myuw.dao.calendar_mapping import get_calendars_for_current_user

Expand Down
4 changes: 2 additions & 2 deletions myuw/dao/canvas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from restclients.canvas.enrollments import Enrollments
from restclients.canvas.courses import Courses
from uw_canvas.enrollments import Enrollments
from uw_canvas.courses import Courses
from restclients_core.exceptions import DataFailureException
from myuw.dao.pws import get_regid_of_current_user
from myuw.dao.exceptions import CanvasNonSWSException
Expand Down
8 changes: 6 additions & 2 deletions myuw/dao/category_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,12 @@ def _get_links_by_category_and_campus(search_category_id,
continue

if link.campus_matched(campus) and\
affiliations["undergrad"] and\
(link.for_undergrad() or link.for_fyp()):
affiliations["undergrad"] and link.for_undergrad():
selected_links.append(link)
continue

if link.campus_matched(campus) and\
affiliations["fyp"] and link.for_fyp():
selected_links.append(link)
continue

Expand Down
28 changes: 19 additions & 9 deletions myuw/dao/class_website.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,24 @@
import logging
from urlparse import urlparse
from BeautifulSoup import BeautifulSoup
from restclients.dao_implementation.live import get_con_pool, get_live_url
from restclients.dao_implementation.mock import get_mockdata_url
from restclients.exceptions import DataFailureException
from restclients_core.exceptions import DataFailureException
from myuw.dao import is_using_file_dao
from restclients_core.dao import DAO
from os.path import abspath, dirname
import os
import re

logger = logging.getLogger(__name__)


class CLASS_WEBSITE_DAO(DAO):
def service_name(self):
return "www"

def service_mock_paths(self):
return [abspath(os.path.join(dirname(__file__), "resources"))]


def _fetch_url(method, url):
try:
p = urlparse(url)
Expand All @@ -22,13 +31,14 @@ def _fetch_url(method, url):
return None

headers = {'ACCEPT': 'text/html'}
if is_using_file_dao():
response = get_mockdata_url(
'www', 'file', "/%s%s" % (p.netloc, p.path), headers)
dao = CLASS_WEBSITE_DAO()

if dao.get_implementation().is_live():
url = "%s://%s" % (p.scheme, p.netloc)
else:
pool = get_con_pool("%s://%s" % (p.scheme, p.netloc), socket_timeout=2)
response = get_live_url(
pool, method, p.hostname, url, headers)
url = "/%s%s" % (p.netloc, p.path)

response = dao.getURL(url, headers)

if response.status != 200:
raise DataFailureException(url, response.status, response.data)
Expand Down
20 changes: 13 additions & 7 deletions myuw/dao/enrollment.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from myuw.dao import is_using_file_dao
from myuw.dao.pws import get_regid_of_current_user
from myuw.dao.term import (get_current_quarter,
get_prev_num_terms,
get_current_and_next_quarters,
get_previous_number_quarters,
get_comparison_date)
from restclients_core.exceptions import DataFailureException
from myuw.dao.exceptions import IndeterminateCampusException
Expand Down Expand Up @@ -73,22 +74,27 @@ def get_prev_enrollments_with_open_sections(request, num_of_prev_terms):
:return: the dictionary of {Term: Enrollment} of the given
number of previous terms with unfinished sections
"""
terms = get_prev_num_terms(request, num_of_prev_terms)
terms = get_previous_number_quarters(request, num_of_prev_terms)
result_dict = get_enrollments_of_terms(terms)
return remove_finished(request, result_dict)


def get_main_campus(request):
campuses = []
try:
enrollment = get_current_quarter_enrollment(request)
for major in enrollment.majors:
campuses.append(major.campus)
result_dict = get_enrollments_of_terms(
get_current_and_next_quarters(request, 2))

for term in result_dict.keys():
enrollment = result_dict.get(term)
for major in enrollment.majors:
if major.campus and major.campus not in campuses:
campuses.append(major.campus)
except DataFailureException as ex:
logger.error("get_current_quarter_enrollment: %s" % ex)
logger.error("get_main_campus: %s" % ex)
raise IndeterminateCampusException()
except Exception as ex:
logger.error("get_current_quarter_enrollment: %s" % ex)
logger.error("get_main_campus: %s" % ex)
pass

return campuses
Expand Down
8 changes: 4 additions & 4 deletions myuw/dao/grad.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

import logging
from datetime import date, datetime, timedelta
from restclients.grad.degree import get_degree_by_regid
from restclients.grad.committee import get_committee_by_regid
from restclients.grad.leave import get_leave_by_regid
from restclients.grad.petition import get_petition_by_regid
from uw_grad.degree import get_degree_by_regid
from uw_grad.committee import get_committee_by_regid
from uw_grad.leave import get_leave_by_regid
from uw_grad.petition import get_petition_by_regid
from myuw.logger.logback import log_exception
from myuw.dao.pws import get_regid_of_current_user
from myuw.dao.gws import is_grad_student
Expand Down
2 changes: 1 addition & 1 deletion myuw/dao/hfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

def get_account_balances_by_uwnetid(uwnetid):
"""
returns restclients.models.hfs.HfsAccouts
returns uw_hfs.models.HfsAccouts
for the given uwnetid
"""
if uwnetid is None:
Expand Down
16 changes: 15 additions & 1 deletion myuw/dao/iasystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.utils import timezone
from uw_pws import PWS
from restclients_core.exceptions import DataFailureException
from restclients.iasystem import evaluation
from uw_iasystem import evaluation
from myuw.logger.logback import log_exception
from myuw.dao.student_profile import get_profile_of_current_user
from myuw.dao.term import get_comparison_datetime, is_b_term,\
Expand All @@ -35,6 +35,17 @@ def _get_evaluations_by_section_and_student(section, student_number):
**search_params)


def get_evaluation_by_section_and_instructor(section, instructor_id):
search_params = {'year': section.term.year,
'term_name': section.term.quarter.capitalize(),
'curriculum_abbreviation': section.curriculum_abbr,
'course_number': section.course_number,
'section_id': section.section_id,
'instructor_id': instructor_id}
return evaluation.search_evaluations(section.course_campus.lower(),
**search_params)


def summer_term_overlaped(request, given_section):
"""
@return true if:
Expand Down Expand Up @@ -102,6 +113,9 @@ def json_for_evaluation(request, evaluations, section):
json_data = []
for evaluation in evaluations:

if not evaluation.is_online():
continue

if summer_term_overlaped(request, section):

logger.debug(
Expand Down
Loading

0 comments on commit 13fbbda

Please sign in to comment.