This commit is contained in:
Tom Hubrecht 2023-01-31 14:15:34 +01:00
parent aa94996155
commit 6e893afd90
5 changed files with 38 additions and 13 deletions

View file

@ -1,3 +1,7 @@
from datetime import date
from typing import Optional
from dateutil.relativedelta import relativedelta
from django.contrib.auth.models import User
from django.core.validators import MinValueValidator
from django.db import models
@ -37,14 +41,18 @@ class Profile(models.Model):
default=False, verbose_name=_("conserver la fiche annuaire ?")
)
def __str__(self):
def __str__(self) -> str:
return self.full_name
@property
def age(self):
return self.day.year - self.birth_date.year
def age(self) -> Optional[int]:
if self.birth_date is not None:
return relativedelta(date.today(), self.birth_date).year
def birthday(self) -> str:
if self.birth_date is None:
return "Unknown"
def birthday(self):
return self.birth_date.strftime("%d%m")
@ -53,7 +61,7 @@ class Department(models.Model):
max_length=255, verbose_name=_("nom du département"), unique=True
)
def __str__(self):
def __str__(self) -> str:
return self.name
@ -64,7 +72,7 @@ class Phone(models.Model):
name = models.CharField(max_length=255, verbose_name=_("type"))
number = models.CharField(max_length=1023, verbose_name=_("numéro"))
def __str__(self):
def __str__(self) -> str:
return "{} : {}".format(self.name, self.number)
@ -86,7 +94,7 @@ class Mail(models.Model):
name = models.CharField(max_length=255, verbose_name=_("type"))
mail = models.CharField(max_length=1023, verbose_name=_("adresse mail"))
def __str__(self):
def __str__(self) -> str:
return "{} : {}".format(self.name, self.mail)
@ -97,5 +105,5 @@ class Address(models.Model):
name = models.CharField(max_length=255, verbose_name=_("type"))
content = models.TextField(verbose_name=_("adresse"))
def __str__(self):
def __str__(self) -> str:
return "{} : {}".format(self.name, self.content)

View file

@ -159,7 +159,7 @@ class BirthdayView(ListView):
birth_date__day=today.day, birth_date__month=today.month
).annotate(day=Value(today, output_field=DateTimeField()))
)
for i in range(1, 7):
for _ in range(1, 7):
today = today + timedelta(days=1)
context["result"] += list(
Profile.objects.filter(

17
poetry.lock generated
View file

@ -922,6 +922,21 @@ lxml = ">=3.4"
requests = ">=2.11.1"
six = ">=1.10.0"
[[package]]
name = "python-dateutil"
version = "2.8.2"
description = "Extensions to the standard Python datetime module"
category = "main"
optional = false
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7"
files = [
{file = "python-dateutil-2.8.2.tar.gz", hash = "sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86"},
{file = "python_dateutil-2.8.2-py2.py3-none-any.whl", hash = "sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9"},
]
[package.dependencies]
six = ">=1.5"
[[package]]
name = "python-ldap"
version = "3.4.3"
@ -1123,4 +1138,4 @@ files = [
[metadata]
lock-version = "2.0"
python-versions = "^3.9"
content-hash = "fa8b2aeaab01568ad58818d249424dd837df8f7cc89be68522542f1f45c9f5a4"
content-hash = "219ac059786c135b45e46fe7f535b750012aa146f18a6a30fddbc0b3889beed2"

View file

@ -10,6 +10,7 @@ python = "^3.9"
Django = "^3.2.0"
Pillow = "^9.4.0"
authens = "^0.1b4"
python-dateutil = "^2.8.2"
[tool.poetry.group.dev.dependencies]
ipython = "^8.9.0"
@ -25,6 +26,9 @@ psycopg2 = "^2.9.5"
gunicorn = "^20.1.0"
django-redis = "^5.2.0"
[tool.isort]
profile = "black"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

View file

@ -11,7 +11,7 @@ print("\nTransfert des fiches annuaires :")
# Configuration
print("Paramétrage de Django...", end=" ")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "annuaire.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "annuaire.settings.prod")
django.setup()
User = get_user_model()
@ -193,8 +193,6 @@ with open("old_fiches.json") as json_file:
fiche.text_field += f" ({obj_data['source']})"
if obj_data["author"]:
fiche.text_field += f", ({obj_data['author']})"
if a:
adresses.append(Address(profile=fiche, name="Adresse", content=a))
except KeyError:
pass