Verified Commit 8f26714f authored by Peter Stanko's avatar Peter Stanko
Browse files

SubmissionDifftime better message

parent e2ac8aae
......@@ -54,7 +54,6 @@ LOGGERS = {
'management': {'handlers': ['console'], 'level': 'INFO', 'propagate': True},
'app': {'handlers': ['console'], 'level': 'DEBUG', 'propagate': True},
'flask': {'handlers': ['console', 'flask_file'], 'level': 'DEBUG', 'propagate': True},
'flask_cors': {'handlers': ['console'], 'level': 'DEBUG', 'propagate': True},
'werkzeug': {'handlers': ['console'], 'level': 'DEBUG', 'propagate': True},
'storage': {'handlers': ['console', 'storage_file'], 'level': 'INFO', 'propagate': True},
}
......
......@@ -5,6 +5,7 @@ import json
from typing import Union
from portal.database import Project, User
from portal.tools import time
class PortalError(Exception):
......@@ -151,10 +152,20 @@ class WorkerNotAvailable(PortalError):
class SubmissionDiffTimeError(PortalAPIError):
def __init__(self, project: Project, diff_time, user: User = None):
log_user = f'by {user.log_name} ' if user else ''
when = time.current_time() + diff_time
message = f"Submission cannot be created for {project.log_name}, {log_user}" \
f"you can create submission in {diff_time}."
f"you can create submission in {diff_time} (when)."
full_message = {
'text': message,
'log_user': log_user,
'project': project.codename,
'course': project.course.codename,
'author': user.username,
'diff_time': str(diff_time),
'when': when.strftime(time.DEFAULT_FORMAT)
}
super().__init__(code=429, message=message)
super().__init__(code=429, message=full_message)
class SuiteStatsNotExists(PortalError):
......@@ -165,4 +176,4 @@ class SuiteStatsNotExists(PortalError):
class ResultsAreNotUploaded(PortalAPIError):
def __init__(self, submission):
message = f"Submission {submission.log_name} results are not ready."
super().__init__(code=404, message=message)
\ No newline at end of file
super().__init__(code=404, message=message)
......@@ -13,6 +13,8 @@ UTC = pytz.UTC
portal_timezone = pytz.timezone('Europe/Prague')
DEFAULT_FORMAT = "%d-%m-%Y %H:%M:%S."
def current_time() -> datetime:
return datetime.datetime.now(tz=portal_timezone)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment