fix accomplishment edit handler

This commit is contained in:
Wojciech Kwolek 2020-09-26 18:47:22 +02:00
parent ccaa2807bd
commit c076e60403
2 changed files with 10 additions and 7 deletions

View File

@ -13,12 +13,15 @@ class Day:
@staticmethod @staticmethod
def from_str(string, user): 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 @staticmethod
def _from_timestamp(timestamp, user): 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 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) return Day(timestamp.year, timestamp.month, timestamp.day, user)
def __eq__(self, other): def __eq__(self, other):
@ -33,14 +36,14 @@ class Day:
raise TypeError( raise TypeError(
'Unsupported operands for "+". The right hand side needs to be a number.') 'Unsupported operands for "+". The right hand side needs to be a number.')
else: 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): def __sub__(self, other):
if not isinstance(other, int): if not isinstance(other, int):
raise TypeError( raise TypeError(
'Unsupported operands for "-". The right hand side needs to be a number.') 'Unsupported operands for "-". The right hand side needs to be a number.')
else: 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 __lt__(self, other): return self.timestamp < other.timestamp
def __gt__(self, other): return self.timestamp > other.timestamp def __gt__(self, other): return self.timestamp > other.timestamp

View File

@ -149,7 +149,7 @@ def edit_accomplishment(accomplishment_id):
if a.user_id != current_user.id: if a.user_id != current_user.id:
abort(403) 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) a.time, current_user).url)
form = EditForm(obj=a) form = EditForm(obj=a)