Fixed date formatting on consolidated sets
This commit is contained in:
@@ -169,6 +169,20 @@ class BrickSet(RebrickableSet):
|
||||
else:
|
||||
return ''
|
||||
|
||||
# Purchase date max formatted for consolidated sets
|
||||
def purchase_date_max_formatted(self, /, *, standard: bool = False) -> str:
|
||||
if hasattr(self.fields, 'purchase_date_max') and self.fields.purchase_date_max is not None:
|
||||
time = datetime.fromtimestamp(self.fields.purchase_date_max)
|
||||
|
||||
if standard:
|
||||
return time.strftime('%Y/%m/%d')
|
||||
else:
|
||||
return time.strftime(
|
||||
current_app.config['PURCHASE_DATE_FORMAT']
|
||||
)
|
||||
else:
|
||||
return ''
|
||||
|
||||
# Purchase price with currency
|
||||
def purchase_price(self, /) -> str:
|
||||
if self.fields.purchase_price is not None:
|
||||
|
||||
@@ -17,6 +17,7 @@ SELECT
|
||||
GROUP_CONCAT("bricktracker_sets"."id", '|') AS "instance_ids",
|
||||
REPLACE(GROUP_CONCAT(DISTINCT "bricktracker_sets"."storage"), ',', '|') AS "storage",
|
||||
MIN("bricktracker_sets"."purchase_date") AS "purchase_date",
|
||||
MAX("bricktracker_sets"."purchase_date") AS "purchase_date_max",
|
||||
REPLACE(GROUP_CONCAT(DISTINCT "bricktracker_sets"."purchase_location"), ',', '|') AS "purchase_location",
|
||||
ROUND(AVG("bricktracker_sets"."purchase_price"), 1) AS "purchase_price"
|
||||
{% block owners %}
|
||||
|
||||
@@ -65,11 +65,22 @@
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro purchase_date(date, solo=false, last=false) %}
|
||||
{% if last %}
|
||||
{% set tooltip=date %}
|
||||
{% macro purchase_date(date, solo=false, last=false, date_max_formatted=none) %}
|
||||
{% if date_max_formatted and date_max_formatted != date %}
|
||||
{# Date range for consolidated sets #}
|
||||
{% set date_range = date ~ ' - ' ~ date_max_formatted %}
|
||||
{% if last %}
|
||||
{% set tooltip=date_range %}
|
||||
{% else %}
|
||||
{% set text=date_range %}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{% set text=date %}
|
||||
{# Single date #}
|
||||
{% if last %}
|
||||
{% set tooltip=date %}
|
||||
{% else %}
|
||||
{% set text=date %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{{ badge(check=date, solo=solo, last=last, color='light border', icon='calendar-line', text=text, tooltip=tooltip, collapsible='Date:') }}
|
||||
{% endmacro %}
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
{% endfor %}
|
||||
{{ badge.storage(item, brickset_storages, solo=solo, last=last) }}
|
||||
{% if not last %}
|
||||
{{ badge.purchase_date(item.purchase_date(), solo=solo, last=last) }}
|
||||
{{ badge.purchase_date(item.purchase_date(), solo=solo, last=last, date_max_formatted=item.purchase_date_max_formatted()) }}
|
||||
{{ badge.purchase_location(item, brickset_purchase_locations, solo=solo, last=last) }}
|
||||
{{ badge.purchase_price(item.purchase_price(), solo=solo, last=last) }}
|
||||
{% if not solo %}
|
||||
|
||||
Reference in New Issue
Block a user