Skip to content

Commit

Permalink
Fix minor bugs and improve some model fields
Browse files Browse the repository at this point in the history
  • Loading branch information
cuom1999 committed Aug 22, 2024
1 parent f98549e commit a42bae5
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 14 deletions.
32 changes: 32 additions & 0 deletions chat_box/migrations/0016_alter_room_unique_together.py
Original file line number Diff line number Diff line change
@@ -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")},
),
]
1 change: 1 addition & 0 deletions chat_box/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Room(models.Model):

class Meta:
app_label = "chat_box"
unique_together = ("user_one", "user_two")

@cached_property
def _cached_info(self):
Expand Down
2 changes: 0 additions & 2 deletions judge/admin/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class OrganizationAdmin(VersionAdmin):
"short_name",
"is_open",
"about",
"organization_image",
"logo_override_image",
"slots",
"registrant",
"creation_date",
Expand Down
17 changes: 17 additions & 0 deletions judge/migrations/0191_deprecate_old_org_image.py
Original file line number Diff line number Diff line change
@@ -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",
),
]
10 changes: 0 additions & 10 deletions judge/models/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,6 @@ class Organization(models.Model):
blank=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):
if isinstance(item, int):
Expand Down
5 changes: 3 additions & 2 deletions judge/views/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ def calculate_lessons_progress(profile, lessons):
num_problems = len(problems)
percentage = 0
for val in problem_points.values():
score = val["case_points"] / val["case_total"]
percentage += score / num_problems
if val["case_total"] > 0:
score = val["case_points"] / val["case_total"]
percentage += score / num_problems
res[lesson.id] = {
"achieved_points": percentage * lesson.points,
"percentage": percentage * 100,
Expand Down
3 changes: 3 additions & 0 deletions resources/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,9 @@ function navigateTo(url, reload_container, force_new_page=false) {

$(document).prop('title', $(data).filter('title').text());
renderKatex($(reload_container)[0]);
if ('DjangoPagedown' in window) {
DjangoPagedown.init();
}
onWindowReady();
registerNavList();
$('.xdsoft_datetimepicker').hide();
Expand Down

0 comments on commit a42bae5

Please sign in to comment.