[FIX] PMS: Added validation for question template when answerable employee in meetings room
This commit is contained in:
@@ -35,6 +35,7 @@ class HorillaMultiSelectWidget(forms.Widget):
|
||||
filter_template_path=None,
|
||||
instance=None,
|
||||
required=False,
|
||||
form=None,
|
||||
**kwargs
|
||||
) -> None:
|
||||
self.filter_route_name = filter_route_name
|
||||
@@ -43,6 +44,7 @@ class HorillaMultiSelectWidget(forms.Widget):
|
||||
self.filter_instance_contex_name = filter_instance_contex_name
|
||||
self.filter_template_path = filter_template_path
|
||||
self.instance = instance
|
||||
self.form = form
|
||||
super().__init__()
|
||||
|
||||
template_name = "horilla_widgets/horilla_multiselect_widget.html"
|
||||
@@ -55,9 +57,17 @@ class HorillaMultiSelectWidget(forms.Widget):
|
||||
field = self.choices.field
|
||||
context["queryset"] = queryset
|
||||
context["field_name"] = name
|
||||
if self.instance and self.instance.pk:
|
||||
if self.form and name in self.form.data:
|
||||
initial = self.form.data.getlist(name)
|
||||
context["initial"] = initial
|
||||
elif value:
|
||||
context["initial"] = value
|
||||
|
||||
elif self.instance and self.instance.pk:
|
||||
initial = list(getattr(self.instance, name).values_list("id", flat=True))
|
||||
context["initial"] = initial
|
||||
else:
|
||||
context["initial"] = []
|
||||
context["field"] = field
|
||||
context["self"] = self
|
||||
context["filter_template_path"] = self.filter_template_path
|
||||
|
||||
75
pms/cbvs.py
75
pms/cbvs.py
@@ -4,8 +4,12 @@ from django.contrib import messages
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import render
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.utils.translation import gettext_lazy as _trans
|
||||
|
||||
from base.methods import filter_own_and_subordinate_recordes, is_reportingmanager
|
||||
from horilla import horilla_middlewares
|
||||
from horilla.decorators import login_required, permission_required
|
||||
from horilla_views.generic.cbv import views
|
||||
from pms import models
|
||||
from pms.filters import BonusPointSettingFilter, EmployeeBonusPointFilter
|
||||
@@ -13,6 +17,8 @@ from pms.forms import BonusPointSettingForm, EmployeeBonusPointForm
|
||||
|
||||
|
||||
# ================Models for BonusPointSetting==============
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
@method_decorator(permission_required("pms.view_bonuspointsetting"), name="dispatch")
|
||||
class BonusPointSettingSectionView(views.HorillaSectionView):
|
||||
"""
|
||||
BonusPointSetting SectionView
|
||||
@@ -29,6 +35,8 @@ class BonusPointSettingSectionView(views.HorillaSectionView):
|
||||
template_name = "bonus/bonus_point_setting_section.html"
|
||||
|
||||
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
@method_decorator(permission_required("pms.view_bonuspointsetting"), name="dispatch")
|
||||
class BonusPointSettingNavView(views.HorillaNavView):
|
||||
"""
|
||||
BonusPointSetting nav view
|
||||
@@ -48,6 +56,8 @@ class BonusPointSettingNavView(views.HorillaNavView):
|
||||
search_swap_target = "#listContainer"
|
||||
|
||||
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
@method_decorator(permission_required("pms.change_bonuspointsetting"), name="dispatch")
|
||||
class BonusPointSettingFormView(views.HorillaFormView):
|
||||
"""
|
||||
BonusPointSettingForm View
|
||||
@@ -90,6 +100,8 @@ class BonusPointSettingFormView(views.HorillaFormView):
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
@method_decorator(permission_required("pms.view_bonuspointsetting"), name="dispatch")
|
||||
class BonusPointSettingListView(views.HorillaListView):
|
||||
"""
|
||||
BnusPointSetting list view
|
||||
@@ -99,30 +111,6 @@ class BonusPointSettingListView(views.HorillaListView):
|
||||
search_url = reverse_lazy("bonus-point-setting-list-view")
|
||||
filter_class = BonusPointSettingFilter
|
||||
action_method = "action_template"
|
||||
# actions = [
|
||||
# {
|
||||
# "action": "Edit",
|
||||
# "icon": "create-outline",
|
||||
# "attrs": """
|
||||
# class="oh-btn oh-btn--light-bkg w-100"
|
||||
# hx-get="{edit_url}?instance_ids={ordered_ids}"
|
||||
# hx-target="#genericModalBody"
|
||||
# data-target="#genericModal"
|
||||
# data-toggle="oh-modal-toggle"
|
||||
# """,
|
||||
# },
|
||||
# {
|
||||
# "action": "Delete",
|
||||
# "icon": "trash-outline",
|
||||
# "attrs": """
|
||||
# class="oh-btn oh-btn--light-bkg w-100 tex-danger"
|
||||
# onclick="
|
||||
# event.stopPropagation();
|
||||
# confirm('Do you want to delete the bonus point setting?','{delete_url}')
|
||||
# "
|
||||
# """,
|
||||
# },
|
||||
# ]
|
||||
|
||||
columns = [
|
||||
("Model", "get_model_display"),
|
||||
@@ -228,42 +216,31 @@ class EmployeeBonusPointListView(views.HorillaListView):
|
||||
BnusPoint list view
|
||||
"""
|
||||
|
||||
request = getattr(horilla_middlewares._thread_locals, "request", None)
|
||||
|
||||
model = models.EmployeeBonusPoint
|
||||
search_url = reverse_lazy("employee-bonus-point-list-view")
|
||||
filter_class = EmployeeBonusPointFilter
|
||||
action_method = "action_template"
|
||||
if is_reportingmanager(request):
|
||||
action_method = "action_template"
|
||||
bulk_update_fields = [
|
||||
"employee_id",
|
||||
"bonus_point",
|
||||
"based_on",
|
||||
]
|
||||
# actions = [
|
||||
# {
|
||||
# "action": "Edit",
|
||||
# "icon": "create-outline",
|
||||
# "attrs": """
|
||||
# class="oh-btn oh-btn--light-bkg w-100"
|
||||
# hx-get="{edit_url}?instance_ids={ordered_ids}"
|
||||
# hx-target="#genericModalBody"
|
||||
# data-target="#genericModal"
|
||||
# data-toggle="oh-modal-toggle"
|
||||
# """,
|
||||
# },
|
||||
# {
|
||||
# "action": "Delete",
|
||||
# "icon": "trash-outline",
|
||||
# "attrs": """
|
||||
# class="oh-btn oh-btn--light-bkg w-100 tex-danger"
|
||||
# onclick="
|
||||
# event.stopPropagation();
|
||||
# confirm('Do you want to delete the automation?','{delete_url}')
|
||||
# "
|
||||
# """,
|
||||
# },
|
||||
# ]
|
||||
|
||||
columns = [
|
||||
("Employee", "employee_id"),
|
||||
("Bonus Point", "bonus_point"),
|
||||
("Based On", "based_on"),
|
||||
]
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = super().get_queryset()
|
||||
request = getattr(horilla_middlewares._thread_locals, "request", None)
|
||||
if is_reportingmanager(request):
|
||||
return filter_own_and_subordinate_recordes(
|
||||
request, queryset, perm="pms.view_employeebonuspoint"
|
||||
)
|
||||
else:
|
||||
return queryset.filter(employee_id=request.user.employee_get)
|
||||
|
||||
11
pms/forms.py
11
pms/forms.py
@@ -1048,6 +1048,16 @@ class MeetingsForm(BaseForm):
|
||||
ids = self.data.getlist("employee_id")
|
||||
if ids:
|
||||
self.errors.pop("employee_id", None)
|
||||
|
||||
if cleaned_data["answer_employees"] and not cleaned_data["question_template"]:
|
||||
raise ValidationError(
|
||||
{
|
||||
"question_template": _(
|
||||
"Question template is required when answer employees are choosed"
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
return cleaned_data
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
@@ -1063,6 +1073,7 @@ class MeetingsForm(BaseForm):
|
||||
filter_class=EmployeeFilter,
|
||||
filter_instance_contex_name="f",
|
||||
filter_template_path="employee_filters.html",
|
||||
form=self,
|
||||
),
|
||||
label=_("Employees"),
|
||||
)
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
<div class="oh-switch p-3">
|
||||
{% if perms.pms.change_bonuspointsetting %}
|
||||
<input type="checkbox" name="is_active" id="BPSIsActivate"
|
||||
{% comment %} hx-post="{% url 'update-isactive-gracetime' instance.id %}" {% endcomment %}
|
||||
{% comment %} hx-trigger="change" hx-target="#graceTimeContainer" {% endcomment %}
|
||||
hx-post="{% url 'update-isactive-bonuspoint-setting' instance.id %}"
|
||||
hx-trigger="change" hx-target="#genericModalBody"
|
||||
class="oh-switch__checkbox"
|
||||
{% if instance.is_active %} checked {% endif %}>
|
||||
{% else %}
|
||||
|
||||
17
pms/urls.py
17
pms/urls.py
@@ -1,6 +1,7 @@
|
||||
from django.urls import path
|
||||
|
||||
from base.views import object_delete
|
||||
from horilla_audit.methods import history_tracking
|
||||
from pms import cbvs
|
||||
|
||||
from . import models, views
|
||||
@@ -417,11 +418,6 @@ urlpatterns = [
|
||||
name="dashboard-feedback-answer",
|
||||
),
|
||||
# ===========bonus point setting============
|
||||
# path(
|
||||
# "view-bonus-setting",
|
||||
# views.view_bonus_setting,
|
||||
# name="view-bonus-setting",
|
||||
# ),
|
||||
path(
|
||||
"bonus-point-setting/",
|
||||
cbvs.BonusPointSettingSectionView.as_view(),
|
||||
@@ -457,6 +453,11 @@ urlpatterns = [
|
||||
views.bonus_setting_form_values,
|
||||
name="bonus-setting-form-values",
|
||||
),
|
||||
path(
|
||||
"update-isactive-bonuspoint-setting/<int:obj_id>",
|
||||
views.update_isactive_bonuspoint_setting,
|
||||
name="update-isactive-bonuspoint-setting",
|
||||
),
|
||||
# ===========Employee bonus point============
|
||||
path(
|
||||
"employee-bonus-point",
|
||||
@@ -488,4 +489,10 @@ urlpatterns = [
|
||||
views.delete_employee_bonus_point,
|
||||
name="delete-employee-bonus-point",
|
||||
),
|
||||
path(
|
||||
"history-tracking/<int:obj_id>/",
|
||||
history_tracking,
|
||||
name="history-tracking",
|
||||
kwargs={"model": models.Meetings, "decorators": ["login_required"]},
|
||||
),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user