Compare commits

...

3 Commits

3 changed files with 21 additions and 34 deletions

View File

@ -1,4 +1,5 @@
import sys
import traceback
from django.views.debug import ExceptionReporter
from django.core import mail
@ -9,12 +10,15 @@ class AdminEmailReporter:
pass
def report(self):
reporter = ExceptionReporter(None, *sys.exc_info())
message = f"Failed to run task\n{reporter.get_traceback_text()}"
html_message = reporter.get_traceback_html()
mail.mail_admins(
"Django Q task failed",
message,
# fail_silently=True,
html_message=html_message,
)
try:
reporter = ExceptionReporter(None, *sys.exc_info())
message = f"Failed to run task\n{reporter.get_traceback_text()}"
html_message = reporter.get_traceback_html()
mail.mail_admins(
"Django Q task failed",
message,
# fail_silently=True,
html_message=html_message,
)
except Exception:
print(traceback.format_exc())

View File

@ -415,13 +415,7 @@ class EventInstructor(models.Model):
class EventExtManager(models.Manager["EventExt"]):
def get_queryset(self) -> models.QuerySet["EventExt"]:
return (
super()
.get_queryset()
.annotate(duration=Sum(F("meeting_times__end") - F("meeting_times__start")))
)
# TODO: use simpler expression when GeneratedField fixed
# return super().get_queryset().annotate(duration=Sum("meeting_times__duration"))
return super().get_queryset().annotate(duration=Sum("meeting_times__duration"))
class EventExt(Event):
@ -446,29 +440,18 @@ class EventExt(Event):
verbose_name = "event"
class EventMeetingTimeManager(models.Manager["EventMeetingTime"]):
def get_queryset(self) -> models.QuerySet["EventMeetingTime"]:
return super().get_queryset().annotate(duration=F("end") - F("start"))
class EventMeetingTime(models.Model):
objects = EventMeetingTimeManager()
event = models.ForeignKey(
EventExt, on_delete=models.CASCADE, related_name="meeting_times"
)
start = models.DateTimeField()
end = models.DateTimeField()
# TODO: Should use generated field instead of manager, but this is
# broken due to current Django bug, pending next release (> 5.0)
# ref: https://code.djangoproject.com/ticket/35019
# duration = models.GeneratedField(
# expression=F("end") - F("start"),
# output_field=models.DurationField(),
# db_persist=False,
# )
duration = models.GeneratedField(
expression=F("end") - F("start"),
output_field=models.DurationField(),
db_persist=False,
)
class Meta:
constraints = [

View File

@ -22,7 +22,7 @@ GROUPS_REGEX = "|".join(
# A group name must start and end with a letter, number or underscore.
# In between additionally spaces, dashes and dots are allowed.
def sanitize_group_name(name):
sanitized_body = re.sub(r"[^0-9A-Za-z_ -.]", ".", name)
sanitized_body = re.sub(r"[^0-9A-Za-z_ -.]+", ".", name)
sanitized_start_end = re.sub("^[^0-9A-Za-z_]|[^0-9A-Za-z_]$", "_", sanitized_body)
return "MW_" + sanitized_start_end
@ -30,7 +30,7 @@ def sanitize_group_name(name):
# From an API error message: "Username must only contain numbers, letters and dots!"
def sanitize_user_name(name):
return re.sub(r"[^0-9a-z.]", ".", name.lower()).strip(".")
return re.sub(r"[^0-9a-z.]+", ".", name.lower()).strip(".")
async def make_groups(udm):