Coverage for sites/comments_site/comments_database/admin.py: 98%

39 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2024-07-18 09:02 +0000

1from django.contrib import admin 

2from django.contrib.auth.admin import UserAdmin as BaseUserAdmin 

3from django.contrib.auth.models import Group 

4from django.utils.translation import gettext_lazy as _ 

5 

6from .forms import UserChangeForm 

7from .forms import UserCreationForm 

8from .models import Comment 

9from .models import ModerationRights 

10from .models import Moderator 

11from .models import User 

12 

13# We don't need this, so remove it from the admin dashboard 

14admin.site.unregister(Group) 

15 

16 

17@admin.register(User) 

18class UserAdmin(BaseUserAdmin): 

19 add_form = UserCreationForm 

20 form = UserChangeForm 

21 model = User 

22 list_display = ("username", "email", "mathdoc_site", "url", "is_staff", "is_superuser") 

23 list_filter = ("is_staff", "is_superuser", "is_active", "groups", "mathdoc_site") 

24 fieldsets = ( 

25 (_("Credentials"), {"fields": ("username", "password")}), 

26 (_("Mathdoc site"), {"fields": ("mathdoc_site", "url")}), 

27 ( 

28 _("Permissions"), 

29 { 

30 "fields": ("is_active", "is_staff", "is_superuser", "groups", "user_permissions"), 

31 }, 

32 ), 

33 (_("Important dates"), {"fields": ("last_login", "date_joined")}), 

34 ) 

35 add_fieldsets = ( 

36 ( 

37 _("Credentials"), 

38 { 

39 "classes": ("wide",), 

40 "fields": ("username", "password1", "password2"), 

41 }, 

42 ), 

43 (_("Mathdoc site"), {"fields": ("mathdoc_site", "url")}), 

44 ) 

45 search_fields = ("username", "url", "email") 

46 ordering = ("mathdoc_site", "username") 

47 

48 

49class ModerationRightsAdmin(admin.TabularInline): 

50 model = ModerationRights 

51 extra = 0 

52 verbose_name_plural = "Comments" 

53 

54 

55@admin.register(Comment) 

56class CommentAdmin(admin.ModelAdmin): 

57 inlines = (ModerationRightsAdmin,) 

58 empty_value_display = "" 

59 list_display = ( 

60 "id", 

61 "doi", 

62 "site", 

63 "author_id", 

64 "author_email", 

65 "author_full_name", 

66 "date_submitted", 

67 "status", 

68 ) 

69 list_filter = ("site", "status", "doi", "author_email") 

70 ordering = ("id",) 

71 

72 def has_change_permission(self, request, obj=None) -> bool: 

73 return False 

74 

75 

76@admin.register(Moderator) 

77class ModeratorAdmin(admin.ModelAdmin): 

78 inlines = (ModerationRightsAdmin,) 

79 list_display = ["__str__"]