Skip to content

Commit

Permalink
Merge pull request #1029 from ubc/plan-release-date-coursename
Browse files Browse the repository at this point in the history
UPDATE to Plan Release Date tool to search based on UTC timestamp.
  • Loading branch information
ubc-tuehoang authored Jun 24, 2022
2 parents e83c50f + 180402c commit a39142a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
1 change: 1 addition & 0 deletions compair/api/assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def non_blank_text(value):
new_assignment_parser.add_argument('answer_end', required=True, nullable=False)
new_assignment_parser.add_argument('compare_start', default=None)
new_assignment_parser.add_argument('compare_end', default=None)
new_assignment_parser.add_argument('compare_localTimeZone', default='UTC')
new_assignment_parser.add_argument('self_eval_start', default=None)
new_assignment_parser.add_argument('self_eval_end', default=None)
new_assignment_parser.add_argument('self_eval_instructions', type=non_blank_text, default=None)
Expand Down
22 changes: 19 additions & 3 deletions compair/api/assignment_search_enddate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from sqlalchemy import create_engine
import json
from flask import jsonify
import pytz


from bouncer.constants import READ, EDIT, CREATE, DELETE, MANAGE
from flask import Blueprint, current_app
Expand Down Expand Up @@ -46,22 +48,36 @@ def get(self):
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')

args = search_date_assignment_parser.parse_args()

end_date = datetime.now().strftime("%Y-%m-%d")
end_date = datetime.now().strftime("%Y-%m-%d 00:00:00")
start_date = datetime.now().strftime("%Y-%m-%d")
compare_localTimeZone = 'UTC'

if (args['compare_localTimeZone']):
compare_localTimeZone = str(args['compare_localTimeZone'])

if validate(args['compare_end']):
end_date = str(args['compare_end'])
end_date = str(args['compare_end']) + ' 00:00:00'

##convert this to UTC
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)

if validate(args['compare_start']):
start_date = str(args['compare_start'])

db_url = str(current_app.config['SQLALCHEMY_DATABASE_URI'])
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')) FROM course as t1, assignment as t2 WHERE (t1.id = t2.course_id) AND (t2.active=1) AND (t2.compare_end >= '" + end_date + "' OR answer_end >= '" + end_date + "');");
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 (t2.compare_end >= '" + end_date + "' OR answer_end >= '" + end_date + "' OR self_eval_end >= '" + end_date + "');");

result = conn.execute(sql_text)

final_result = [list(i) for i in result]
Expand Down
13 changes: 10 additions & 3 deletions compair/static/script-assignment-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ let api_url = "/api/assignment/search/enddate";
const options = { year: 'numeric', month: 'short', day: 'numeric' };
var searchDay = new Date().toLocaleDateString('en-us', options);

const d = new Date();
let diff = d.getTimezoneOffset();
let localTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;

function formatDate(date) {
var d = (new Date(date.toString().replace(/-/g, '\/')) );
return d.toLocaleDateString('en-ca', options);
Expand All @@ -11,7 +15,9 @@ function formatDate(date) {
function getObjectDate(object)
{
searchDay = formatDate(object);
strURL = api_url.concat('?compare_end=').concat(object);
strURL = api_url.concat('?compare_end=').concat(object).concat('&compare_localTimeZone=').concat(localTimeZone.toString());

console.log(localTimeZone);

getsearchapi(strURL);
}
Expand Down Expand Up @@ -51,15 +57,16 @@ function showsearchapi(search_data) {
for (let key in search_data) {
//tab += `<tr><td colspan="4">${search_data[key]}</td></tr>`;
let obj = JSON.parse(search_data[key])

if (obj.compare_start == null){
obj.compare_start = 'After answering ends';
}

if (obj.compare_end == null){
obj.compare_end = '<i>No end date</i>';
}

//FOR NEXT RELEASE 2 DISPLAY SELF_EVAL_DATES
//tab += `<tr><td>${JSON.stringify(obj.course_name).replace(/\"/g, "")}</td><td>${JSON.stringify(obj.name).replace(/\"/g, "")}</td><td>${JSON.stringify(obj.answer_start).replace(/\"/g, "")}</td><td>${JSON.stringify(obj.answer_end).replace(/\"/g, "")}</td><td>${JSON.stringify(obj.compare_start).replace(/\"/g, "")}</td><td>${JSON.stringify(obj.compare_end).replace(/\"/g, "")}</td><td>${JSON.stringify(obj.self_eval_end).replace(/\"/g, "")}</td></tr>`;
tab += `<tr><td>${JSON.stringify(obj.course_name).replace(/\"/g, "")}</td><td>${JSON.stringify(obj.name).replace(/\"/g, "")}</td><td>${JSON.stringify(obj.answer_start).replace(/\"/g, "")}</td><td>${JSON.stringify(obj.answer_end).replace(/\"/g, "")}</td><td>${JSON.stringify(obj.compare_start).replace(/\"/g, "")}</td><td>${JSON.stringify(obj.compare_end).replace(/\"/g, "")}</td></tr>`;
iKey++;
}
Expand Down

0 comments on commit a39142a

Please sign in to comment.