Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions course_management/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from pathlib import Path

import dj_database_url
from django.templatetags.static import static
from django.utils.translation import gettext_lazy as _


Expand All @@ -35,13 +34,10 @@
EXTRA_ALLOWED_HOSTS = os.getenv("EXTRA_ALLOWED_HOSTS", "")
extra_allowed_hosts_parsed = EXTRA_ALLOWED_HOSTS.split(",")

ALLOWED_HOSTS = [
"localhost",
"127.0.0.1"
] + extra_allowed_hosts_parsed
ALLOWED_HOSTS = ["localhost", "127.0.0.1"] + extra_allowed_hosts_parsed

IS_LOCAL = os.getenv("IS_LOCAL", "0") == "1"
print(f'IS_LOCAL={IS_LOCAL}')
print(f"IS_LOCAL={IS_LOCAL}")

CSRF_TRUSTED_ORIGINS = []

Expand All @@ -62,17 +58,14 @@
"django.contrib.staticfiles",
"django.contrib.sites",
"loginas",

"accounts.apps.AccountsConfig",
"courses.apps.CoursesConfig",

"allauth",
"allauth.account",
"allauth.socialaccount",
"allauth.socialaccount.providers.google",
"allauth.socialaccount.providers.github",
"allauth.socialaccount.providers.slack",

]

MIDDLEWARE = [
Expand Down Expand Up @@ -215,12 +208,10 @@
"disable_existing_loggers": False,
"formatters": {
"json": {
"()": "pythonjsonlogger.jsonlogger.JsonFormatter",
"()": "pythonjsonlogger.json.JsonFormatter",
"format": "%(asctime)s %(levelname)s %(name)s %(message)s",
},
"simple": {
"format": "%(levelname)s %(message)s"
},
"simple": {"format": "%(levelname)s %(message)s"},
},
"handlers": {
"console": {
Expand Down Expand Up @@ -320,4 +311,7 @@
"SITE_HEADER": _("Course Management"),
"SITE_TITLE": _("Course Management"),
"SITE_SYMBOL": "school",
}
}

# Fix Django 6.0 URLField deprecation warning
FORMS_URLFIELD_ASSUME_HTTPS = True
21 changes: 14 additions & 7 deletions courses/models/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ class Meta:
enrollment_date = models.DateTimeField(auto_now_add=True)

display_name = models.CharField(
verbose_name="Leaderboard name", max_length=255, blank=True,
help_text="Name on the leaderboard"
verbose_name="Leaderboard name",
max_length=255,
blank=True,
help_text="Name on the leaderboard",
)
display_on_leaderboard = models.BooleanField(default=True)

Expand All @@ -92,7 +94,7 @@ class Meta:
max_length=255,
blank=True,
null=True,
help_text="Your actual name that will appear on your certificate"
help_text="Your actual name that will appear on your certificate",
)

total_score = models.IntegerField(default=0)
Expand Down Expand Up @@ -129,15 +131,20 @@ class Meta:
def save(self, *args, **kwargs):
if not self.display_name:
self.display_name = generate_random_name()

# If certificate_name is being set, update the user's certificate_name
if self.certificate_name and self.certificate_name != self.student.certificate_name:
if (
self.certificate_name
and self.certificate_name != self.student.certificate_name
):
self.student.certificate_name = self.certificate_name
self.student.save()
# If certificate_name is not set but user has one, use the user's certificate_name
elif not self.certificate_name and self.student.certificate_name:
elif (
not self.certificate_name and self.student.certificate_name
):
self.certificate_name = self.student.certificate_name

super().save(*args, **kwargs)

def __str__(self):
Expand Down
Loading