From 203cb4de604cbc3bdf2a37af2d16ffe6a02df17a Mon Sep 17 00:00:00 2001 From: Heibert Date: Fri, 2 Aug 2024 09:38:34 -0500 Subject: [PATCH] Commit before delete the last commit --- INSIGHTSAPI/INSIGHTSAPI/settings.py | 2 +- INSIGHTSAPI/hierarchy/models.py | 23 +++++++++++++++++++++++ INSIGHTSAPI/hierarchy/tests.py | 12 +++++++++++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/INSIGHTSAPI/INSIGHTSAPI/settings.py b/INSIGHTSAPI/INSIGHTSAPI/settings.py index 6d852ad..cb110ac 100644 --- a/INSIGHTSAPI/INSIGHTSAPI/settings.py +++ b/INSIGHTSAPI/INSIGHTSAPI/settings.py @@ -251,7 +251,7 @@ def str_to_bool(value: str) -> bool: USE_I18N = True -# USE_L10N = True +USE_L10N = True USE_THOUSAND_SEPARATOR = True diff --git a/INSIGHTSAPI/hierarchy/models.py b/INSIGHTSAPI/hierarchy/models.py index 8efd29b..f70d52c 100644 --- a/INSIGHTSAPI/hierarchy/models.py +++ b/INSIGHTSAPI/hierarchy/models.py @@ -1,16 +1,39 @@ """This file contains the models for the hierarchy app. """ + from django.db import models +from users.models import User +from django.db.models import Q +from django.core.mail import mail_admins class Area(models.Model): """Model for the area""" name = models.CharField(max_length=100) + # manager = models.ForeignKey( + # "User", on_delete=models.SET_NULL, null=True, related_name="managed_areas" + # ) def __str__(self): """String representation of the model.""" return self.name + # def save(self, *args, **kwargs): + # """Save method for the model.""" + # if not self.manager: + # self.manager = ( + # User.objects.filter(area__name=self.name, job_position__rank__gte=5) + # .order_by("job_position__rank") + # .first() + # ) + # if not self.manager: + # mail_admins( + # "Warning", + # f"No manager found for area {self.name}. Please assign a manager.", + # ) + # super(Area, self).save(*args, **kwargs) + + class JobPosition(models.Model): name = models.CharField(max_length=100, unique=True) rank = models.PositiveIntegerField() diff --git a/INSIGHTSAPI/hierarchy/tests.py b/INSIGHTSAPI/hierarchy/tests.py index 7ce503c..7b203f0 100644 --- a/INSIGHTSAPI/hierarchy/tests.py +++ b/INSIGHTSAPI/hierarchy/tests.py @@ -1,3 +1,13 @@ -from django.test import TestCase +from services.tests import BaseTestCase +from hierarchy.models import Area # Create your tests here. +# class AreaTest(BaseTestCase): +# def test_manager_assignment(self): +# """Test the manager assignment for the area model.""" +# self.area = Area.objects.create(name="Test Area") +# area = Area.objects.create(name="Test Area") +# self.assertEqual(area.manager, None) +# area.save() +# self.assertEqual(area.manager, None) + \ No newline at end of file