Update
This commit is contained in:
parent
aa94996155
commit
6e893afd90
5 changed files with 38 additions and 13 deletions
|
@ -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.contrib.auth.models import User
|
||||||
from django.core.validators import MinValueValidator
|
from django.core.validators import MinValueValidator
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
@ -37,14 +41,18 @@ class Profile(models.Model):
|
||||||
default=False, verbose_name=_("conserver la fiche annuaire ?")
|
default=False, verbose_name=_("conserver la fiche annuaire ?")
|
||||||
)
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self) -> str:
|
||||||
return self.full_name
|
return self.full_name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def age(self):
|
def age(self) -> Optional[int]:
|
||||||
return self.day.year - self.birth_date.year
|
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")
|
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
|
max_length=255, verbose_name=_("nom du département"), unique=True
|
||||||
)
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self) -> str:
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,7 +72,7 @@ class Phone(models.Model):
|
||||||
name = models.CharField(max_length=255, verbose_name=_("type"))
|
name = models.CharField(max_length=255, verbose_name=_("type"))
|
||||||
number = models.CharField(max_length=1023, verbose_name=_("numéro"))
|
number = models.CharField(max_length=1023, verbose_name=_("numéro"))
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self) -> str:
|
||||||
return "{} : {}".format(self.name, self.number)
|
return "{} : {}".format(self.name, self.number)
|
||||||
|
|
||||||
|
|
||||||
|
@ -86,7 +94,7 @@ class Mail(models.Model):
|
||||||
name = models.CharField(max_length=255, verbose_name=_("type"))
|
name = models.CharField(max_length=255, verbose_name=_("type"))
|
||||||
mail = models.CharField(max_length=1023, verbose_name=_("adresse mail"))
|
mail = models.CharField(max_length=1023, verbose_name=_("adresse mail"))
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self) -> str:
|
||||||
return "{} : {}".format(self.name, self.mail)
|
return "{} : {}".format(self.name, self.mail)
|
||||||
|
|
||||||
|
|
||||||
|
@ -97,5 +105,5 @@ class Address(models.Model):
|
||||||
name = models.CharField(max_length=255, verbose_name=_("type"))
|
name = models.CharField(max_length=255, verbose_name=_("type"))
|
||||||
content = models.TextField(verbose_name=_("adresse"))
|
content = models.TextField(verbose_name=_("adresse"))
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self) -> str:
|
||||||
return "{} : {}".format(self.name, self.content)
|
return "{} : {}".format(self.name, self.content)
|
||||||
|
|
|
@ -159,7 +159,7 @@ class BirthdayView(ListView):
|
||||||
birth_date__day=today.day, birth_date__month=today.month
|
birth_date__day=today.day, birth_date__month=today.month
|
||||||
).annotate(day=Value(today, output_field=DateTimeField()))
|
).annotate(day=Value(today, output_field=DateTimeField()))
|
||||||
)
|
)
|
||||||
for i in range(1, 7):
|
for _ in range(1, 7):
|
||||||
today = today + timedelta(days=1)
|
today = today + timedelta(days=1)
|
||||||
context["result"] += list(
|
context["result"] += list(
|
||||||
Profile.objects.filter(
|
Profile.objects.filter(
|
||||||
|
|
17
poetry.lock
generated
17
poetry.lock
generated
|
@ -922,6 +922,21 @@ lxml = ">=3.4"
|
||||||
requests = ">=2.11.1"
|
requests = ">=2.11.1"
|
||||||
six = ">=1.10.0"
|
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]]
|
[[package]]
|
||||||
name = "python-ldap"
|
name = "python-ldap"
|
||||||
version = "3.4.3"
|
version = "3.4.3"
|
||||||
|
@ -1123,4 +1138,4 @@ files = [
|
||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "2.0"
|
lock-version = "2.0"
|
||||||
python-versions = "^3.9"
|
python-versions = "^3.9"
|
||||||
content-hash = "fa8b2aeaab01568ad58818d249424dd837df8f7cc89be68522542f1f45c9f5a4"
|
content-hash = "219ac059786c135b45e46fe7f535b750012aa146f18a6a30fddbc0b3889beed2"
|
||||||
|
|
|
@ -10,6 +10,7 @@ python = "^3.9"
|
||||||
Django = "^3.2.0"
|
Django = "^3.2.0"
|
||||||
Pillow = "^9.4.0"
|
Pillow = "^9.4.0"
|
||||||
authens = "^0.1b4"
|
authens = "^0.1b4"
|
||||||
|
python-dateutil = "^2.8.2"
|
||||||
|
|
||||||
[tool.poetry.group.dev.dependencies]
|
[tool.poetry.group.dev.dependencies]
|
||||||
ipython = "^8.9.0"
|
ipython = "^8.9.0"
|
||||||
|
@ -25,6 +26,9 @@ psycopg2 = "^2.9.5"
|
||||||
gunicorn = "^20.1.0"
|
gunicorn = "^20.1.0"
|
||||||
django-redis = "^5.2.0"
|
django-redis = "^5.2.0"
|
||||||
|
|
||||||
|
[tool.isort]
|
||||||
|
profile = "black"
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["poetry-core"]
|
requires = ["poetry-core"]
|
||||||
build-backend = "poetry.core.masonry.api"
|
build-backend = "poetry.core.masonry.api"
|
||||||
|
|
|
@ -11,7 +11,7 @@ print("\nTransfert des fiches annuaires :")
|
||||||
# Configuration
|
# Configuration
|
||||||
print("Paramétrage de Django...", end=" ")
|
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()
|
django.setup()
|
||||||
|
|
||||||
User = get_user_model()
|
User = get_user_model()
|
||||||
|
@ -193,8 +193,6 @@ with open("old_fiches.json") as json_file:
|
||||||
fiche.text_field += f" ({obj_data['source']})"
|
fiche.text_field += f" ({obj_data['source']})"
|
||||||
if obj_data["author"]:
|
if obj_data["author"]:
|
||||||
fiche.text_field += f", ({obj_data['author']})"
|
fiche.text_field += f", ({obj_data['author']})"
|
||||||
if a:
|
|
||||||
adresses.append(Address(profile=fiche, name="Adresse", content=a))
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue