Fix minor bugs and improve some model fields

This commit is contained in:
cuom1999 2024-08-21 22:42:42 -05:00
parent f98549e92d
commit a42bae51f7
7 changed files with 56 additions and 14 deletions

View file

@ -0,0 +1,32 @@
# Generated by Django 3.2.18 on 2024-08-22 03:12
from django.db import migrations, models
def remove_duplicates(apps, schema_editor):
Room = apps.get_model("chat_box", "Room")
seen = set()
for room in Room.objects.all():
pair = (room.user_one_id, room.user_two_id)
reverse_pair = (room.user_two_id, room.user_one_id)
if pair in seen or reverse_pair in seen:
room.delete()
else:
seen.add(pair)
class Migration(migrations.Migration):
dependencies = [
("chat_box", "0015_room_last_msg_time"),
]
operations = [
migrations.RunPython(remove_duplicates),
migrations.AlterUniqueTogether(
name="room",
unique_together={("user_one", "user_two")},
),
]

View file

@ -24,6 +24,7 @@ class Room(models.Model):
class Meta: class Meta:
app_label = "chat_box" app_label = "chat_box"
unique_together = ("user_one", "user_two")
@cached_property @cached_property
def _cached_info(self): def _cached_info(self):

View file

@ -33,8 +33,6 @@ class OrganizationAdmin(VersionAdmin):
"short_name", "short_name",
"is_open", "is_open",
"about", "about",
"organization_image",
"logo_override_image",
"slots", "slots",
"registrant", "registrant",
"creation_date", "creation_date",

View file

@ -0,0 +1,17 @@
# Generated by Django 3.2.18 on 2024-08-22 03:12
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("judge", "0190_deprecate_old_notif_fields"),
]
operations = [
migrations.RemoveField(
model_name="organization",
name="logo_override_image",
),
]

View file

@ -111,16 +111,6 @@ class Organization(models.Model):
blank=True, blank=True,
) )
organization_image = models.ImageField(upload_to=organization_image_path, null=True) organization_image = models.ImageField(upload_to=organization_image_path, null=True)
logo_override_image = models.CharField(
verbose_name=_("Logo override image"),
default="",
max_length=150,
blank=True,
help_text=_(
"This image will replace the default site logo for users "
"viewing the organization."
),
)
def __contains__(self, item): def __contains__(self, item):
if isinstance(item, int): if isinstance(item, int):

View file

@ -48,8 +48,9 @@ def calculate_lessons_progress(profile, lessons):
num_problems = len(problems) num_problems = len(problems)
percentage = 0 percentage = 0
for val in problem_points.values(): for val in problem_points.values():
score = val["case_points"] / val["case_total"] if val["case_total"] > 0:
percentage += score / num_problems score = val["case_points"] / val["case_total"]
percentage += score / num_problems
res[lesson.id] = { res[lesson.id] = {
"achieved_points": percentage * lesson.points, "achieved_points": percentage * lesson.points,
"percentage": percentage * 100, "percentage": percentage * 100,

View file

@ -538,6 +538,9 @@ function navigateTo(url, reload_container, force_new_page=false) {
$(document).prop('title', $(data).filter('title').text()); $(document).prop('title', $(data).filter('title').text());
renderKatex($(reload_container)[0]); renderKatex($(reload_container)[0]);
if ('DjangoPagedown' in window) {
DjangoPagedown.init();
}
onWindowReady(); onWindowReady();
registerNavList(); registerNavList();
$('.xdsoft_datetimepicker').hide(); $('.xdsoft_datetimepicker').hide();