From 07a742f8f32191a73a33ffa85c083ab1f78d8fd3 Mon Sep 17 00:00:00 2001 From: Heibert Date: Wed, 25 Sep 2024 18:10:26 -0500 Subject: [PATCH] Changes to hierarchy admin --- INSIGHTSAPI/hierarchy/admin.py | 15 +++++++++++++++ INSIGHTSAPI/users/views.py | 5 +++-- INSIGHTSAPI/vacation/views.py | 5 +---- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/INSIGHTSAPI/hierarchy/admin.py b/INSIGHTSAPI/hierarchy/admin.py index 6e30182..3a046fe 100644 --- a/INSIGHTSAPI/hierarchy/admin.py +++ b/INSIGHTSAPI/hierarchy/admin.py @@ -12,6 +12,20 @@ def upper_case_name(obj): return "" +class ChildAreaInline(admin.TabularInline): + """Inline admin for displaying child areas.""" + + model = Area + fk_name = "parent" # Specifies that the parent field links the child areas + extra = 0 # No extra empty forms in the inline by default + max_num = 0 # Do not allow adding more child areas + fields = ("name", "manager") # Fields to display for the child areas + readonly_fields = ("name", "manager") # Make these fields read-only + show_change_link = True # Show a link to the child area's change page + can_delete = False # Do not allow deleting child areas from the parent area + ordering = ("name",) # Order the child areas by name + + @admin.register(Area) class AreaAdmin(admin.ModelAdmin): """Area admin.""" @@ -23,6 +37,7 @@ class AreaAdmin(admin.ModelAdmin): "manager__last_name", ) ordering = ("name",) + inlines = [ChildAreaInline] def formfield_for_foreignkey(self, db_field, request, **kwargs): """Customize the queryset for the manager field.""" diff --git a/INSIGHTSAPI/users/views.py b/INSIGHTSAPI/users/views.py index c1c3c34..e034ca9 100644 --- a/INSIGHTSAPI/users/views.py +++ b/INSIGHTSAPI/users/views.py @@ -38,8 +38,9 @@ def login_staffnet(): "Error logging in StaffNet", "Error logging in StaffNet: {}".format(response.text), ) - # delete the token to try to login again - del os.environ["StaffNetToken"] + if os.environ.get("StaffNetToken"): + # delete the token to try to login again + del os.environ["StaffNetToken"] return None os.environ["StaffNetToken"] = response.cookies["StaffNet"] return True diff --git a/INSIGHTSAPI/vacation/views.py b/INSIGHTSAPI/vacation/views.py index 981e040..8ad45d0 100644 --- a/INSIGHTSAPI/vacation/views.py +++ b/INSIGHTSAPI/vacation/views.py @@ -167,10 +167,7 @@ def partial_update(self, request, *args, **kwargs): # Check if the user is updating the hr_approbation field if "manager_approbation" in request.data: # Check if the user is a manager - if ( - request.user.job_position.rank >= 5 - or request.user.cedula == "1022370826" - ): + if request.user.job_position.rank >= 5: if self.get_object().manager_approbation is not None: return Response( {"detail": "No puedes modificar esta solicitud."},