Skip to content

Commit

Permalink
Merge pull request #183 from uw-it-aca/qa
Browse files Browse the repository at this point in the history
Qa
  • Loading branch information
fanglinfang committed Aug 27, 2015
2 parents 1a0e3c6 + 1e2eb08 commit 35056e7
Show file tree
Hide file tree
Showing 33 changed files with 1,711 additions and 395 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ notifications:
webhooks:
urls:
- https://yarn.cac.washington.edu/rest/botalyst/v1/travis-ci
sudo: false
sudo: false
28 changes: 11 additions & 17 deletions myuw_mobile/dao/card_display_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@
from django.conf import settings
from datetime import datetime, timedelta
from myuw_mobile.dao.term import get_comparison_date,\
is_in_summer_b_term, is_summer_term,\
get_current_quarter, get_next_quarter,\
get_term_after, get_term_before, get_bof_1st_instruction,\
get_term_after, get_last_term, get_bof_1st_instruction,\
get_eof_last_instruction, get_bof_7d_before_last_instruction,\
get_eof_7d_after_class_start, get_eof_last_final_exam


def in_show_grades_period(term, request):
"""
return true if it is within the grades display window -
before the 1st day of next quarter
"""
comparison_date = get_comparison_date(request)
next_term = get_term_after(term)
if comparison_date < next_term.first_day_quarter:
return True

return False
return comparison_date < next_term.first_day_quarter


def get_card_visibilty_date_values(request=None):
Expand All @@ -35,15 +37,7 @@ def get_values_by_date(now, request):
"""
now is a datetime object of 1 second after the beginning of the day.
"""
current_term = get_current_quarter(request)
last_term = get_term_before(current_term)

is_summer = False
is_after_summer_b = False
if current_term.quarter == "summer":
is_summer = True
if get_comparison_date(request) >= current_term.bterm_first_date:
is_after_summer_b = True
last_term = get_last_term(request)

return {
"is_after_7d_before_last_instruction":
Expand Down Expand Up @@ -72,10 +66,10 @@ def get_values_by_date(now, request):
is_before_bof_term(now, request),
"is_before_last_day_of_classes":
is_before_last_day_of_classes(now, request),
"last_term": "%s,%s" % (last_term.year, last_term.quarter),
"is_summer": is_summer,
"is_after_summer_b": is_after_summer_b,
"is_summer": is_summer_term(request),
"is_after_summer_b": is_in_summer_b_term(request),
"current_summer_term": "%s,%s" % (last_term.year, "summer"),
"last_term": "%s,%s" % (last_term.year, last_term.quarter),
}


Expand Down
8 changes: 4 additions & 4 deletions myuw_mobile/dao/notice_categorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,22 +486,22 @@
"location_tags": ['tuition_acceptreject_title'],
"critical": False
},
"StudentFinAid_DisbursDateA": {
"StudentFinAid_DisburseDateA": {
"myuw_category": "Fees & Finances",
"location_tags": ['tuition_disbursedateA', 'notices_date_sort'],
"critical": True
},
"StudentFinAid_DisbursDateAShort": {
"StudentFinAid_DisburseDateAShort": {
"myuw_category": "Fees & Finances",
"location_tags": ['tuition_disbursedateA_title'],
"critical": False
},
"StudentFinAid_DisbursDateB": {
"StudentFinAid_DisburseDateB": {
"myuw_category": "Fees & Finances",
"location_tags": ['tuition_disbursedateB', 'notices_date_sort'],
"critical": True
},
"StudentFinAid_DisbursDateBShort": {
"StudentFinAid_DisburseDateBShort": {
"myuw_category": "Fees & Finances",
"location_tags": ['tuition_disbursedateB_title'],
"critical": False
Expand Down
113 changes: 112 additions & 1 deletion myuw_mobile/dao/notice_mapping.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
"""
This module categorize notices based on notice_categorization
This module provides utility the following functions:
1. categorize notices based on the dictionary defined
in notice_categorization.py;
2. apply show/hide on notices besed on their category and timing;
3. convert notice object into json format
"""
import logging
import pytz
from datetime import datetime, timedelta
from django.utils import timezone
from myuw_mobile.dao.notice_categorization import NOTICE_CATEGORIES
from myuw_mobile.dao.term import get_comparison_date


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -37,3 +45,106 @@ def map_notice_category(notice):
notice.is_critical = False
notice.location_tags = None
return notice


def equals_myuwid(notice, value):
myuw_id = notice.notice_category + "_" + notice.notice_type
return myuw_id == value


def apply_showhide(request, notices):
"""
Some financial aid notices have additional show/hide logic
depending on the open/close dates of the notice.
This function will apply the show/hide logic on each notice,
update the notice atttibutes accordingly.
"""
if notices is None:
return None
today = get_comparison_date(request)
local_tz = timezone.get_current_timezone()
now = local_tz.localize(
datetime(today.year,
today.month,
today.day, 0, 0, 1)).astimezone(pytz.utc)
for notice in notices:
if notice.notice_category != "StudentFinAid":
continue

if equals_myuwid(notice, "StudentFinAid_AidPriorityDate"):
# not critical after the first week and
# before last two weeks
if is_after_eof_days_after_open(now, notice, 15) and\
is_before_bof_days_before_close(now, notice, 15):
notice.is_critical = False
return notices


def get_open_date(notice):
"""
@return the datetime object of the notice begin date value
in utc timezone
"""
for attribute in notice.attributes:
if attribute.data_type == "date" and\
attribute.name.endswith("Begin"):
return attribute._date_value


def get_close_date(notice):
"""
@return the datetime object of the notice end date value
in utc timezone
"""
for attribute in notice.attributes:
if attribute.data_type == "date" and\
attribute.name.endswith("End"):
return attribute._date_value


def is_after_eof_days_after_open(now, notice, n_days):
"""
@return true if it is after "n_days" after the notice open datetime
"""
return now > get_open_date(notice) + timedelta(days=n_days)


def is_before_bof_days_before_close(now, notice, n_days):
"""
@return true if it is before "n_days" prior to the notice close datetime
"""
return now < get_close_date(notice) - timedelta(days=n_days)


def get_json_for_notices(request, notices):
"""
@return the json data of notices with the specific show/hide logic
applied on the corresponding notices.
"""
notice_json = []

for notice in apply_showhide(request, notices):

if notice.notice_category == "StudentFinAid" and\
notice.notice_type.endswith("Short") and\
notice.long_notice is not None:
data = notice.long_notice.json_data(
include_abbr_week_month_day_format=True)
data['short_content'] = notice.notice_content
data['category'] = notice.custom_category
data['is_critical'] = False
data['id_hash'] = notice.id_hash
data['is_read'] = notice.is_read
data['location_tags'] = notice.location_tags

else:
data = notice.json_data(
include_abbr_week_month_day_format=True)
data['category'] = notice.custom_category
data['sws_category'] = notice.notice_category
data['is_critical'] = notice.is_critical
data['id_hash'] = notice.id_hash
data['is_read'] = notice.is_read
data['location_tags'] = notice.location_tags
notice_json.append(data)
return notice_json
Loading

0 comments on commit 35056e7

Please sign in to comment.