Skip to content

Commit

Permalink
Fix user admin bug and comment index bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cuom1999 committed Sep 19, 2024
1 parent c54bcd4 commit 1dd4ccd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
16 changes: 10 additions & 6 deletions judge/admin/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.utils.translation import gettext, gettext_lazy as _, ungettext
from django.contrib.auth.admin import UserAdmin as OldUserAdmin
from django.core.exceptions import ValidationError
from django.contrib.auth.forms import UserChangeForm

from django_ace import AceWidget

Expand Down Expand Up @@ -171,12 +172,12 @@ def recalculate_points(self, request, queryset):
recalculate_points.short_description = _("Recalculate scores")


class UserForm(ModelForm):
username = CharField(
max_length=150,
help_text=_("Username can only contain letters, digits, and underscores."),
widget=TextInput(attrs={"class": "vTextField"}),
)
class UserForm(UserChangeForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["username"].help_text = _(
"Username can only contain letters, digits, and underscores."
)

def clean_username(self):
username = self.cleaned_data.get("username")
Expand Down Expand Up @@ -221,3 +222,6 @@ def get_readonly_fields(self, request, obj=None):
"user_permissions",
)
return fields

def has_add_permission(self, request):
return False
9 changes: 7 additions & 2 deletions judge/views/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,18 @@ class CommentRevisionAjax(CommentMixin, DetailView):
def get_context_data(self, **kwargs):
context = super(CommentRevisionAjax, self).get_context_data(**kwargs)
revisions = Version.objects.get_for_object(self.object).order_by("-revision")

if len(revisions) == 0:
raise Http404

try:
wanted = min(
max(int(self.request.GET.get("revision", 0)), 0), len(revisions) - 1
)
except ValueError:
revision = revisions[wanted]
except (ValueError, IndexError):
raise Http404
revision = revisions[wanted]

data = json.loads(revision.serialized_data)
try:
context["body"] = data[0]["fields"]["body"]
Expand Down

0 comments on commit 1dd4ccd

Please sign in to comment.