[UPDT] BASE: Moved rotating shift create form from rotating_shift_assign.py to rotating_shift.py
This commit is contained in:
@@ -4,14 +4,22 @@ This page handles rotating shift types page in settings.
|
||||
|
||||
from typing import Any
|
||||
|
||||
from django.contrib import messages
|
||||
from django.http import HttpResponse
|
||||
from django.urls import reverse
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from base.decorators import manager_can_enter
|
||||
from base.filters import RotatingShiftFilter
|
||||
from base.forms import RotatingShiftForm
|
||||
from base.models import RotatingShift
|
||||
from horilla_views.cbv_methods import login_required, permission_required
|
||||
from horilla_views.generic.cbv.views import HorillaListView, HorillaNavView
|
||||
from horilla_views.generic.cbv.views import (
|
||||
HorillaFormView,
|
||||
HorillaListView,
|
||||
HorillaNavView,
|
||||
)
|
||||
|
||||
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
@@ -104,3 +112,56 @@ class RotatingShiftTypeNav(HorillaNavView):
|
||||
nav_title = _("Rotating Shift")
|
||||
filter_instance = RotatingShiftFilter()
|
||||
search_swap_target = "#listContainer"
|
||||
|
||||
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
@method_decorator(manager_can_enter("base.add_rotatingshift"), name="dispatch")
|
||||
class DynamicRotatingShiftTypeFormView(HorillaFormView):
|
||||
"""
|
||||
form view
|
||||
"""
|
||||
|
||||
model = RotatingShift
|
||||
form_class = RotatingShiftForm
|
||||
new_display_title = "Create Rotating Shift"
|
||||
is_dynamic_create_view = True
|
||||
template_name = "cbv/rotating_shift/rot_shift_form.html"
|
||||
|
||||
def form_valid(self, form: RotatingShiftForm) -> HttpResponse:
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
message = _("Rotating Shift Created")
|
||||
messages.success(self.request, message)
|
||||
return self.HttpResponse()
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
@method_decorator(manager_can_enter("base.add_rotatingshift"), name="dispatch")
|
||||
class RotatingShiftTypeCreateFormView(DynamicRotatingShiftTypeFormView):
|
||||
"""
|
||||
form view
|
||||
"""
|
||||
|
||||
is_dynamic_create_view = False
|
||||
template_name = "cbv/rotating_shift/rot_shift_form.html"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
form = self.form_class()
|
||||
if self.form.instance.pk:
|
||||
form = self.form_class(instance=self.form.instance)
|
||||
self.form_class.verbose_name = _("Update Rotating Shift Type")
|
||||
context[form] = form
|
||||
return context
|
||||
|
||||
def form_valid(self, form: RotatingShiftForm) -> HttpResponse:
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
if self.form.instance.pk:
|
||||
message = _("Rotating Shift Updated")
|
||||
else:
|
||||
message = _("Rotating Shift Created")
|
||||
messages.success(self.request, message)
|
||||
return self.HttpResponse()
|
||||
return super().form_valid(form)
|
||||
|
||||
@@ -13,15 +13,12 @@ from django.urls import reverse, reverse_lazy
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from base.cbv.rotating_shift import DynamicRotatingShiftTypeFormView
|
||||
from base.decorators import manager_can_enter
|
||||
from base.filters import RotatingShiftAssignFilters
|
||||
from base.forms import (
|
||||
RotatingShiftAssignExportForm,
|
||||
RotatingShiftAssignForm,
|
||||
RotatingShiftForm,
|
||||
)
|
||||
from base.forms import RotatingShiftAssignExportForm, RotatingShiftAssignForm
|
||||
from base.methods import choosesubordinates, filtersubordinates, is_reportingmanager
|
||||
from base.models import RotatingShift, RotatingShiftAssign
|
||||
from base.models import RotatingShiftAssign
|
||||
from employee.models import Employee
|
||||
from horilla_views.cbv_methods import login_required
|
||||
from horilla_views.generic.cbv.views import (
|
||||
@@ -292,57 +289,6 @@ class RotatingExportView(TemplateView):
|
||||
return context
|
||||
|
||||
|
||||
class DynamicRotatingShiftTypeFormView(HorillaFormView):
|
||||
"""
|
||||
form view
|
||||
"""
|
||||
|
||||
model = RotatingShift
|
||||
form_class = RotatingShiftForm
|
||||
new_display_title = "Create Rotating Shift"
|
||||
is_dynamic_create_view = True
|
||||
template_name = "cbv/rotating_shift/rot_shift_form.html"
|
||||
|
||||
def form_valid(self, form: RotatingShiftForm) -> HttpResponse:
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
message = _("Rotating Shift Created")
|
||||
messages.success(self.request, message)
|
||||
return self.HttpResponse()
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
@method_decorator(manager_can_enter("base.add_rotatingshift"), name="dispatch")
|
||||
class RotatingShiftTypeCreateFormView(DynamicRotatingShiftTypeFormView):
|
||||
"""
|
||||
form view
|
||||
"""
|
||||
|
||||
is_dynamic_create_view = False
|
||||
template_name = "cbv/rotating_shift/rot_shift_form.html"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
form = self.form_class()
|
||||
if self.form.instance.pk:
|
||||
form = self.form_class(instance=self.form.instance)
|
||||
self.form_class.verbose_name = _("Update Rotating Shift Type")
|
||||
context[form] = form
|
||||
return context
|
||||
|
||||
def form_valid(self, form: RotatingShiftForm) -> HttpResponse:
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
if self.form.instance.pk:
|
||||
message = _("Rotating Shift Updated")
|
||||
else:
|
||||
message = _("Rotating Shift Created")
|
||||
messages.success(self.request, message)
|
||||
return self.HttpResponse()
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
@method_decorator(manager_can_enter("base.add_rotatingshiftassign"), name="dispatch")
|
||||
class RotatingShiftFormView(HorillaFormView):
|
||||
|
||||
@@ -527,12 +527,12 @@ urlpatterns = [
|
||||
),
|
||||
path(
|
||||
"rotating-work-type-create-form/",
|
||||
rotating_work_type.RotatingWorkTypesCreateForm.as_view(),
|
||||
settings_rotatingwork.RotatingWorkTypesCreateForm.as_view(),
|
||||
name="rotating-work-type-create-form",
|
||||
),
|
||||
path(
|
||||
"rotating-work-type-update-form/<int:pk>",
|
||||
rotating_work_type.RotatingWorkTypesCreateForm.as_view(),
|
||||
settings_rotatingwork.RotatingWorkTypesCreateForm.as_view(),
|
||||
name="rotating-work-type-update-form",
|
||||
),
|
||||
path(
|
||||
@@ -787,7 +787,7 @@ urlpatterns = [
|
||||
# ),
|
||||
path(
|
||||
"rotating-shift-create/",
|
||||
rotating_shift_assign.RotatingShiftTypeCreateFormView.as_view(),
|
||||
rotating_shift.RotatingShiftTypeCreateFormView.as_view(),
|
||||
name="rotating-shift-create",
|
||||
),
|
||||
path(
|
||||
@@ -825,7 +825,7 @@ urlpatterns = [
|
||||
# ),
|
||||
path(
|
||||
"settings/rotating-shift-update/<int:pk>/",
|
||||
rotating_shift_assign.RotatingShiftTypeCreateFormView.as_view(),
|
||||
rotating_shift.RotatingShiftTypeCreateFormView.as_view(),
|
||||
name="rotating-shift-update",
|
||||
),
|
||||
path(
|
||||
|
||||
Reference in New Issue
Block a user