diff --git a/scipost_django/ethics/admin.py b/scipost_django/ethics/admin.py index bdb227fcb9c4c8d68ce1f60d5dc00e8ce5667032..984b59beda0f7d1ccde857b68a6a0d67cc6909e9 100644 --- a/scipost_django/ethics/admin.py +++ b/scipost_django/ethics/admin.py @@ -2,9 +2,17 @@ __copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)" __license__ = "AGPL v3" +from typing import Any, Optional from django.contrib import admin +from django.contrib.contenttypes.admin import GenericTabularInline from django.contrib.contenttypes.models import ContentType -from django.forms import ChoiceField +from django.db.models.fields import Field +from django.forms import ChoiceField, widgets +from django.forms.fields import TypedChoiceField +from django.http.request import HttpRequest +from blog import forms + +from profiles.models import Profile from .models import CompetingInterest, RedFlag @@ -59,12 +67,33 @@ class ConcerningObjectExistingFilter(admin.SimpleListFilter): @admin.register(RedFlag) class RedFlagAdmin(admin.ModelAdmin): - search_fields = ("concerning_object_id", "raised_by__last_name") - list_filter = ["resolved", ConcerningObjectExistingFilter] + model = RedFlag list_display = ( - "concerning_object", - "raised_by", "description", + "raised_by", "raised_on", "resolved", ) + + +class RedFlagInline(GenericTabularInline): + ct_field = "concerning_object_type" + ct_fk_field = "concerning_object_id" + fk_name = "concerning_object" + model = RedFlag + extra = 0 + + fields = ["raised_on", "raised_by", "description", "resolved"] + autocomplete_fields = ["raised_by"] + + # modify the description textarea field to have 2 rows + def formfield_for_dbfield(self, db_field: Field, **kwargs: Any) -> Any: + if db_field.name == "description": + kwargs["widget"] = widgets.Textarea(attrs={"rows": 1}) + return super().formfield_for_dbfield(db_field, **kwargs) + + # prefill the autocomplete field with the current user + def formfield_for_foreignkey(self, db_field, request, **kwargs): + if db_field.name == "raised_by": + kwargs["initial"] = request.user.contributor + return super().formfield_for_foreignkey(db_field, request, **kwargs) diff --git a/scipost_django/profiles/admin.py b/scipost_django/profiles/admin.py index 30a592ffaf28bafb772a1100d4ee85aa0f56076e..ea483fa1f2ddd23c89cf51f937c3676857f6f7dd 100644 --- a/scipost_django/profiles/admin.py +++ b/scipost_django/profiles/admin.py @@ -4,6 +4,8 @@ __license__ = "AGPL v3" from django.contrib import admin +from ethics.admin import RedFlagInline + from .models import Profile, ProfileEmail, ProfileNonDuplicates, Affiliation @@ -23,10 +25,8 @@ class AffiliationInline(admin.TabularInline): class ProfileAdmin(admin.ModelAdmin): list_display = ["__str__", "email", "acad_field", "has_active_contributor"] search_fields = ["first_name", "last_name", "emails__email", "orcid_id"] - inlines = [ProfileEmailInline, AffiliationInline] - autocomplete_fields = [ - "topics", - ] + inlines = [ProfileEmailInline, AffiliationInline, RedFlagInline] + autocomplete_fields = ["topics"] admin.site.register(Profile, ProfileAdmin) diff --git a/scipost_django/submissions/admin.py b/scipost_django/submissions/admin.py index 1ffb69d4f048b6f8e871d50cc45523651abcb7fe..c0d25f52f01334bc52f0d201a0131d24073e46fd 100644 --- a/scipost_django/submissions/admin.py +++ b/scipost_django/submissions/admin.py @@ -7,6 +7,7 @@ from django.db.models import Q from django import forms from guardian.admin import GuardedModelAdmin +from ethics.admin import RedFlagInline from submissions.models import ( SubmissionAuthorProfile, @@ -172,6 +173,7 @@ class SubmissionAdmin(GuardedModelAdmin): SubmissionClearanceInline, SubmissionTieringInline, CollectionInline, + RedFlagInline, ] # Admin fields should be added in the fieldsets