diff --git a/judge/admin/profile.py b/judge/admin/profile.py index 2bd3ae9..4c380c9 100644 --- a/judge/admin/profile.py +++ b/judge/admin/profile.py @@ -4,6 +4,7 @@ from django.utils.html import format_html 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 @@ -171,12 +172,12 @@ class ProfileAdmin(VersionAdmin): 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") @@ -221,3 +222,6 @@ class UserAdmin(OldUserAdmin): "user_permissions", ) return fields + + def has_add_permission(self, request): + return False diff --git a/judge/views/comment.py b/judge/views/comment.py index 73506bf..8ac62fa 100644 --- a/judge/views/comment.py +++ b/judge/views/comment.py @@ -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"]