Skip to content

Commit

Permalink
Changes to hierarchy admin
Browse files Browse the repository at this point in the history
  • Loading branch information
Heibert committed Sep 25, 2024
1 parent 3982a8e commit 07a742f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
15 changes: 15 additions & 0 deletions INSIGHTSAPI/hierarchy/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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."""
Expand Down
5 changes: 3 additions & 2 deletions INSIGHTSAPI/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions INSIGHTSAPI/vacation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."},
Expand Down

0 comments on commit 07a742f

Please sign in to comment.