mirror of
https://github.com/daniviga/django-ram.git
synced 2026-02-28 05:32:28 +01:00
Code refactoring to simplify template data contexts (#55)
* Fix a search filter when no catalogs are returned * Code refactoring to simplify templates * Remove duplicated code * Remove dead code * More improvements, clean up and add featured items in homepage * Fix a type and better page navigation
This commit is contained in:
@@ -2,37 +2,37 @@
|
||||
{% load dynamic_url %}
|
||||
<div class="col">
|
||||
<div class="card shadow-sm">
|
||||
{% if d.type == "magazine" %}
|
||||
<a href="{{ d.item.get_absolute_url }}">
|
||||
{% if d.item.image and d.type == "magazine" %}
|
||||
<img class="card-img-top" src="{{ d.item.image.url }}" alt="{{ d.item }}">
|
||||
{% elif d.item.issue.first.image.exists %}
|
||||
{% with d.item.issue.first as i %}
|
||||
<img class="card-img-top" src="{{ i.image.first.image.url }}" alt="{{ d.item }}">
|
||||
{% if d.obj_type == "magazine" %}
|
||||
<a href="{{ d.get_absolute_url }}">
|
||||
{% if d.image and d.obj_type == "magazine" %}
|
||||
<img class="card-img-top" src="{{ d.image.url }}" alt="{{ d }}">
|
||||
{% elif d.issue.first.image.exists %}
|
||||
{% with d.issue.first as i %}
|
||||
<img class="card-img-top" src="{{ i.image.first.image.url }}" alt="{{ d }}">
|
||||
{% endwith %}
|
||||
{% else %}
|
||||
<!-- Do not show the "Coming soon" image when running in a single card column mode (e.g. on mobile) -->
|
||||
<img class="card-img-top d-none d-sm-block" src="{% static DEFAULT_CARD_IMAGE %}" alt="{{ d.item }}">
|
||||
<img class="card-img-top d-none d-sm-block" src="{% static DEFAULT_CARD_IMAGE %}" alt="{{ d }}">
|
||||
{% endif %}
|
||||
</a>
|
||||
{% elif d.type == "magazineissue" %}
|
||||
<a href="{{ d.item.get_absolute_url }}">
|
||||
{% if d.item.image.exists %}
|
||||
<img class="card-img-top" src="{{ d.item.image.first.image.url }}" alt="{{ d.item }}">
|
||||
{% elif d.obj_type == "magazineissue" %}
|
||||
<a href="{{ d.get_absolute_url }}">
|
||||
{% if d.image.exists %}
|
||||
<img class="card-img-top" src="{{ d.image.first.image.url }}" alt="{{ d }}">
|
||||
{% else %}
|
||||
<!-- Do not show the "Coming soon" image when running in a single card column mode (e.g. on mobile) -->
|
||||
<img class="card-img-top d-none d-sm-block" src="{% static DEFAULT_CARD_IMAGE %}" alt="{{ d.item }}">
|
||||
<img class="card-img-top d-none d-sm-block" src="{% static DEFAULT_CARD_IMAGE %}" alt="{{ d }}">
|
||||
{% endif %}
|
||||
</a>
|
||||
{% endif %}
|
||||
</a>
|
||||
<div class="card-body">
|
||||
<p class="card-text" style="position: relative;">
|
||||
<strong>{{ d.item }}</strong>
|
||||
<a class="stretched-link" href="{{ d.item.get_absolute_url }}"></a>
|
||||
<strong>{{ d }}</strong>
|
||||
<a class="stretched-link" href="{{ d.get_absolute_url }}"></a>
|
||||
</p>
|
||||
<p class="card-text"><small>Tags:</small>
|
||||
{% for t in d.item.tags.all %}<a href="{% url 'filtered' _filter="tag" search=t.slug %}" class="badge rounded-pill bg-primary">
|
||||
{% for t in d.tags.all %}<a href="{% url 'filtered' _filter="tag" search=t.slug %}" class="badge rounded-pill bg-primary">
|
||||
{{ t.name }}</a>{# new line is required #}
|
||||
{% empty %}
|
||||
<span class="badge rounded-pill bg-secondary"><i class="bi bi-ban"></i></span>
|
||||
@@ -42,10 +42,10 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2" scope="row">
|
||||
{{ d.label|capfirst }}
|
||||
{{ d.obj_label|capfirst }}
|
||||
|
||||
<div class="float-end">
|
||||
{% if not d.item.published %}
|
||||
{% if not d.published %}
|
||||
<span class="badge text-bg-warning">Unpublished</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
@@ -53,51 +53,51 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-group-divider">
|
||||
{% if d.type == "magazineissue" %}
|
||||
{% if d.obj_type == "magazineissue" %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Magazine</th>
|
||||
<td>{{ d.item.magazine }}</td>
|
||||
<td>{{ d.magazine }}</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Website</th>
|
||||
<td>{% if d.item.website %}<a href="{{ d.item.website }}" target="_blank">{{ d.item.website_short }}</td>{% else %}-{% endif %}</td>
|
||||
<td>{% if d.website %}<a href="{{ d.website }}" target="_blank">{{ d.website_short }}</td>{% else %}-{% endif %}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Publisher</th>
|
||||
<td>
|
||||
<img src="{{ d.item.publisher.country.flag }}" alt="{{ d.item.publisher.country }}"> {{ d.item.publisher }}
|
||||
{% if d.item.publisher.website %} <a href="{{ d.item.publisher.website }}" target="_blank"><i class="bi bi-box-arrow-up-right"></i></a>{% endif %}
|
||||
<img src="{{ d.publisher.country.flag }}" alt="{{ d.publisher.country }}"> {{ d.publisher }}
|
||||
{% if d.publisher.website %} <a href="{{ d.publisher.website }}" target="_blank"><i class="bi bi-box-arrow-up-right"></i></a>{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% if d.type == "magazineissue" %}
|
||||
{% if d.obj_type == "magazineissue" %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Issue</th>
|
||||
<td>{{ d.item.issue_number }}</td>
|
||||
<td>{{ d.issue_number }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Date</th>
|
||||
<td>{{ d.item.publication_year|default:"-" }} / {{ d.item.get_publication_month_display|default:"-" }}</td>
|
||||
<td>{{ d.publication_year|default:"-" }} / {{ d.get_publication_month_display|default:"-" }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Pages</th>
|
||||
<td>{{ d.item.number_of_pages|default:"-" }}</td>
|
||||
<td>{{ d.number_of_pages|default:"-" }}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Language</th>
|
||||
<td>{{ d.item.get_language_display }}</td>
|
||||
<td>{{ d.get_language_display }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="d-grid gap-2 mb-1 d-md-block">
|
||||
{% if d.type == "magazine" %}
|
||||
<a class="btn btn-sm btn-outline-primary{% if d.item.issues == 0 %} disabled{% endif %}" href="{{ d.item.get_absolute_url }}">Show {{ d.item.issues }} issue{{ d.item.issues|pluralize }}</a>
|
||||
{% if d.obj_type == "magazine" %}
|
||||
<a class="btn btn-sm btn-outline-primary{% if d.issues == 0 %} disabled{% endif %}" href="{{ d.get_absolute_url }}">Show {{ d.issues }} issue{{ d.issues|pluralize }}</a>
|
||||
{% else %}
|
||||
<a class="btn btn-sm btn-outline-primary" href="{{ d.item.get_absolute_url }}">Show all data</a>
|
||||
<a class="btn btn-sm btn-outline-primary" href="{{ d.get_absolute_url }}">Show all data</a>
|
||||
{% endif %}
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% dynamic_admin_url 'bookshelf' d.type d.item.pk %}">Edit</a>{% endif %}
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% dynamic_admin_url 'bookshelf' d.obj_type d.pk %}">Edit</a>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user