diff --git a/compair/api/assignment_search_enddate.py b/compair/api/assignment_search_enddate.py index 4c3222b16..e9b50f401 100644 --- a/compair/api/assignment_search_enddate.py +++ b/compair/api/assignment_search_enddate.py @@ -6,7 +6,6 @@ from flask import jsonify import pytz - from bouncer.constants import READ, EDIT, CREATE, DELETE, MANAGE from flask import Blueprint, current_app from flask_bouncer import can @@ -26,13 +25,11 @@ from .util import new_restful_api, get_model_changes, pagination_parser from datetime import datetime +import time assignment_search_enddate_api = Blueprint('assignment_search_enddate_api', __name__) api = new_restful_api(assignment_search_enddate_api) -##event -on_assignment_get = event.signal('ASSIGNMENT_GET') - def validate(date_text): try: if date_text != datetime.strptime(date_text, "%Y-%m-%d").strftime('%Y-%m-%d'): @@ -45,16 +42,19 @@ class AssignmentRootAPI1(Resource): @login_required def get(self): + # get app timezone in settings + appTimeZone = current_app.config.get('APP_TIMEZONE', time.strftime('%Z') ) + search_date_assignment_parser = RequestParser() search_date_assignment_parser.add_argument('compare_start', default=datetime.now().strftime("%Y-%m-%d")) search_date_assignment_parser.add_argument('compare_end', default=datetime.now().strftime("%Y-%m-%d")) - search_date_assignment_parser.add_argument('compare_localTimeZone', default='UTC') + search_date_assignment_parser.add_argument('compare_localTimeZone', default=appTimeZone) args = search_date_assignment_parser.parse_args() end_date = datetime.now().strftime("%Y-%m-%d 00:00:00") start_date = datetime.now().strftime("%Y-%m-%d") - compare_localTimeZone = 'UTC' + compare_localTimeZone = appTimeZone if (args['compare_localTimeZone']): compare_localTimeZone = str(args['compare_localTimeZone']) @@ -62,12 +62,12 @@ def get(self): if validate(args['compare_end']): end_date = str(args['compare_end']) + ' 00:00:00' - ##convert this to UTC + ##convert this to System TZ local = pytz.timezone(compare_localTimeZone) naive = datetime.strptime(end_date, "%Y-%m-%d %H:%M:%S") local_dt = local.localize(naive, is_dst=None) - utc_dt = local_dt.astimezone(pytz.utc) - end_date = str(utc_dt) + systemTZ_dt = local_dt.astimezone(pytz.timezone(appTimeZone)) + end_date = str(systemTZ_dt) if validate(args['compare_start']): start_date = str(args['compare_start']) @@ -76,7 +76,7 @@ def get(self): engine = create_engine(db_url, pool_size=5, pool_recycle=3600) conn = engine.connect() - sql_text = str("SELECT JSON_OBJECT('course_name', t1.name,'name', t2.name,'answer_start', date_format(t2.answer_start, '%%M %%d, %%Y'),'answer_end', date_format(t2.answer_end, '%%M %%d, %%Y'),'compare_start', date_format(t2.compare_start, '%%M %%d, %%Y'), 'compare_end', date_format(t2.compare_end, '%%M %%d, %%Y'), 'self_eval_end', date_format(t2.self_eval_end, '%%M %%d, %%Y'), 'self_eval_start', date_format(t2.self_eval_start, '%%M %%d, %%Y')) FROM course as t1, assignment as t2 WHERE (t1.id = t2.course_id) AND (t2.active=TRUE AND t1.active=TRUE) AND (t2.compare_end >= '" + end_date + "' OR answer_end >= '" + end_date + "' OR self_eval_end >= '" + end_date + "');"); + sql_text = str("SELECT JSON_OBJECT('course_name', t1.name,'name', t2.name,'answer_start', date_format(CONVERT_TZ(t2.answer_start, '" + appTimeZone + "','" + compare_localTimeZone + "'), '%%b %%d, %%Y'),'answer_end', date_format(CONVERT_TZ(t2.answer_end, '" + appTimeZone + "','" + compare_localTimeZone + "'), '%%b %%d, %%Y'),'compare_start', date_format(CONVERT_TZ(t2.compare_start, '" + appTimeZone + "','" + compare_localTimeZone + "'), '%%b %%d, %%Y'), 'compare_end', date_format(CONVERT_TZ(t2.compare_end, '" + appTimeZone + "','" + compare_localTimeZone + "'), '%%b %%d, %%Y'), 'self_eval_end', date_format(CONVERT_TZ(t2.self_eval_end, '" + appTimeZone + "','" + compare_localTimeZone + "'), '%%b %%d, %%Y'), 'self_eval_start', date_format(CONVERT_TZ(t2.self_eval_start, '" + appTimeZone + "','" + compare_localTimeZone + "'), '%%b %%d, %%Y')) FROM course as t1, assignment as t2 WHERE (t1.id = t2.course_id) AND (t2.active=TRUE AND t1.active=TRUE) AND (t2.compare_end >= '" + end_date + "' OR answer_end >= '" + end_date + "' OR self_eval_end >= '" + end_date + "');"); result = conn.execute(sql_text) diff --git a/compair/configuration.py b/compair/configuration.py index 41b471014..65071b0ef 100644 --- a/compair/configuration.py +++ b/compair/configuration.py @@ -23,6 +23,8 @@ import os import json import re +import pytz +import time from distutils.util import strtobool from flask import Config @@ -91,7 +93,7 @@ 'KALTURA_SECRET', 'KALTURA_PLAYER_ID', 'MAIL_SERVER', 'MAIL_DEBUG', 'MAIL_USERNAME', 'MAIL_PASSWORD', 'MAIL_DEFAULT_SENDER', 'MAIL_SUPPRESS_SEND', - 'GA_TRACKING_ID' + 'GA_TRACKING_ID', 'APP_TIMEZONE' ] env_bool_overridables = [ @@ -150,3 +152,7 @@ config['APP_LOGIN_ENABLED'] = True config['CAS_LOGIN_ENABLED'] = False config['SAML_LOGIN_ENABLED'] = False + +# configuring APP_TIMEZONE +if not(config['APP_TIMEZONE'] in pytz.all_timezones): + config['APP_TIMEZONE'] = time.strftime('%Z') diff --git a/compair/settings.py b/compair/settings.py index 8daf60594..3cd055ffb 100644 --- a/compair/settings.py +++ b/compair/settings.py @@ -1,5 +1,5 @@ import os - +import time """ Default settings, if no other settings is specified, values here are used. """ @@ -163,3 +163,7 @@ # Allow impersonation IMPERSONATION_ENABLED = True + +# when APP_TIMEZONE is empty or incorrect, it will default to system timezone +# example America/Vancouver or America/Montreal +APP_TIMEZONE = time.strftime('%Z') diff --git a/compair/static/modules/assignment/assignment-search-partial.html b/compair/static/modules/assignment/assignment-search-partial.html index e25b8d979..cd62d63ed 100644 --- a/compair/static/modules/assignment/assignment-search-partial.html +++ b/compair/static/modules/assignment/assignment-search-partial.html @@ -12,7 +12,7 @@