Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
refactor: use fstrings instead of str.format
Browse files Browse the repository at this point in the history
  • Loading branch information
c0rydoras committed Apr 29, 2024
1 parent 9c16448 commit f2c52fc
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 24 deletions.
8 changes: 2 additions & 6 deletions timed/employment/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -228,11 +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"),
self.end_date.strftime("%d.%m.%Y") if self.end_date else "today",
)
return f"{self.user.username} ({self.start_date:%d.%m.%Y} - {(self.end_date or date.today()):%d.%m.%Y})"

def calculate_worktime(
self, start: date, end: date
Expand Down
2 changes: 1 addition & 1 deletion timed/employment/tests/test_worktime_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 1 addition & 6 deletions timed/reports/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 2 additions & 11 deletions timed/tracking/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 f"{self.user}: {self.date:%Y-%m-%d} {self.from_time:%H:%M} - {self.to_time:%H:%M}"


class Report(models.Model):
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit f2c52fc

Please sign in to comment.