diff --git a/timed/employment/models.py b/timed/employment/models.py index 1aae9a81..7a1856c4 100644 --- a/timed/employment/models.py +++ b/timed/employment/models.py @@ -62,7 +62,7 @@ class Meta: def __str__(self) -> str: """Represent the model as a string.""" - return "{} {}".format(self.name, self.date.strftime("%Y")) + return f"{self.name} {self.date:%Y}" class AbsenceType(models.Model): @@ -228,9 +228,7 @@ class Meta: def __str__(self) -> str: """Represent the model as a string.""" - return "{} ({} - {})".format( - self.user.username, - self.start_date.strftime("%d.%m.%Y"), + return f"{self.user.username} ({self.start_date:%d.%m.%Y} - {{}})".format( self.end_date.strftime("%d.%m.%Y") if self.end_date else "today", ) diff --git a/timed/employment/tests/test_worktime_balance.py b/timed/employment/tests/test_worktime_balance.py index da4c4223..5f055433 100644 --- a/timed/employment/tests/test_worktime_balance.py +++ b/timed/employment/tests/test_worktime_balance.py @@ -86,7 +86,7 @@ def test_worktime_balance_with_employments(auth_client, django_assert_num_querie url = reverse( "worktime-balance-detail", - args=["{}_{}".format(auth_client.user.id, end_date.strftime("%Y-%m-%d"))], + args=[f"{auth_client.user.id}_{end_date:%Y-%m-%d}"], ) with django_assert_num_queries(11): diff --git a/timed/reports/views.py b/timed/reports/views.py index 5f724fa7..8b259cc0 100644 --- a/timed/reports/views.py +++ b/timed/reports/views.py @@ -299,12 +299,7 @@ def _generate_workreport_name(self, from_date: date, project: Project) -> str: whereas YYMM is year and month of from_date and YYYYMMDD is date when work reports gets created. """ - return "{}-{}-{}-{}.ods".format( - from_date.strftime("%y%m"), - date.today().strftime("%Y%m%d"), - self._clean_filename(project.customer.name), - self._clean_filename(project.name), - ) + return f"{from_date:%y%m}-{date.today():%Y%m%d}-{self._clean_filename(project.customer.name)}-{self._clean_filename(project.name)}.ods" def _create_workreport( # noqa: PLR0913 self, diff --git a/timed/tracking/models.py b/timed/tracking/models.py index 329d41f9..9b8b74f4 100644 --- a/timed/tracking/models.py +++ b/timed/tracking/models.py @@ -65,12 +65,7 @@ class Attendance(models.Model): def __str__(self) -> str: """Represent the model as a string.""" - return "{}: {} {} - {}".format( - self.user, - self.date.strftime("%Y-%m-%d"), - self.from_time.strftime("%H:%M"), - self.to_time.strftime("%H:%M"), - ) + return "{self.user}: {self.date:%Y-%m-%d} {self.from_time:%H:%M} - {self.to_time:%H:%M}" class Report(models.Model): @@ -149,11 +144,7 @@ class Meta: def __str__(self) -> str: """Represent the model as a string.""" - return "{}: {} {}".format( - self.user, - self.date.strftime("%Y-%m-%d"), - self.comment, - ) + return f"{self.user}: {self.date:%Y-%m-%d} {self.comment}" def calculate_duration(self, employment: Employment) -> timedelta: """Calculate duration of absence with given employment.