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.utils.translation import gettext, gettext_lazy as _, ungettext
from django.contrib.auth.admin import UserAdmin as OldUserAdmin from django.contrib.auth.admin import UserAdmin as OldUserAdmin
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.contrib.auth.forms import UserChangeForm
from django_ace import AceWidget from django_ace import AceWidget
@ -171,11 +172,11 @@ class ProfileAdmin(VersionAdmin):
recalculate_points.short_description = _("Recalculate scores") recalculate_points.short_description = _("Recalculate scores")
class UserForm(ModelForm): class UserForm(UserChangeForm):
username = CharField( def __init__(self, *args, **kwargs):
max_length=150, super().__init__(*args, **kwargs)
help_text=_("Username can only contain letters, digits, and underscores."), self.fields["username"].help_text = _(
widget=TextInput(attrs={"class": "vTextField"}), "Username can only contain letters, digits, and underscores."
) )
def clean_username(self): def clean_username(self):
@ -221,3 +222,6 @@ class UserAdmin(OldUserAdmin):
"user_permissions", "user_permissions",
) )
return fields 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): def get_context_data(self, **kwargs):
context = super(CommentRevisionAjax, self).get_context_data(**kwargs) context = super(CommentRevisionAjax, self).get_context_data(**kwargs)
revisions = Version.objects.get_for_object(self.object).order_by("-revision") revisions = Version.objects.get_for_object(self.object).order_by("-revision")
if len(revisions) == 0:
raise Http404
try: try:
wanted = min( wanted = min(
max(int(self.request.GET.get("revision", 0)), 0), len(revisions) - 1 max(int(self.request.GET.get("revision", 0)), 0), len(revisions) - 1
) )
except ValueError:
raise Http404
revision = revisions[wanted] revision = revisions[wanted]
except (ValueError, IndexError):
raise Http404
data = json.loads(revision.serialized_data) data = json.loads(revision.serialized_data)
try: try:
context["body"] = data[0]["fields"]["body"] context["body"] = data[0]["fields"]["body"]