display some file sizes
modified: make_post_sell/models/product.py modified: make_post_sell/templates/shop_products.j2 modified: make_post_sell/views/content.py modified: make_post_sell/views/product.py
This commit is contained in:
parent
06617affda
commit
65189452a3
4 changed files with 22 additions and 42 deletions
|
|
@ -58,6 +58,14 @@ DEFAULT_BUNDLE_METADATA = unicode(
|
|||
)
|
||||
|
||||
|
||||
def sizeof_fmt(num, suffix="B"):
|
||||
for unit in ["", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"]:
|
||||
if abs(num) < 1024.0:
|
||||
return f"{num:3.1f}{unit}{suffix}"
|
||||
num /= 1024.0
|
||||
return f"{num:.1f}Yi{suffix}"
|
||||
|
||||
|
||||
class Product(RBase, Base):
|
||||
"""This class represents a product."""
|
||||
|
||||
|
|
@ -278,6 +286,14 @@ class Product(RBase, Base):
|
|||
self.json_file_bytes = json.dumps(new_dict)
|
||||
self.total_file_bytes = sum(self.file_bytes.values())
|
||||
|
||||
@property
|
||||
def human_total_file_bytes(self):
|
||||
return sizeof_fmt(self.total_file_bytes)
|
||||
|
||||
@property
|
||||
def human_product_file_bytes(self):
|
||||
return sizeof_fmt(self.file_bytes["product"])
|
||||
|
||||
@property
|
||||
def extensions(self):
|
||||
return self.file_metadata.get("extensions", {})
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ tr { text-align: left;}
|
|||
|
||||
<table style="width=100%; max-width: 100%; table-layout : fixed;">
|
||||
<thead>
|
||||
<tr> <th> Sellable <th> Price <th> Visibility <th> Bundle <th> Ready <th> Title
|
||||
<tr> <th> Sellable <th> Price <th> Visibility <th> Bundle <th> Ready <th> Title <th> Size
|
||||
<tbody style="width=100%; max-width: 100%;">
|
||||
|
||||
{% for product in products %}
|
||||
|
|
@ -22,6 +22,7 @@ tr { text-align: left;}
|
|||
<td>{{ product.is_bundle }}</td>
|
||||
<td>{{ product.is_ready }}</td>
|
||||
<td><b><a href="{{ product.absolute_url(request) }}">{{ product.title }}</a></b></td>
|
||||
<td>{{ product.human_total_file_bytes }}</td>
|
||||
</tr>
|
||||
|
||||
{% endfor %}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ from pyramid.httpexceptions import HTTPFound
|
|||
def content(request):
|
||||
|
||||
product = request.product
|
||||
product_size = ""
|
||||
|
||||
if not request.is_saas_domain and request.domain != request.shop.domain_name:
|
||||
# The content uuid in the URI matchdict is mismatched with request shop.
|
||||
|
|
@ -65,29 +64,9 @@ def content(request):
|
|||
ExpiresIn=900
|
||||
)
|
||||
|
||||
#t = request.secure_uploads_client.get_object_torrent(
|
||||
# Bucket=bucket_name,
|
||||
# Key=product.s3_key,
|
||||
#)
|
||||
|
||||
product_size = ""
|
||||
if product.has_product_file:
|
||||
# get the human readable size of s3 object for product.
|
||||
|
||||
response = request.secure_uploads_client.head_object(
|
||||
Bucket=bucket_name,
|
||||
Key=product.s3_key,
|
||||
)
|
||||
|
||||
product_content_length = response["ContentLength"]
|
||||
|
||||
def sizeof_fmt(num, suffix="B"):
|
||||
for unit in ["", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"]:
|
||||
if abs(num) < 1024.0:
|
||||
return f"{num:3.1f}{unit}{suffix}"
|
||||
num /= 1024.0
|
||||
return f"{num:.1f}Yi{suffix}"
|
||||
|
||||
product_size = sizeof_fmt(product_content_length)
|
||||
product_size = product.human_product_file_bytes
|
||||
|
||||
return {
|
||||
"product": product,
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ def checkbox_to_bool(checkbox):
|
|||
def product(request):
|
||||
|
||||
product = request.product
|
||||
product_size = ""
|
||||
|
||||
if not request.is_saas_domain and request.domain != request.shop.domain_name:
|
||||
# The product uuid in the URI matchdict is mismatched with request shop.
|
||||
|
|
@ -77,24 +76,9 @@ def product(request):
|
|||
ExpiresIn=900
|
||||
)
|
||||
|
||||
product_size = ""
|
||||
if product.has_product_file:
|
||||
# get the human readable size of s3 object for product.
|
||||
|
||||
response = request.secure_uploads_client.head_object(
|
||||
Bucket=bucket_name,
|
||||
Key=product.s3_key,
|
||||
)
|
||||
|
||||
product_content_length = response["ContentLength"]
|
||||
|
||||
def sizeof_fmt(num, suffix="B"):
|
||||
for unit in ["", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"]:
|
||||
if abs(num) < 1024.0:
|
||||
return f"{num:3.1f}{unit}{suffix}"
|
||||
num /= 1024.0
|
||||
return f"{num:.1f}Yi{suffix}"
|
||||
|
||||
product_size = sizeof_fmt(product_content_length)
|
||||
product_size = product.human_product_file_bytes
|
||||
|
||||
return {
|
||||
"product": product,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue