Skip to content

Commit 00b714d

Browse files
Changed pretty_date to handle empty input argument (#851) (#856)
* Added an empty arg check to pretty_date. Should probably never happen, though was getting an fatal error for what should be a minor data quality issue. * Based on PR feedback removed default None value (function typically expects one). Renamed function parameter 'time' to avoid any clashes with time std module. Added created_at value to admin user in test database to avoid original issue. Co-authored-by: James Beard <[email protected]>
1 parent b26dd73 commit 00b714d

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

lib/utilities.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,15 @@ def generate_digest_from_dictionary(values):
138138

139139

140140
# Adapted from http://stackoverflow.com/questions/1551382/python-user-friendly-time-format
141-
def pretty_date(time=False):
141+
def pretty_date(pdate):
142142
"""
143143
Expects a datetime in utc.
144144
"""
145+
if pdate is None:
146+
return ''
147+
145148
now = utcnow()
146-
diff = now - time
149+
diff = now - pdate
147150
second_diff = diff.seconds
148151
day_diff = diff.days
149152

setup/db-fixtures.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
-- auth_secret for local testing: dummy-secret
44
INSERT INTO `user` (`name`, `disable_notifications`, `created_at`) VALUES ('mltshp', 1, now());
55
-- password for "admin" is "password" if you're using the local testing auth_secret key
6-
INSERT INTO `user` (`name`, `hashed_password`, `email`, `full_name`, `email_confirmed`, `is_paid`, `stripe_plan_id`)
7-
VALUES ('admin', '9bbdccf408a2420e20fcd157c6315d5f77427c64', '[email protected]', 'Site Admin', 1, 1, 'mltshp-double');
6+
INSERT INTO `user` (`name`, `hashed_password`, `email`, `full_name`, `email_confirmed`, `is_paid`, `stripe_plan_id`, `created_at`)
7+
VALUES ('admin', '9bbdccf408a2420e20fcd157c6315d5f77427c64', '[email protected]', 'Site Admin', 1, 1, 'mltshp-double', now());
88

99
INSERT INTO `shake` (`user_id`, `type`, `name`) VALUES (1, 'user', 'Best of MLTSHP');
1010
INSERT INTO `shake` (`user_id`, `type`) VALUES (2, 'user');

0 commit comments

Comments
 (0)