Make it possible to see created ago and updated ago as HTML comments
new file: make_post_sell/lib/time_funcs.py modified: make_post_sell/models/cart.py modified: make_post_sell/models/product.py modified: make_post_sell/templates/base.j2
This commit is contained in:
parent
5de3af5469
commit
29d9128502
4 changed files with 26 additions and 16 deletions
12
make_post_sell/lib/time_funcs.py
Normal file
12
make_post_sell/lib/time_funcs.py
Normal file
|
|
@ -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)
|
||||
|
|
@ -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."""
|
||||
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
{% if request.product -%}
|
||||
{% if request.shop -%}
|
||||
<!--shop_id={{ request.shop.id }}-->
|
||||
{%- endif %}
|
||||
{% if request.product -%}
|
||||
<!--product_id={{ request.product.id }}-->
|
||||
<!--product_created={{ request.product.human_created_timestamp }}-->
|
||||
<!--product_updated={{ request.product.human_updated_timestamp }}-->
|
||||
{%- endif %}
|
||||
<html lang="en" data-theme="{{ request.html_data_theme or 'dark' }}">
|
||||
<head>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue