Fix user admin bug and comment index bug

This commit is contained in:
cuom1999 2024-09-19 16:14:45 -05:00
parent c54bcd4a16
commit 1dd4ccd324
2 changed files with 17 additions and 8 deletions

View file

@ -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,11 +172,11 @@ 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):
@ -221,3 +222,6 @@ class UserAdmin(OldUserAdmin):
"user_permissions",
)
return fields
def has_add_permission(self, request):
return False

View file

@ -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:
raise Http404
revision = revisions[wanted]
except (ValueError, IndexError):
raise Http404
data = json.loads(revision.serialized_data)
try:
context["body"] = data[0]["fields"]["body"]