diff --git a/make_post_sell/templates/product.j2 b/make_post_sell/templates/product.j2 index 5d3dcc2..0694748 100644 --- a/make_post_sell/templates/product.j2 +++ b/make_post_sell/templates/product.j2 @@ -16,7 +16,6 @@ --> {%- endblock append_to_head_tag_section -%} - {%- block call_to_action -%} {% if request.user.can_edit_shop(request.shop) %} ✎ Edit @@ -35,7 +34,6 @@ {{ product.shop.name }} - {% if "thumbnail1" in product.extensions %}
@@ -47,8 +45,7 @@ {% endif %} {% endfor %} - - +
@@ -122,9 +119,10 @@ {% elif product.has_product_file %} File Type
- {{ product.get_content_type("product") }} + {{ product.get_content_type("product") }} {{ product_size }}
Please make sure you have an application to open this file type. + {% endif %}
diff --git a/make_post_sell/views/product.py b/make_post_sell/views/product.py index fc09c46..1976fd0 100644 --- a/make_post_sell/views/product.py +++ b/make_post_sell/views/product.py @@ -74,8 +74,25 @@ def product(request): ExpiresIn=900 ) + response = request.secure_uploads_client.head_object( + Bucket=request.app["bucket.secure_uploads"], + 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) + return { "product": product, + "product_size": product_size, "signed_get_object_url": signed_get_object_url, }