__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)"
__license__ = "AGPL v3"
from django.contrib import admin
from django import forms
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User, Permission
from scipost.models import (
TOTPDevice,
Contributor,
Remark,
AuthorshipClaim,
PrecookedEmail,
UnavailabilityPeriod,
)
from organizations.admin import ContactInline
from production.admin import ProductionUserInline
from profiles.models import Profile
from submissions.models import Submission
[docs]class TOTPDeviceAdmin(admin.ModelAdmin):
search_fields = [
"user",
]
autocomplete_fields = [
"user",
]
admin.site.register(TOTPDevice)
[docs]class UnavailabilityPeriodAdmin(admin.ModelAdmin):
autocomplete_fields = [
"contributor",
]
admin.site.register(UnavailabilityPeriod, UnavailabilityPeriodAdmin)
[docs]class ContributorAdmin(admin.ModelAdmin):
search_fields = [
"user__first_name",
"user__last_name",
"user__email",
"profile__orcid_id",
]
autocomplete_fields = [
"profile",
"user",
"vetted_by",
"duplicate_of",
]
[docs]class ContributorInline(admin.StackedInline):
model = Contributor
extra = 0
min_num = 0
autocomplete_fields = [
"profile",
"vetted_by",
"duplicate_of",
]
[docs]class TOTPDeviceInline(admin.StackedInline):
model = TOTPDevice
extra = 0
min_num = 0
[docs]class UserAdmin(UserAdmin):
inlines = [ContributorInline, TOTPDeviceInline, ContactInline, ProductionUserInline]
list_display = [
"username",
"email",
"first_name",
"last_name",
"is_active",
"is_staff",
"is_duplicate",
]
search_fields = ["username", "last_name", "email"]
[docs] def is_duplicate(self, obj):
return obj.contributor.is_duplicate
is_duplicate.short_description = "Is duplicate?"
is_duplicate.boolean = True
admin.site.unregister(User)
admin.site.register(Contributor, ContributorAdmin)
admin.site.register(User, UserAdmin)
admin.site.register(Remark, RemarkAdmin)
[docs]class AuthorshipClaimAdmin(admin.ModelAdmin):
autocomplete_fields = [
"claimant",
"submission",
"commentary",
"thesislink",
"vetted_by",
]
admin.site.register(AuthorshipClaim, AuthorshipClaimAdmin)
admin.site.register(Permission)
[docs]class PrecookedEmailAdmin(admin.ModelAdmin):
search_fields = ["email_subject", "email_text", "emailed_to"]
admin.site.register(PrecookedEmail, PrecookedEmailAdmin)