88#
99# Standard library
1010# ----------------
11-
11+ import json
12+ import datetime
1213
1314# Third-party imports
1415# -------------------
15- from fastapi import APIRouter , Request , Depends
16+ from typing import Optional
17+ from fastapi import APIRouter , Cookie , Request , Depends
1618from fastapi .templating import Jinja2Templates
1719
1820# Local application imports
3335 fetch_lti_version ,
3436)
3537from rsptx .logging import rslogger
36- from rsptx .response_helpers .core import make_json_response
38+ from rsptx .response_helpers .core import canonical_utcnow , make_json_response
3739from rsptx .auth .session import is_instructor
3840from rsptx .grading_helpers .core import adjust_deadlines
3941
5254
5355
5456@router .api_route ("/index" , methods = ["GET" , "POST" ])
55- async def index (request : Request , user = Depends (auth_manager )):
57+ async def index (
58+ request : Request , user = Depends (auth_manager ), RS_info : Optional [str ] = Cookie (None )
59+ ):
5660 """Fetch current course information
5761 Fetch current assignment information
5862
@@ -93,7 +97,29 @@ async def index(request: Request, user=Depends(auth_manager)):
9397 if not user_is_instructor :
9498 assignments = [a for a in assignments if a .visible or a .id in assignment_ids ]
9599 assignments = adjust_deadlines (assignments , accommodations )
96- assignments .sort (key = lambda x : x .duedate , reverse = True )
100+
101+ parsed_js = json .loads (RS_info ) if RS_info else {}
102+ timezoneoffset = parsed_js .get ("tz_offset" , None )
103+
104+ def sort_key (assignment ):
105+ deadline = assignment .duedate
106+ if timezoneoffset :
107+ deadline = deadline + datetime .timedelta (hours = float (timezoneoffset ))
108+ return (
109+ deadline < canonical_utcnow (),
110+ abs ((deadline - canonical_utcnow ()).total_seconds ()),
111+ )
112+ else :
113+ return (
114+ assignment .duedate < canonical_utcnow (),
115+ abs ((assignment .duedate - canonical_utcnow ()).total_seconds ()),
116+ )
117+
118+ now = canonical_utcnow ()
119+ assignments .sort (
120+ key = sort_key
121+ )
122+
97123 stats_list = await fetch_all_assignment_stats (course_name , user .id )
98124 stats = {}
99125 for s in stats_list :
@@ -117,6 +143,7 @@ async def index(request: Request, user=Depends(auth_manager)):
117143 "is_instructor" : user_is_instructor ,
118144 "has_discussion_group" : any ([book .social_url for book in books ]),
119145 "lti1p1" : is_lti1p1_course ,
146+ "now" : now ,
120147 },
121148 )
122149
0 commit comments