mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 05:07:50 +02:00
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
This commit is contained in:
@@ -59,11 +59,15 @@
|
|||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
{% if type == "catalog" %}
|
<th colspan="2" scope="row">
|
||||||
<th colspan="2" scope="row">Catalog</th>
|
{% if type == "catalog" %}Catalog
|
||||||
{% elif type == "book" %}
|
{% elif type == "book" %}Book{% endif %}
|
||||||
<th colspan="2" scope="row">Book</th>
|
<div class="float-end">
|
||||||
{% endif %}
|
{% if not book.published %}
|
||||||
|
<span class="badge text-bg-warning">Draft</span>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody class="table-group-divider">
|
<tbody class="table-group-divider">
|
||||||
|
@@ -23,11 +23,15 @@
|
|||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
{% if d.type == "catalog" %}
|
<th colspan="2" scope="row">
|
||||||
<th colspan="2" scope="row">Catalog</th>
|
{% if d.type == "catalog" %}Catalog
|
||||||
{% elif d.type == "book" %}
|
{% elif d.type == "book" %}Book{% endif %}
|
||||||
<th colspan="2" scope="row">Book</th>
|
<div class="float-end">
|
||||||
{% endif %}
|
{% if not d.item.published %}
|
||||||
|
<span class="badge text-bg-warning">Draft</span>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody class="table-group-divider">
|
<tbody class="table-group-divider">
|
||||||
|
@@ -9,9 +9,11 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th colspan="2" scope="row">
|
<th colspan="2" scope="row">
|
||||||
Company
|
Company
|
||||||
{% if d.item.freelance %}
|
<div class="float-end">
|
||||||
<span class="mt-1 float-end badge text-bg-secondary">Freelance</span>
|
{% if d.item.freelance %}
|
||||||
{% endif %}
|
<span class="badge text-bg-secondary">Freelance</span>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
@@ -26,9 +26,14 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th colspan="2" scope="row">
|
<th colspan="2" scope="row">
|
||||||
Consist
|
Consist
|
||||||
{% if d.item.company.freelance %}
|
<div class="float-end">
|
||||||
<span class="mt-1 float-end badge text-bg-secondary">Freelance</span>
|
{% if d.item.company.freelance %}
|
||||||
{% endif %}
|
<span class="badge text-bg-secondary">Freelance</span>
|
||||||
|
{% endif %}
|
||||||
|
{% if not d.item.published %}
|
||||||
|
<span class="badge text-bg-warning">Draft</span>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
@@ -24,9 +24,14 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th colspan="2" scope="row">
|
<th colspan="2" scope="row">
|
||||||
Rolling stock
|
Rolling stock
|
||||||
{% if d.item.rolling_class.company.freelance %}
|
<div class="float-end">
|
||||||
<span class="mt-1 float-end badge text-bg-secondary">Freelance</span>
|
{% if d.item.company.freelance %}
|
||||||
{% endif %}
|
<span class="badge text-bg-secondary">Freelance</span>
|
||||||
|
{% endif %}
|
||||||
|
{% if not d.item.published %}
|
||||||
|
<span class="badge text-bg-warning">Draft</span>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -38,7 +43,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Company</th>
|
<th scope="row">Company</th>
|
||||||
<td>
|
<td>
|
||||||
<a href="{% url 'filtered' _filter="company" search=d.item.rolling_class.company.slug %}"><abbr title="{{ d.item.rolling_class.company.extended_name }}">{{ d.item.rolling_class.company }}</abbr></a>
|
<a href="{% url 'filtered' _filter="company" search=d.item.company.slug %}"><abbr title="{{ d.item.company.extended_name }}">{{ d.item.company }}</abbr></a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -69,7 +74,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
{% if d.item.decoder %}
|
{% if d.item.decoder or d.item.decoder_interface %}
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -78,13 +83,19 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody class="table-group-divider">
|
<tbody class="table-group-divider">
|
||||||
<tr>
|
<tr>
|
||||||
<th class="w-33" scope="row">Decoder</th>
|
<th class="w-33" scope="row">Interface</th>
|
||||||
|
<td>{{ d.item.get_decoder_interface }}</td>
|
||||||
|
</tr>
|
||||||
|
{% if d.item.decoder %}
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Decoder</th>
|
||||||
<td>{{ d.item.decoder }}</td>
|
<td>{{ d.item.decoder }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Address</th>
|
<th scope="row">Address</th>
|
||||||
<td>{{ d.item.address }}</td>
|
<td>{{ d.item.address }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{% endif %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@@ -81,9 +81,14 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th colspan="2" scope="row">
|
<th colspan="2" scope="row">
|
||||||
Consist
|
Consist
|
||||||
{% if consist.company.freelance %}
|
<div class="float-end">
|
||||||
<span class="mt-1 float-end badge text-bg-secondary">Freelance</span>
|
{% if consist.company.freelance %}
|
||||||
{% endif %}
|
<span class="badge text-bg-secondary">Freelance</span>
|
||||||
|
{% endif %}
|
||||||
|
{% if not consist.published %}
|
||||||
|
<span class="badge text-bg-warning">Draft</span>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
@@ -3,10 +3,17 @@
|
|||||||
{% block header %}
|
{% block header %}
|
||||||
<small class="text-muted">Updated {{ flatpage.updated_time | date:"M d, Y H:i" }}</small>
|
<small class="text-muted">Updated {{ flatpage.updated_time | date:"M d, Y H:i" }}</small>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
{% block carousel %}
|
||||||
|
{% endblock %}
|
||||||
{% block extra_content %}
|
{% block extra_content %}
|
||||||
<section class="py-4 text-start container">
|
<section class="py-4 text-start container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="mx-auto">
|
<div class="mx-auto">
|
||||||
|
{% if not flatpage.published %}
|
||||||
|
<div class="alert alert-warning" role="alert">
|
||||||
|
⚠️ This page is a <strong>draft</strong> and is not published.
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
<div>{{ flatpage.content | safe }} </div>
|
<div>{{ flatpage.content | safe }} </div>
|
||||||
<div class="d-grid gap-2 d-md-flex justify-content-md-end">
|
<div class="d-grid gap-2 d-md-flex justify-content-md-end">
|
||||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:portal_flatpage_change' flatpage.pk %}">Edit</a>{% endif %}
|
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:portal_flatpage_change' flatpage.pk %}">Edit</a>{% endif %}
|
||||||
|
@@ -75,9 +75,14 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th colspan="2" scope="row">
|
<th colspan="2" scope="row">
|
||||||
Rolling stock
|
Rolling stock
|
||||||
{% if company.freelance %}
|
<div class="mt-1 float-end">
|
||||||
<span class="mt-1 float-end badge text-bg-secondary">Freelance</span>
|
{% if company.freelance %}
|
||||||
{% endif %}
|
<span class="badge text-bg-secondary">Freelance</span>
|
||||||
|
{% endif %}
|
||||||
|
{% if not rolling_stock.published %}
|
||||||
|
<span class="badge text-bg-warning">Draft</span>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -145,7 +150,7 @@
|
|||||||
<tbody class="table-group-divider">
|
<tbody class="table-group-divider">
|
||||||
<tr>
|
<tr>
|
||||||
<th class="w-33" scope="row">Interface</th>
|
<th class="w-33" scope="row">Interface</th>
|
||||||
<td>{{ rolling_stock.get_decoder_interface_display }}</td>
|
<td>{{ rolling_stock.get_decoder_interface }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% if rolling_stock.decoder %}
|
{% if rolling_stock.decoder %}
|
||||||
<tr>
|
<tr>
|
||||||
@@ -332,7 +337,7 @@
|
|||||||
<tbody class="table-group-divider">
|
<tbody class="table-group-divider">
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Interface</th>
|
<th scope="row">Interface</th>
|
||||||
<td>{{ rolling_stock.get_decoder_interface_display }}</td>
|
<td>{{ rolling_stock.get_decoder_interface }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="w-33" scope="row">Address</th>
|
<th class="w-33" scope="row">Address</th>
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
from ram.utils import git_suffix
|
from ram.utils import git_suffix
|
||||||
|
|
||||||
__version__ = "0.16.2"
|
__version__ = "0.16.3"
|
||||||
__version__ += git_suffix(__file__)
|
__version__ += git_suffix(__file__)
|
||||||
|
@@ -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:
|
class DisableClientSideCachingMiddleware:
|
||||||
@@ -7,5 +8,13 @@ class DisableClientSideCachingMiddleware:
|
|||||||
|
|
||||||
def __call__(self, request):
|
def __call__(self, request):
|
||||||
response = self.get_response(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)
|
add_never_cache_headers(response)
|
||||||
return response
|
return response
|
||||||
|
@@ -129,13 +129,21 @@ class RollingStock(BaseModel):
|
|||||||
def preview(self):
|
def preview(self):
|
||||||
return self.image.first().image_thumbnail(350)
|
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
|
@property
|
||||||
def country(self):
|
def country(self):
|
||||||
return self.rolling_class.company.country
|
return self.rolling_class.company.country
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def company(self):
|
def company(self):
|
||||||
return str(self.rolling_class.company)
|
return self.rolling_class.company
|
||||||
|
|
||||||
def delete(self, *args, **kwargs):
|
def delete(self, *args, **kwargs):
|
||||||
shutil.rmtree(
|
shutil.rmtree(
|
||||||
|
Reference in New Issue
Block a user