From 0413c1c5abacc0ce7fedad57bc1af9a0c1fe3298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniele=20Vigan=C3=B2?= Date: Mon, 20 Jan 2025 18:24:20 +0100 Subject: [PATCH] Add a draft tag to unpublished items and minor improvements (#46) * Add a draft tag to unpublished items * Add X-Cache-Hit header * Expose decoder interface in roster cards * Manage decoder interface set to None --- ram/portal/templates/bookshelf/book.html | 14 +++++++----- ram/portal/templates/cards/book.html | 14 +++++++----- ram/portal/templates/cards/company.html | 8 ++++--- ram/portal/templates/cards/consist.html | 11 +++++++--- ram/portal/templates/cards/roster.html | 23 +++++++++++++++----- ram/portal/templates/consist.html | 11 +++++++--- ram/portal/templates/flatpages/flatpage.html | 7 ++++++ ram/portal/templates/rollingstock.html | 15 ++++++++----- ram/ram/__init__.py | 2 +- ram/ram/middleware.py | 11 +++++++++- ram/roster/models.py | 10 ++++++++- 11 files changed, 93 insertions(+), 33 deletions(-) diff --git a/ram/portal/templates/bookshelf/book.html b/ram/portal/templates/bookshelf/book.html index 47be5c6..05661d7 100644 --- a/ram/portal/templates/bookshelf/book.html +++ b/ram/portal/templates/bookshelf/book.html @@ -59,11 +59,15 @@ - {% if type == "catalog" %} - - {% elif type == "book" %} - - {% endif %} + diff --git a/ram/portal/templates/cards/book.html b/ram/portal/templates/cards/book.html index 895e107..e3eec4a 100644 --- a/ram/portal/templates/cards/book.html +++ b/ram/portal/templates/cards/book.html @@ -23,11 +23,15 @@
CatalogBook + {% if type == "catalog" %}Catalog + {% elif type == "book" %}Book{% endif %} +
+ {% if not book.published %} + Draft + {% endif %} +
+
- {% if d.type == "catalog" %} - - {% elif d.type == "book" %} - - {% endif %} + diff --git a/ram/portal/templates/cards/company.html b/ram/portal/templates/cards/company.html index 7b4d171..9467c79 100644 --- a/ram/portal/templates/cards/company.html +++ b/ram/portal/templates/cards/company.html @@ -9,9 +9,11 @@ diff --git a/ram/portal/templates/cards/consist.html b/ram/portal/templates/cards/consist.html index aa632d5..3af1cc0 100644 --- a/ram/portal/templates/cards/consist.html +++ b/ram/portal/templates/cards/consist.html @@ -26,9 +26,14 @@ diff --git a/ram/portal/templates/cards/roster.html b/ram/portal/templates/cards/roster.html index 4b7785d..544cba4 100644 --- a/ram/portal/templates/cards/roster.html +++ b/ram/portal/templates/cards/roster.html @@ -24,9 +24,14 @@ @@ -38,7 +43,7 @@ @@ -69,7 +74,7 @@
CatalogBook + {% if d.type == "catalog" %}Catalog + {% elif d.type == "book" %}Book{% endif %} +
+ {% if not d.item.published %} + Draft + {% endif %} +
+
Company - {% if d.item.freelance %} - Freelance - {% endif %} +
+ {% if d.item.freelance %} + Freelance + {% endif %} +
Consist - {% if d.item.company.freelance %} - Freelance - {% endif %} +
+ {% if d.item.company.freelance %} + Freelance + {% endif %} + {% if not d.item.published %} + Draft + {% endif %} +
Rolling stock - {% if d.item.rolling_class.company.freelance %} - Freelance - {% endif %} +
+ {% if d.item.company.freelance %} + Freelance + {% endif %} + {% if not d.item.published %} + Draft + {% endif %} +
Company - {{ d.item.rolling_class.company }} + {{ d.item.company }}
- {% if d.item.decoder %} + {% if d.item.decoder or d.item.decoder_interface %} @@ -78,13 +83,19 @@ - + + + + {% if d.item.decoder %} + + + {% endif %}
DecoderInterface{{ d.item.get_decoder_interface }}
Decoder {{ d.item.decoder }}
Address {{ d.item.address }}
{% endif %} diff --git a/ram/portal/templates/consist.html b/ram/portal/templates/consist.html index 0c6786f..7bb77ca 100644 --- a/ram/portal/templates/consist.html +++ b/ram/portal/templates/consist.html @@ -81,9 +81,14 @@ Consist - {% if consist.company.freelance %} - Freelance - {% endif %} +
+ {% if consist.company.freelance %} + Freelance + {% endif %} + {% if not consist.published %} + Draft + {% endif %} +
diff --git a/ram/portal/templates/flatpages/flatpage.html b/ram/portal/templates/flatpages/flatpage.html index 001e68a..418fb01 100644 --- a/ram/portal/templates/flatpages/flatpage.html +++ b/ram/portal/templates/flatpages/flatpage.html @@ -3,10 +3,17 @@ {% block header %} Updated {{ flatpage.updated_time | date:"M d, Y H:i" }} {% endblock %} + {% block carousel %} + {% endblock %} {% block extra_content %}
+ {% if not flatpage.published %} + + {% endif %}
{{ flatpage.content | safe }}
{% if request.user.is_staff %}Edit{% endif %} diff --git a/ram/portal/templates/rollingstock.html b/ram/portal/templates/rollingstock.html index ef85902..d40818d 100644 --- a/ram/portal/templates/rollingstock.html +++ b/ram/portal/templates/rollingstock.html @@ -75,9 +75,14 @@ Rolling stock - {% if company.freelance %} - Freelance - {% endif %} +
+ {% if company.freelance %} + Freelance + {% endif %} + {% if not rolling_stock.published %} + Draft + {% endif %} +
@@ -145,7 +150,7 @@ Interface - {{ rolling_stock.get_decoder_interface_display }} + {{ rolling_stock.get_decoder_interface }} {% if rolling_stock.decoder %} @@ -332,7 +337,7 @@ Interface - {{ rolling_stock.get_decoder_interface_display }} + {{ rolling_stock.get_decoder_interface }} Address diff --git a/ram/ram/__init__.py b/ram/ram/__init__.py index c0f1206..a070a7e 100644 --- a/ram/ram/__init__.py +++ b/ram/ram/__init__.py @@ -1,4 +1,4 @@ from ram.utils import git_suffix -__version__ = "0.16.2" +__version__ = "0.16.3" __version__ += git_suffix(__file__) diff --git a/ram/ram/middleware.py b/ram/ram/middleware.py index b6e3012..beed49d 100644 --- a/ram/ram/middleware.py +++ b/ram/ram/middleware.py @@ -1,4 +1,5 @@ -from django.utils.cache import add_never_cache_headers +from django.core.cache import cache +from django.utils.cache import add_never_cache_headers, get_cache_key class DisableClientSideCachingMiddleware: @@ -7,5 +8,13 @@ class DisableClientSideCachingMiddleware: def __call__(self, request): response = self.get_response(request) + + # Check if the cache key exists for this request + cache_key = get_cache_key(request) + cache_hit = "MISS" + if cache_key and cache.get(cache_key): + cache_hit = "HIT" + response['X-Cache-Hit'] = cache_hit + add_never_cache_headers(response) return response diff --git a/ram/roster/models.py b/ram/roster/models.py index e40872c..af26726 100644 --- a/ram/roster/models.py +++ b/ram/roster/models.py @@ -129,13 +129,21 @@ class RollingStock(BaseModel): def preview(self): return self.image.first().image_thumbnail(350) + # similar to get_decoder_interface_display in template render, + # but returns "-" if no decoder interface is set + def get_decoder_interface(self): + return str( + dict(settings.DECODER_INTERFACES).get(self.decoder_interface) + or "-" + ) + @property def country(self): return self.rolling_class.company.country @property def company(self): - return str(self.rolling_class.company) + return self.rolling_class.company def delete(self, *args, **kwargs): shutil.rmtree(