Source code for nlpmed_portal.management.views

# SPDX-FileCopyrightText: Copyright (C) 2026 Omid Jafari <omidjafari.com>
# SPDX-License-Identifier: AGPL-3.0-or-later
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from auditlog.models import LogEntry
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.contrib.contenttypes.models import ContentType
from django.contrib.sites.models import Site
from django.views.generic import ListView
from django.views.generic import TemplateView

from nlpmed_portal.users.models import User


[docs] class UserListView(LoginRequiredMixin, PermissionRequiredMixin, ListView): permission_required = "management.view_user" model = User queryset = User.objects.filter(is_staff=False) context_object_name = "users" template_name = "management/users_list.html"
[docs] def dispatch(self, request, *args, **kwargs): ct = ContentType.objects.get_for_model(Site) LogEntry.objects.create( content_type=ct, object_repr=f"management | {self.__class__.__name__}", action=LogEntry.Action.ACCESS, ) return super().dispatch(request, *args, **kwargs)
[docs] class GroupView(LoginRequiredMixin, PermissionRequiredMixin, TemplateView): permission_required = "management.view_group" template_name = "management/groups_list.html"
[docs] def dispatch(self, request, *args, **kwargs): ct = ContentType.objects.get_for_model(Site) LogEntry.objects.create( content_type=ct, object_repr=f"management | {self.__class__.__name__}", action=LogEntry.Action.ACCESS, ) return super().dispatch(request, *args, **kwargs)
[docs] class BackendView(LoginRequiredMixin, PermissionRequiredMixin, TemplateView): permission_required = "management.view_backend" template_name = "management/backends.html"
[docs] def dispatch(self, request, *args, **kwargs): ct = ContentType.objects.get_for_model(Site) LogEntry.objects.create( content_type=ct, object_repr=f"management | {self.__class__.__name__}", action=LogEntry.Action.ACCESS, ) return super().dispatch(request, *args, **kwargs)
[docs] class JobView(LoginRequiredMixin, PermissionRequiredMixin, TemplateView): permission_required = "management.view_job" template_name = "management/jobs_list.html"
[docs] def dispatch(self, request, *args, **kwargs): ct = ContentType.objects.get_for_model(Site) LogEntry.objects.create( content_type=ct, object_repr=f"management | {self.__class__.__name__}", action=LogEntry.Action.ACCESS, ) return super().dispatch(request, *args, **kwargs)
[docs] class FeedbackView(LoginRequiredMixin, PermissionRequiredMixin, TemplateView): permission_required = "management.view_feedback" template_name = "management/feedback_list.html"
[docs] def dispatch(self, request, *args, **kwargs): ct = ContentType.objects.get_for_model(Site) LogEntry.objects.create( content_type=ct, object_repr=f"management | {self.__class__.__name__}", action=LogEntry.Action.ACCESS, ) return super().dispatch(request, *args, **kwargs)