Spaces:
Sleeping
Sleeping
submission_deadline fix
Browse files- assignment_service.py +7 -5
- assignment_ui.py +2 -2
assignment_service.py
CHANGED
@@ -19,10 +19,12 @@ class AssignmentService:
|
|
19 |
return assignment_id
|
20 |
|
21 |
def create_assignment_metadata(self, assignment_type, grade, topic, introduction, description, attach_materials, submission_deadline):
|
22 |
-
# submission_deadline is Unix timestamp (seconds)
|
23 |
-
# convert to ISO format with timezone, example: 2024-06-01T00:00:00+08:00
|
24 |
taipei_tz = pytz.timezone('Asia/Taipei')
|
25 |
-
|
|
|
|
|
|
|
|
|
26 |
|
27 |
metadata = {
|
28 |
"assignment_type": assignment_type,
|
@@ -30,7 +32,7 @@ class AssignmentService:
|
|
30 |
"topic": topic,
|
31 |
"introduction": introduction,
|
32 |
"description": description,
|
33 |
-
"attach_materials": attach_materials,
|
34 |
"submission_deadline": submission_deadline
|
35 |
}
|
36 |
|
@@ -146,7 +148,7 @@ class AssignmentService:
|
|
146 |
if not self.gcs_service.delete_file(self.bucket_name, file_name):
|
147 |
raise Exception("Failed to delete assignment file")
|
148 |
|
149 |
-
#
|
150 |
user_assignments = self.get_user_assignments(user_data)
|
151 |
if assignment_id in user_assignments:
|
152 |
del user_assignments[assignment_id]
|
|
|
19 |
return assignment_id
|
20 |
|
21 |
def create_assignment_metadata(self, assignment_type, grade, topic, introduction, description, attach_materials, submission_deadline):
|
|
|
|
|
22 |
taipei_tz = pytz.timezone('Asia/Taipei')
|
23 |
+
|
24 |
+
if submission_deadline:
|
25 |
+
submission_deadline = datetime.fromtimestamp(submission_deadline, tz=taipei_tz).isoformat()
|
26 |
+
else:
|
27 |
+
submission_deadline = None
|
28 |
|
29 |
metadata = {
|
30 |
"assignment_type": assignment_type,
|
|
|
32 |
"topic": topic,
|
33 |
"introduction": introduction,
|
34 |
"description": description,
|
35 |
+
"attach_materials": attach_materials if attach_materials else None,
|
36 |
"submission_deadline": submission_deadline
|
37 |
}
|
38 |
|
|
|
148 |
if not self.gcs_service.delete_file(self.bucket_name, file_name):
|
149 |
raise Exception("Failed to delete assignment file")
|
150 |
|
151 |
+
# 從用戶的作業列表中刪���
|
152 |
user_assignments = self.get_user_assignments(user_data)
|
153 |
if assignment_id in user_assignments:
|
154 |
del user_assignments[assignment_id]
|
assignment_ui.py
CHANGED
@@ -24,7 +24,7 @@ def create_assignment_ui(user_data, assignment_service, submission_service):
|
|
24 |
with gr.Row():
|
25 |
gr.Markdown("### 繳交規範")
|
26 |
with gr.Row():
|
27 |
-
assignment_submission_deadline = gr.DateTime(label="提交截止日期")
|
28 |
assignment_attach_materials = gr.Textbox(label="附件參考", placeholder='[{"type": "video", "url": "link1", "description": "描述"}]', visible=False)
|
29 |
with gr.Row():
|
30 |
assignment_create_button = gr.Button("建立作業")
|
@@ -131,7 +131,7 @@ def create_assignment_ui(user_data, assignment_service, submission_service):
|
|
131 |
if submission_deadline is not None:
|
132 |
try:
|
133 |
if isinstance(submission_deadline, (int, float)):
|
134 |
-
#
|
135 |
submission_datetime = datetime.fromtimestamp(submission_deadline)
|
136 |
elif isinstance(submission_deadline, str):
|
137 |
# 嘗試解析 ISO 格式的字串
|
|
|
24 |
with gr.Row():
|
25 |
gr.Markdown("### 繳交規範")
|
26 |
with gr.Row():
|
27 |
+
assignment_submission_deadline = gr.DateTime(label="提交截止日期", value=None)
|
28 |
assignment_attach_materials = gr.Textbox(label="附件參考", placeholder='[{"type": "video", "url": "link1", "description": "描述"}]', visible=False)
|
29 |
with gr.Row():
|
30 |
assignment_create_button = gr.Button("建立作業")
|
|
|
131 |
if submission_deadline is not None:
|
132 |
try:
|
133 |
if isinstance(submission_deadline, (int, float)):
|
134 |
+
# 假設這是個 Unix 時間戳(秒)
|
135 |
submission_datetime = datetime.fromtimestamp(submission_deadline)
|
136 |
elif isinstance(submission_deadline, str):
|
137 |
# 嘗試解析 ISO 格式的字串
|