From c076e60403d2c1895071f846c1b245322ab045f5 Mon Sep 17 00:00:00 2001 From: Wojciech Kwolek Date: Sat, 26 Sep 2020 18:47:22 +0200 Subject: [PATCH] fix accomplishment edit handler --- app/days.py | 15 +++++++++------ app/main.py | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/days.py b/app/days.py index bbbdef2..82ae8ae 100644 --- a/app/days.py +++ b/app/days.py @@ -13,12 +13,15 @@ class Day: @staticmethod def from_str(string, user): - return Day._from_timestamp(datetime.strptime(string, "%Y-%m-%d"), user) + return Day.from_timestamp(datetime.strptime(string, "%Y-%m-%d"), user) @staticmethod - def _from_timestamp(timestamp, user): - # not exposed because it is only an utilty function, not aware of the - # user's time zone and start-of-day hour + def from_timestamp(timestamp, user): + """ + This function is NOT meant to be aware of timezones etc, you should + only use it to handle data stored in the database, in the format of the + output of the ".timestamp" property. + """ return Day(timestamp.year, timestamp.month, timestamp.day, user) def __eq__(self, other): @@ -33,14 +36,14 @@ class Day: raise TypeError( 'Unsupported operands for "+". The right hand side needs to be a number.') else: - return Day._from_timestamp(self.timestamp + timedelta(days=other), self.user) + return Day.from_timestamp(self.timestamp + timedelta(days=other), self.user) def __sub__(self, other): if not isinstance(other, int): raise TypeError( 'Unsupported operands for "-". The right hand side needs to be a number.') else: - return Day._from_timestamp(self.timestamp + timedelta(days=-other), self.user) + return Day.from_timestamp(self.timestamp + timedelta(days=-other), self.user) def __lt__(self, other): return self.timestamp < other.timestamp def __gt__(self, other): return self.timestamp > other.timestamp diff --git a/app/main.py b/app/main.py index ef987cb..9299e55 100644 --- a/app/main.py +++ b/app/main.py @@ -149,7 +149,7 @@ def edit_accomplishment(accomplishment_id): if a.user_id != current_user.id: abort(403) - back_url = url_for('main.edit_day', day=Day.from_str( + back_url = url_for('main.edit_day', day=Day.from_timestamp( a.time, current_user).url) form = EditForm(obj=a)