* refactors team views * split views.py into users.py and teams.py in users app * refactors method headers for _user_has_permission() * adds method and class comments and documentation to base view classes
58 lines
1.7 KiB
Python
58 lines
1.7 KiB
Python
"""
|
|
Author: Michel Peltriaux
|
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
|
Contact: ksp-servicestelle@sgdnord.rlp.de
|
|
Created on: 22.08.22
|
|
|
|
"""
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
from django.urls import reverse
|
|
|
|
from compensation.forms.modals.state import NewCompensationStateModalForm, EditCompensationStateModalForm, \
|
|
RemoveCompensationStateModalForm
|
|
from konova.utils.message_templates import COMPENSATION_STATE_ADDED, COMPENSATION_STATE_EDITED, \
|
|
COMPENSATION_STATE_REMOVED
|
|
from konova.views.base import BaseModalFormView
|
|
|
|
|
|
class AbstractCompensationStateView(LoginRequiredMixin, BaseModalFormView):
|
|
_MODEL_CLS = None
|
|
_FORM_CLS = None
|
|
_REDIRECT_URL = None
|
|
|
|
class Meta:
|
|
abstract = True
|
|
|
|
def _user_has_permission(self, user, **kwargs):
|
|
return user.is_default_user()
|
|
|
|
def _get_redirect_url(self, *args, **kwargs):
|
|
obj = kwargs.get("obj", None)
|
|
assert obj is not None
|
|
return reverse(self._REDIRECT_URL, args=(obj.id,)) + "#related_data"
|
|
|
|
class AbstractNewCompensationStateView(AbstractCompensationStateView):
|
|
_MODEL_CLS = None
|
|
_FORM_CLS = NewCompensationStateModalForm
|
|
_MSG_SUCCESS = COMPENSATION_STATE_ADDED
|
|
|
|
class Meta:
|
|
abstract = True
|
|
|
|
class AbstractEditCompensationStateView(AbstractCompensationStateView):
|
|
_MODEL_CLS = None
|
|
_FORM_CLS = EditCompensationStateModalForm
|
|
_MSG_SUCCESS = COMPENSATION_STATE_EDITED
|
|
|
|
class Meta:
|
|
abstract = True
|
|
|
|
|
|
class AbstractRemoveCompensationStateView(AbstractCompensationStateView):
|
|
_MODEL_CLS = None
|
|
_FORM_CLS = RemoveCompensationStateModalForm
|
|
_MSG_SUCCESS = COMPENSATION_STATE_REMOVED
|
|
|
|
class Meta:
|
|
abstract = True
|