diff --git a/make_post_sell/lib/time_funcs.py b/make_post_sell/lib/time_funcs.py new file mode 100644 index 0000000..092296b --- /dev/null +++ b/make_post_sell/lib/time_funcs.py @@ -0,0 +1,12 @@ +from datetime import datetime +from ago import human + + +def timestamp_to_datetime(timestamp): + """Accepts a milliseconds timestamp integer and returns a datetime""" + return datetime.fromtimestamp(timestamp / 1000.0) + + +def timestamp_to_ago_string(timestamp): + """Accepts a timestamp and returns a human readable string""" + return human(timestamp_to_datetime(timestamp), 2, abbreviate=True) diff --git a/make_post_sell/models/cart.py b/make_post_sell/models/cart.py index 440679c..946ed38 100644 --- a/make_post_sell/models/cart.py +++ b/make_post_sell/models/cart.py @@ -25,7 +25,8 @@ from .cart_coupon import CartCoupon from .inventory import get_inventory_by_product_and_shop_location -from ..lib.currency import cents_to_dollars +from make_post_sell.lib.currency import cents_to_dollars +from make_post_sell.lib.time_funcs import timestamp_to_datetime, timestamp_to_ago_string try: unicode("") @@ -33,20 +34,6 @@ except: from six import u as unicode -def timestamp_to_datetime(timestamp): - """Accepts a milliseconds timestamp integer and returns a datetime""" - from datetime import datetime - - return datetime.fromtimestamp(timestamp / 1000.0) - - -def timestamp_to_ago_string(timestamp): - """Accepts a timestamp and returns a human readable string""" - from ago import human - - return human(timestamp_to_datetime(timestamp), 2, abbreviate=True) - - class Cart(RBase, Base): """This class tracks a User's shopping carts.""" diff --git a/make_post_sell/models/product.py b/make_post_sell/models/product.py index a3b8ea0..c4ac372 100644 --- a/make_post_sell/models/product.py +++ b/make_post_sell/models/product.py @@ -25,6 +25,7 @@ from .user_product import UserProduct from .price import Price from make_post_sell.lib.render import markdown_to_html +from make_post_sell.lib.time_funcs import timestamp_to_datetime, timestamp_to_ago_string from slugify import slugify @@ -153,6 +154,14 @@ class Product(RBase, Base): self.created_timestamp = now_timestamp() self.updated_timestamp = now_timestamp() + @property + def human_updated_timestamp(self): + return timestamp_to_ago_string(self.updated_timestamp) + + @property + def human_created_timestamp(self): + return timestamp_to_ago_string(self.created_timestamp) + def get_userproduct_for_user(self, user): """Given a User object, return the UserProduct object or None.""" for up in self.product_users: diff --git a/make_post_sell/templates/base.j2 b/make_post_sell/templates/base.j2 index 47db2d8..06d1b8a 100644 --- a/make_post_sell/templates/base.j2 +++ b/make_post_sell/templates/base.j2 @@ -1,9 +1,11 @@ -{% if request.product -%} +{% if request.shop -%} {%- endif %} {% if request.product -%} + + {%- endif %}