3
3
from typing import Union , List , Dict , Tuple
4
4
5
5
from dateutil .parser import parse as date_parse , ParserError
6
- from sqlalchemy import or_ , and_
6
+ from sqlalchemy import or_
7
7
8
8
from anubis .models import (
9
9
db ,
25
25
from anubis .utils .services .logger import logger
26
26
27
27
28
- @cache .memoize (timeout = 5 , unless = is_debug )
28
+ @cache .memoize (timeout = 60 , unless = is_debug )
29
29
def get_courses (netid : str ):
30
30
"""
31
31
Get all classes a given netid is in
@@ -122,48 +122,6 @@ def get_assignments(netid: str, course_id=None) -> Union[List[Dict[str, str]], N
122
122
return response
123
123
124
124
125
- @cache .memoize (timeout = 3 , unless = is_debug )
126
- def get_submissions (
127
- user_id = None , course_id = None , assignment_id = None
128
- ) -> Union [List [Dict [str , str ]], None ]:
129
- """
130
- Get all submissions for a given netid. Cache the results. Optionally specify
131
- a class_name and / or assignment_name for additional filtering.
132
-
133
- :param user_id:
134
- :param course_id:
135
- :param assignment_id: id of assignment
136
- :return:
137
- """
138
-
139
- # Load user
140
- owner = User .query .filter (User .id == user_id ).first ()
141
-
142
- # Verify user exists
143
- if owner is None :
144
- return None
145
-
146
- # Build filters
147
- filters = []
148
- if course_id is not None and course_id != "" :
149
- filters .append (Course .id == course_id )
150
- if user_id is not None and user_id != "" :
151
- filters .append (User .id == user_id )
152
- if assignment_id is not None :
153
- filters .append (Assignment .id == assignment_id )
154
-
155
- submissions = (
156
- Submission .query .join (Assignment )
157
- .join (Course )
158
- .join (InCourse )
159
- .join (User )
160
- .filter (Submission .owner_id == owner .id , * filters )
161
- .all ()
162
- )
163
-
164
- return [s .full_data for s in submissions ]
165
-
166
-
167
125
def assignment_sync (assignment_data : dict ) -> Tuple [Union [dict , str ], bool ]:
168
126
"""
169
127
Take an assignment_data dictionary from a assignment meta.yaml
@@ -181,24 +139,24 @@ def assignment_sync(assignment_data: dict) -> Tuple[Union[dict, str], bool]:
181
139
182
140
# Attempt to find the class
183
141
course_name = assignment_data .get ('class' , None ) or assignment_data .get ('course' , None )
184
- c : Course = Course .query .filter (
142
+ course : Course = Course .query .filter (
185
143
or_ (
186
144
Course .name == course_name ,
187
145
Course .course_code == course_name ,
188
146
)
189
147
).first ()
190
- if c is None :
148
+ if course is None :
191
149
return "Unable to find class" , False
192
150
193
- assert_course_admin (c .id )
151
+ assert_course_admin (course .id )
194
152
195
153
# Check if it exists
196
154
if assignment is None :
197
155
assignment = Assignment (
198
- theia_image = c .theia_default_image ,
199
- theia_options = c .theia_default_options ,
156
+ theia_image = course .theia_default_image ,
157
+ theia_options = course .theia_default_options ,
200
158
unique_code = assignment_data ["unique_code" ],
201
- course = c ,
159
+ course = course ,
202
160
)
203
161
204
162
# Update fields
@@ -220,10 +178,8 @@ def assignment_sync(assignment_data: dict) -> Tuple[Union[dict, str], bool]:
220
178
# Go through assignment tests, and delete those that are now
221
179
# not in the assignment data.
222
180
for assignment_test in AssignmentTest .query .filter (
223
- and_ (
224
- AssignmentTest .assignment_id == assignment .id ,
225
- AssignmentTest .name .notin_ (assignment_data ["tests" ]),
226
- )
181
+ AssignmentTest .assignment_id == assignment .id ,
182
+ AssignmentTest .name .notin_ (assignment_data ["tests" ]),
227
183
).all ():
228
184
# Delete any and all submission test results that are still outstanding
229
185
# for an assignment test that will be deleted.
@@ -257,7 +213,7 @@ def assignment_sync(assignment_data: dict) -> Tuple[Union[dict, str], bool]:
257
213
258
214
# Sync the questions in the assignment data
259
215
question_message = None
260
- if 'questions' in assignment_data :
216
+ if 'questions' in assignment_data and isinstance ( assignment_data [ 'questions' ], list ) :
261
217
accepted , ignored , rejected = ingest_questions (
262
218
assignment_data ["questions" ], assignment
263
219
)
@@ -266,3 +222,5 @@ def assignment_sync(assignment_data: dict) -> Tuple[Union[dict, str], bool]:
266
222
db .session .commit ()
267
223
268
224
return {"assignment" : assignment .data , "questions" : question_message }, True
225
+
226
+
0 commit comments