mirror of
https://github.com/daniviga/django-ram.git
synced 2025-12-26 15:28:31 +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,23 +2,23 @@
|
||||
{% load dynamic_url %}
|
||||
|
||||
{% block header %}
|
||||
{% if book.tags.all %}
|
||||
{% if data.tags.all %}
|
||||
<p><small>Tags:</small>
|
||||
{% for t in book.tags.all %}<a href="{% url 'filtered' _filter="tag" search=t.slug %}" class="badge rounded-pill bg-primary">
|
||||
{% for t in data.tags.all %}<a href="{% url 'filtered' _filter="tag" search=t.slug %}" class="badge rounded-pill bg-primary">
|
||||
{{ t.name }}</a>{# new line is required #}
|
||||
{% endfor %}
|
||||
</p>
|
||||
{% endif %}
|
||||
{% if not book.published %}
|
||||
{% if not data.published %}
|
||||
<span class="badge text-bg-warning">Unpublished</span> |
|
||||
{% endif %}
|
||||
<small class="text-body-secondary">Updated {{ book.updated_time | date:"M d, Y H:i" }}</small>
|
||||
<small class="text-body-secondary">Updated {{ data.updated_time | date:"M d, Y H:i" }}</small>
|
||||
{% endblock %}
|
||||
{% block carousel %}
|
||||
<div class="row">
|
||||
<div id="carouselControls" class="carousel carousel-dark slide" data-bs-ride="carousel" data-bs-interval="10000">
|
||||
<div class="carousel-inner">
|
||||
{% for t in book.image.all %}
|
||||
{% for t in data.image.all %}
|
||||
{% if forloop.first %}
|
||||
<div class="carousel-item active">
|
||||
{% else %}
|
||||
@@ -28,7 +28,7 @@
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% if book.image.count > 1 %}
|
||||
{% if data.image.count > 1 %}
|
||||
<button class="carousel-control-prev" type="button" data-bs-target="#carouselControls" data-bs-slide="prev">
|
||||
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
|
||||
<span class="visually-hidden"><i class="bi bi-chevron-left"></i></span>
|
||||
@@ -61,86 +61,86 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2" scope="row">
|
||||
{{ label|capfirst }}
|
||||
{{ data.obj_label|capfirst }}
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-group-divider">
|
||||
{% if type == "catalog" %}
|
||||
{% if data.obj_type == "catalog" %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Manufacturer</th>
|
||||
<td>
|
||||
<a href="{% url 'filtered' _filter="manufacturer" search=book.manufacturer.slug %}">{{ book.manufacturer }}{% if book.manufacturer.website %}</a> <a href="{{ book.manufacturer.website }}" target="_blank"><i class="bi bi-box-arrow-up-right"></i></a>{% endif %}
|
||||
<a href="{% url 'filtered' _filter="manufacturer" search=data.manufacturer.slug %}">{{ data.manufacturer }}{% if data.manufacturer.website %}</a> <a href="{{ data.manufacturer.website }}" target="_blank"><i class="bi bi-box-arrow-up-right"></i></a>{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Scales</th>
|
||||
<td>{{ book.get_scales }}</td>
|
||||
<td>{{ data.get_scales }}</td>
|
||||
</tr>
|
||||
{% elif type == "book" %}
|
||||
{% elif data.obj_type == "book" %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Title</th>
|
||||
<td>{{ book.title }}</td>
|
||||
<td>{{ data.title }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Authors</th>
|
||||
<td>
|
||||
<ul class="mb-0 list-unstyled">{% for a in book.authors.all %}<li>{{ a }}</li>{% endfor %}</ul>
|
||||
<ul class="mb-0 list-unstyled">{% for a in data.authors.all %}<li>{{ a }}</li>{% endfor %}</ul>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Publisher</th>
|
||||
<td>
|
||||
<img src="{{ book.publisher.country.flag }}" alt="{{ book.publisher.country }}"> {{ book.publisher }}
|
||||
{% if book.publisher.website %} <a href="{{ book.publisher.website }}" target="_blank"><i class="bi bi-box-arrow-up-right"></i></a>{% endif %}
|
||||
<img src="{{ data.publisher.country.flag }}" alt="{{ data.publisher.country }}"> {{ data.publisher }}
|
||||
{% if data.publisher.website %} <a href="{{ data.publisher.website }}" target="_blank"><i class="bi bi-box-arrow-up-right"></i></a>{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% elif type == "magazineissue" %}
|
||||
{% elif data.obj_type == "magazineissue" %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Magazine</th>
|
||||
<td>
|
||||
<a href="{% url 'magazine' book.magazine.pk %}">{{ book.magazine }}</a>
|
||||
{% if book.magazine.website %} <a href="{{ book.magazine.website }}" target="_blank"><i class="bi bi-box-arrow-up-right"></i></a>{% endif %}
|
||||
<a href="{% url 'magazine' data.magazine.pk %}">{{ data.magazine }}</a>
|
||||
{% if data.magazine.website %} <a href="{{ data.magazine.website }}" target="_blank"><i class="bi bi-box-arrow-up-right"></i></a>{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Publisher</th>
|
||||
<td>
|
||||
<img src="{{ book.publisher.country.flag }}" alt="{{ book.publisher.country }}"> {{ book.publisher }}
|
||||
{% if book.publisher.website %} <a href="{{ book.publisher.website }}" target="_blank"><i class="bi bi-box-arrow-up-right"></i></a>{% endif %}
|
||||
<img src="{{ data.publisher.country.flag }}" alt="{{ data.publisher.country }}"> {{ data.publisher }}
|
||||
{% if data.publisher.website %} <a href="{{ data.publisher.website }}" target="_blank"><i class="bi bi-box-arrow-up-right"></i></a>{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Issue</th>
|
||||
<td>{{ book.issue_number }}</td>
|
||||
<td>{{ data.issue_number }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Date</th>
|
||||
<td>{{ book.publication_year|default:"-" }} / {{ book.get_publication_month_display|default:"-" }}</td>
|
||||
<td>{{ data.publication_year|default:"-" }} / {{ data.get_publication_month_display|default:"-" }}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<tr>
|
||||
<th scope="row">ISBN</th>
|
||||
<td>{{ book.ISBN|default:"-" }}</td>
|
||||
<td>{{ data.ISBN|default:"-" }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Language</th>
|
||||
<td>{{ book.get_language_display }}</td>
|
||||
<td>{{ data.get_language_display }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Number of pages</th>
|
||||
<td>{{ book.number_of_pages|default:"-" }}</td>
|
||||
<td>{{ data.number_of_pages|default:"-" }}</td>
|
||||
</tr>
|
||||
{% if type == "boook" or type == "catalog" %}
|
||||
{% if data.obj_type == "book" or data.obj_type == "catalog" %}
|
||||
<tr>
|
||||
<th scope="row">Publication year</th>
|
||||
<td>{{ book.publication_year|default:"-" }}</td>
|
||||
<td>{{ data.publication_year|default:"-" }}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if book.description %}
|
||||
{% if data.description %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Description</th>
|
||||
<td>{{ book.description | safe }}</td>
|
||||
<td>{{ data.description | safe }}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
</tbody>
|
||||
@@ -156,17 +156,17 @@
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Shop</th>
|
||||
<td>
|
||||
{{ book.shop|default:"-" }}
|
||||
{% if book.shop.website %} <a href="{{ book.shop.website }}" target="_blank"><i class="bi bi-box-arrow-up-right"></i></a>{% endif %}
|
||||
{{ data.shop|default:"-" }}
|
||||
{% if data.shop.website %} <a href="{{ data.shop.website }}" target="_blank"><i class="bi bi-box-arrow-up-right"></i></a>{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Purchase date</th>
|
||||
<td>{{ book.purchase_date|default:"-" }}</td>
|
||||
<td>{{ data.purchase_date|default:"-" }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Price ({{ site_conf.currency }})</th>
|
||||
<td>{{ book.price|default:"-" }}</td>
|
||||
<td>{{ data.price|default:"-" }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -209,7 +209,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<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="{% dynamic_admin_url 'bookshelf' type book.pk %}">Edit</a>{% endif %}
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% dynamic_admin_url 'bookshelf' data.obj_type data.pk %}">Edit</a>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -6,21 +6,21 @@
|
||||
<div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 g-3">
|
||||
{% block cards %}
|
||||
{% for d in data %}
|
||||
{% if d.type == "roster" %}
|
||||
{% if d.obj_type == "rollingstock" %}
|
||||
{% include "cards/roster.html" %}
|
||||
{% elif d.type == "company" %}
|
||||
{% elif d.obj_type == "company" %}
|
||||
{% include "cards/company.html" %}
|
||||
{% elif d.type == "rolling_stock_type" %}
|
||||
{% elif d.obj_type == "rollingstocktype" %}
|
||||
{% include "cards/rolling_stock_type.html" %}
|
||||
{% elif d.type == "scale" %}
|
||||
{% elif d.obj_type == "scale" %}
|
||||
{% include "cards/scale.html" %}
|
||||
{% elif d.type == "consist" %}
|
||||
{% elif d.obj_type == "consist" %}
|
||||
{% include "cards/consist.html" %}
|
||||
{% elif d.type == "manufacturer" %}
|
||||
{% elif d.obj_type == "manufacturer" %}
|
||||
{% include "cards/manufacturer.html" %}
|
||||
{% elif d.type == "magazine" or d.type == "magazineissue" %}
|
||||
{% elif d.obj_type == "magazine" or d.obj_type == "magazineissue" %}
|
||||
{% include "cards/magazine.html" %}
|
||||
{% elif d.type == "book" or d.type == "catalog" %}
|
||||
{% elif d.obj_type == "book" or d.obj_type == "catalog" %}
|
||||
{% include "cards/book.html" %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
@@ -2,19 +2,19 @@
|
||||
{% load dynamic_url %}
|
||||
<div class="col">
|
||||
<div class="card shadow-sm">
|
||||
{% if d.item.image.exists %}
|
||||
<a href="{{d.item.get_absolute_url}}"><img class="card-img-top" src="{{ d.item.image.first.image.url }}" alt="{{ d.item }}"></a>
|
||||
{% if d.image.exists %}
|
||||
<a href="{{d.get_absolute_url}}"><img class="card-img-top" src="{{ d.image.first.image.url }}" alt="{{ d }}"></a>
|
||||
{% else %}
|
||||
<!-- Do not show the "Coming soon" image when running in a single card column mode (e.g. on mobile) -->
|
||||
<a href="{{d.item.get_absolute_url}}"><img class="card-img-top d-none d-sm-block" src="{% static DEFAULT_CARD_IMAGE %}" alt="{{ d.item }}"></a>
|
||||
<a href="{{d.get_absolute_url}}"><img class="card-img-top d-none d-sm-block" src="{% static DEFAULT_CARD_IMAGE %}" alt="{{ d }}"></a>
|
||||
{% endif %}
|
||||
<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>
|
||||
@@ -24,9 +24,9 @@
|
||||
<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>
|
||||
@@ -34,46 +34,46 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-group-divider">
|
||||
{% if d.type == "catalog" %}
|
||||
{% if d.obj_type == "catalog" %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Manufacturer</th>
|
||||
<td>
|
||||
<a href="{% url 'filtered' _filter="manufacturer" search=d.item.manufacturer.slug %}">{{ d.item.manufacturer }}{% if d.item.manufacturer.website %}</a> <a href="{{ d.item.manufacturer.website }}" target="_blank"><i class="bi bi-box-arrow-up-right"></i></a>{% endif %}
|
||||
<a href="{% url 'filtered' _filter="manufacturer" search=d.manufacturer.slug %}">{{ d.manufacturer }}{% if d.manufacturer.website %}</a> <a href="{{ d.manufacturer.website }}" target="_blank"><i class="bi bi-box-arrow-up-right"></i></a>{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Scales</th>
|
||||
<td>{{ d.item.get_scales }}</td>
|
||||
<td>{{ d.get_scales }}</td>
|
||||
</tr>
|
||||
{% elif d.type == "book" %}
|
||||
{% elif d.obj_type == "book" %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Authors</th>
|
||||
<td>
|
||||
<ul class="mb-0 list-unstyled">{% for a in d.item.authors.all %}<li>{{ a }}</li>{% endfor %}</ul>
|
||||
<ul class="mb-0 list-unstyled">{% for a in d.authors.all %}<li>{{ a }}</li>{% endfor %}</ul>
|
||||
</td>
|
||||
</tr>
|
||||
<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 }}</td>
|
||||
<td><img src="{{ d.publisher.country.flag }}" alt="{{ d.publisher.country }}"> {{ d.publisher }}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<tr>
|
||||
<th scope="row">Language</th>
|
||||
<td>{{ d.item.get_language_display }}</td>
|
||||
<td>{{ d.get_language_display }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Pages</th>
|
||||
<td>{{ d.item.number_of_pages|default:"-" }}</td>
|
||||
<td>{{ d.number_of_pages|default:"-" }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Year</th>
|
||||
<td>{{ d.item.publication_year|default:"-" }}</td>
|
||||
<td>{{ d.publication_year|default:"-" }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="d-grid gap-2 mb-1 d-md-block">
|
||||
<a class="btn btn-sm btn-outline-primary" href="{{ d.item.get_absolute_url }}">Show all data</a>
|
||||
{% 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 %}
|
||||
<a class="btn btn-sm btn-outline-primary" href="{{ d.get_absolute_url }}">Show all data</a>
|
||||
{% 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>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<p class="card-text" style="position: relative;">
|
||||
<strong>{{ d.item.name }}</strong>
|
||||
<strong>{{ d.name }}</strong>
|
||||
</p>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
@@ -10,7 +10,7 @@
|
||||
<th colspan="2" scope="row">
|
||||
Company
|
||||
<div class="float-end">
|
||||
{% if d.item.freelance %}
|
||||
{% if d.freelance %}
|
||||
<span class="badge text-bg-secondary">Freelance</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
@@ -18,30 +18,30 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-group-divider">
|
||||
{% if d.item.logo %}
|
||||
{% if d.logo %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Logo</th>
|
||||
<td><img class="logo" src="{{ d.item.logo.url }}" alt="{{ d.item.name }} logo"></td>
|
||||
<td><img class="logo" src="{{ d.logo.url }}" alt="{{ d.name }} logo"></td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Name</th>
|
||||
<td>{{ d.item.extended_name }}</td>
|
||||
<td>{{ d.extended_name }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Abbreviation</th>
|
||||
<td>{{ d.item.name }}</td>
|
||||
<td>{{ d.name }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Country</th>
|
||||
<td><img src="{{ d.item.country.flag }}" alt="{{ d.item.country }}"> {{ d.item.country.name }}</td>
|
||||
<td><img src="{{ d.country.flag }}" alt="{{ d.country }}"> {{ d.country.name }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="d-grid gap-2 mb-1 d-md-block">
|
||||
{% with items=d.item.num_items %}
|
||||
<a class="btn btn-sm btn-outline-primary{% if items == 0 %} disabled{% endif %}" href="{% url 'filtered' _filter="company" search=d.item.slug %}">Show {{ items }} item{{ items | pluralize}}</a>
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:metadata_company_change' d.item.pk %}">Edit</a>{% endif %}
|
||||
{% with items=d.num_items %}
|
||||
<a class="btn btn-sm btn-outline-primary{% if items == 0 %} disabled{% endif %}" href="{% url 'filtered' _filter="company" search=d.slug %}">Show {{ items }} item{{ items | pluralize}}</a>
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:metadata_company_change' d.pk %}">Edit</a>{% endif %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
<div class="col">
|
||||
<div class="card shadow-sm">
|
||||
<a href="{{ d.item.get_absolute_url }}">
|
||||
{% if d.item.image %}
|
||||
<img class="card-img-top" src="{{ d.item.image.url }}" alt="{{ d.item }}">
|
||||
<a href="{{ d.get_absolute_url }}">
|
||||
{% if d.image %}
|
||||
<img class="card-img-top" src="{{ d.image.url }}" alt="{{ d }}">
|
||||
{% else %}
|
||||
{% with d.item.consist_item.first.rolling_stock as r %}
|
||||
<img class="card-img-top" src="{{ r.image.first.image.url }}" alt="{{ d.item }}">
|
||||
{% with d.consist_item.first.rolling_stock as r %}
|
||||
<img class="card-img-top" src="{{ r.image.first.image.url }}" alt="{{ d }}">
|
||||
{% endwith %}
|
||||
{% 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>
|
||||
@@ -27,10 +27,10 @@
|
||||
<th colspan="2" scope="row">
|
||||
Consist
|
||||
<div class="float-end">
|
||||
{% if not d.item.published %}
|
||||
{% if not d.published %}
|
||||
<span class="badge text-bg-warning">Unpublished</span>
|
||||
{% endif %}
|
||||
{% if d.item.company.freelance %}
|
||||
{% if d.company.freelance %}
|
||||
<span class="badge text-bg-secondary">Freelance</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
@@ -38,32 +38,32 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-group-divider">
|
||||
{% if d.item.address %}
|
||||
{% if d.address %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Address</th>
|
||||
<td>{{ d.item.address }}</td>
|
||||
<td>{{ d.address }}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Company</th>
|
||||
<td>
|
||||
<img src="{{ d.item.company.country.flag }}" alt="{{ d.item.company.country }}">
|
||||
<abbr title="{{ d.item.company.extended_name }}">{{ d.item.company }}</abbr>
|
||||
<img src="{{ d.company.country.flag }}" alt="{{ d.company.country }}">
|
||||
<abbr title="{{ d.company.extended_name }}">{{ d.company }}</abbr>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Era</th>
|
||||
<td>{{ d.item.era }}</td>
|
||||
<td>{{ d.era }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Length</th>
|
||||
<td>{{ d.item.length }}</td>
|
||||
<td>{{ d.length }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="d-grid gap-2 mb-1 d-md-block">
|
||||
<a class="btn btn-sm btn-outline-primary" href="{{ d.item.get_absolute_url }}">Show all data</a>
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:consist_consist_change' d.item.pk %}">Edit</a>{% endif %}
|
||||
<a class="btn btn-sm btn-outline-primary" href="{{ d.get_absolute_url }}">Show all data</a>
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:consist_consist_change' d.pk %}">Edit</a>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<p class="card-text" style="position: relative;">
|
||||
<strong>{{ d.item.name }}</strong>
|
||||
<strong>{{ d.name }}</strong>
|
||||
</p>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
@@ -11,26 +11,26 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-group-divider">
|
||||
{% if d.item.logo %}
|
||||
{% if d.logo %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Logo</th>
|
||||
<td><img class="logo" src="{{ d.item.logo.url }}" alt="{{ d.item.name }} logo"></td>
|
||||
<td><img class="logo" src="{{ d.logo.url }}" alt="{{ d.name }} logo"></td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<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>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Category</th>
|
||||
<td>{{ d.item.category | title }}</td>
|
||||
<td>{{ d.category | title }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="d-grid gap-2 mb-1 d-md-block">
|
||||
{% with items=d.item.num_items %}
|
||||
<a class="btn btn-sm btn-outline-primary{% if items == 0 %} disabled{% endif %}" href="{% url 'filtered' _filter="manufacturer" search=d.item.slug %}">Show {{ items }} item{{ items|pluralize }}</a>
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:metadata_manufacturer_change' d.item.pk %}">Edit</a>{% endif %}
|
||||
{% with items=d.num_items %}
|
||||
<a class="btn btn-sm btn-outline-primary{% if items == 0 %} disabled{% endif %}" href="{% url 'filtered' _filter="manufacturer" search=d.slug %}">Show {{ items }} item{{ items|pluralize }}</a>
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:metadata_manufacturer_change' d.pk %}">Edit</a>{% endif %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<div class="col">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<p class="card-text"><strong>{{ d.item }}</strong></p>
|
||||
<p class="card-text"><strong>{{ d }}</strong></p>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -11,18 +11,18 @@
|
||||
<tbody class="table-group-divider">
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Type</th>
|
||||
<td>{{ d.item.type }}</td>
|
||||
<td>{{ d.type }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Category</th>
|
||||
<td>{{ d.item.category | title}}</td>
|
||||
<td>{{ d.category | title}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="d-grid gap-2 mb-1 d-md-block">
|
||||
{% with items=d.item.num_items %}
|
||||
<a class="btn btn-sm btn-outline-primary{% if items == 0 %} disabled{% endif %}" href="{% url 'filtered' _filter="type" search=d.item.slug %}">Show {{ items }} item{{ items | pluralize}}</a>
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:metadata_rollingstocktype_change' d.item.pk %}">Edit</a>{% endif %}
|
||||
{% with items=d.num_items %}
|
||||
<a class="btn btn-sm btn-outline-primary{% if items == 0 %} disabled{% endif %}" href="{% url 'filtered' _filter="type" search=d.slug %}">Show {{ items }} item{{ items | pluralize}}</a>
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:metadata_rollingstocktype_change' d.pk %}">Edit</a>{% endif %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -3,19 +3,19 @@
|
||||
|
||||
<div class="col">
|
||||
<div class="card shadow-sm">
|
||||
{% if d.item.image.exists %}
|
||||
<a href="{{d.item.get_absolute_url}}"><img class="card-img-top" src="{{ d.item.image.first.image.url }}" alt="{{ d.item }}"></a>
|
||||
{% if d.image.exists %}
|
||||
<a href="{{d.get_absolute_url}}"><img class="card-img-top" src="{{ d.image.first.image.url }}" alt="{{ d }}"></a>
|
||||
{% else %}
|
||||
<!-- Do not show the "Coming soon" image when running in a single card column mode (e.g. on mobile) -->
|
||||
<a href="{{d.item.get_absolute_url}}"><img class="card-img-top d-none d-sm-block" src="{% static DEFAULT_CARD_IMAGE %}" alt="{{ d.item }}"></a>
|
||||
<a href="{{d.get_absolute_url}}"><img class="card-img-top d-none d-sm-block" src="{% static DEFAULT_CARD_IMAGE %}" alt="{{ d }}"></a>
|
||||
{% endif %}
|
||||
<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>
|
||||
@@ -27,10 +27,10 @@
|
||||
<th colspan="2" scope="row">
|
||||
Rolling stock
|
||||
<div class="float-end">
|
||||
{% if not d.item.published %}
|
||||
{% if not d.published %}
|
||||
<span class="badge text-bg-warning">Unpublished</span>
|
||||
{% endif %}
|
||||
{% if d.item.company.freelance %}
|
||||
{% if d.company.freelance %}
|
||||
<span class="badge text-bg-secondary">Freelance</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
@@ -40,50 +40,50 @@
|
||||
<tbody class="table-group-divider">
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Type</th>
|
||||
<td>{{ d.item.rolling_class.type }}</td>
|
||||
<td>{{ d.rolling_class.type }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Company</th>
|
||||
<td>
|
||||
<img src="{{ d.item.company.country.flag }}" alt="{{ d.item.company.country }}">
|
||||
<a href="{% url 'filtered' _filter="company" search=d.item.company.slug %}"><abbr title="{{ d.item.company.extended_name }}">{{ d.item.company }}</abbr></a>
|
||||
<img src="{{ d.company.country.flag }}" alt="{{ d.company.country }}">
|
||||
<a href="{% url 'filtered' _filter="company" search=d.company.slug %}"><abbr title="{{ d.company.extended_name }}">{{ d.company }}</abbr></a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Class</th>
|
||||
<td>{{ d.item.rolling_class.identifier }}</td>
|
||||
<td>{{ d.rolling_class.identifier }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Road number</th>
|
||||
<td>{{ d.item.road_number }}</td>
|
||||
<td>{{ d.road_number }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Era</th>
|
||||
<td>{{ d.item.era }}</td>
|
||||
<td>{{ d.era }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Manufacturer</th>
|
||||
<td>{%if d.item.manufacturer %}
|
||||
<a href="{% url 'filtered' _filter="manufacturer" search=d.item.manufacturer.slug %}">{{ d.item.manufacturer }}{% if d.item.manufacturer.website %}</a> <a href="{{ d.item.manufacturer.website }}" target="_blank"><i class="bi bi-box-arrow-up-right"></i></a>{% endif %}
|
||||
<td>{%if d.manufacturer %}
|
||||
<a href="{% url 'filtered' _filter="manufacturer" search=d.manufacturer.slug %}">{{ d.manufacturer }}{% if d.manufacturer.website %}</a> <a href="{{ d.manufacturer.website }}" target="_blank"><i class="bi bi-box-arrow-up-right"></i></a>{% endif %}
|
||||
{% endif %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Scale</th>
|
||||
<td><a href="{% url 'filtered' _filter="scale" search=d.item.scale.slug %}"><abbr title="{{ d.item.scale.ratio }} - {{ d.item.scale.tracks }} mm">{{ d.item.scale }}</abbr></a></td>
|
||||
<td><a href="{% url 'filtered' _filter="scale" search=d.scale.slug %}"><abbr title="{{ d.scale.ratio }} - {{ d.scale.tracks }} mm">{{ d.scale }}</abbr></a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Item number</th>
|
||||
<td>{{ d.item.item_number }}{%if d.item.set %} | <a class="badge text-bg-primary" href="{% url 'manufacturer' manufacturer=d.item.manufacturer.slug search=d.item.item_number_slug %}">SET</a>{% endif %}</td>
|
||||
<td>{{ d.item_number }}{%if d.set %} | <a class="badge text-bg-primary" href="{% url 'manufacturer' manufacturer=d.manufacturer.slug search=d.item_number_slug %}">SET</a>{% endif %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">DCC</th>
|
||||
<td><a class="text-reset text-decoration-none" title="Symbols" href="" data-bs-toggle="modal" data-bs-target="#symbolsModal">{% dcc d.item %}</a></td>
|
||||
<td><a class="text-reset text-decoration-none" title="Symbols" href="" data-bs-toggle="modal" data-bs-target="#symbolsModal">{% dcc d %}</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="d-grid gap-2 mb-1 d-md-block">
|
||||
<a class="btn btn-sm btn-outline-primary" href="{{d.item.get_absolute_url}}">Show all data</a>
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:roster_rollingstock_change' d.item.pk %}">Edit</a>{% endif %}
|
||||
<a class="btn btn-sm btn-outline-primary" href="{{d.get_absolute_url}}">Show all data</a>
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:roster_rollingstock_change' d.pk %}">Edit</a>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<div class="col">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<p class="card-text"><strong>{{ d.item }}</strong></p>
|
||||
<p class="card-text"><strong>{{ d }}</strong></p>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -11,26 +11,26 @@
|
||||
<tbody>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Name</th>
|
||||
<td>{{ d.item.scale }}</td>
|
||||
<td>{{ d.scale }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Ratio</th>
|
||||
<td>{{ d.item.ratio }}</td>
|
||||
<td>{{ d.ratio }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Tracks</th>
|
||||
<td>{{ d.item.tracks }} mm</td>
|
||||
<td>{{ d.tracks }} mm</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Gauge</th>
|
||||
<td>{{ d.item.gauge }}</td>
|
||||
<td>{{ d.gauge }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="d-grid gap-2 mb-1 d-md-block">
|
||||
{% with items=d.item.num_items %}
|
||||
<a class="btn btn-sm btn-outline-primary{% if items == 0 %} disabled{% endif %}" href="{% url 'filtered' _filter="scale" search=d.item.slug %}">Show {{ items }} item{{ items | pluralize}}</a>
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:metadata_scale_change' d.item.pk %}">Edit</a>{% endif %}
|
||||
{% with items=d.num_items %}
|
||||
<a class="btn btn-sm btn-outline-primary{% if items == 0 %} disabled{% endif %}" href="{% url 'filtered' _filter="scale" search=d.slug %}">Show {{ items }} item{{ items | pluralize}}</a>
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:metadata_scale_change' d.pk %}">Edit</a>{% endif %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
<ul class="pagination flex-wrap justify-content-center mt-4 mb-0">
|
||||
{% if data.has_previous %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="{% url 'consist_pagination' uuid=consist.uuid page=data.previous_page_number %}#main-content" tabindex="-1"><i class="bi bi-chevron-left"></i></a>
|
||||
<a class="page-link" href="{% url 'consist' uuid=consist.uuid page=data.previous_page_number %}#main-content" tabindex="-1"><i class="bi bi-chevron-left"></i></a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item disabled">
|
||||
@@ -48,13 +48,13 @@
|
||||
{% if i == data.paginator.ELLIPSIS %}
|
||||
<li class="page-item"><span class="page-link">{{ i }}</span></li>
|
||||
{% else %}
|
||||
<li class="page-item"><a class="page-link" href="{% url 'consist_pagination' uuid=consist.uuid page=i %}#main-content">{{ i }}</a></li>
|
||||
<li class="page-item"><a class="page-link" href="{% url 'consist' uuid=consist.uuid page=i %}#main-content">{{ i }}</a></li>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if data.has_next %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="{% url 'consist_pagination' uuid=consist.uuid page=data.next_page_number %}#main-content" tabindex="-1"><i class="bi bi-chevron-right"></i></a>
|
||||
<a class="page-link" href="{% url 'consist' uuid=consist.uuid page=data.next_page_number %}#main-content" tabindex="-1"><i class="bi bi-chevron-right"></i></a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item disabled">
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<ul class="pagination flex-wrap justify-content-center mt-4 mb-0">
|
||||
{% if data.has_previous %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="{% url 'filtered_pagination' _filter=filter search=search page=data.previous_page_number %}#main-content" tabindex="-1"><i class="bi bi-chevron-left"></i></a>
|
||||
<a class="page-link" href="{% url 'filtered' _filter=filter search=search page=data.previous_page_number %}#main-content" tabindex="-1"><i class="bi bi-chevron-left"></i></a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item disabled">
|
||||
@@ -21,13 +21,13 @@
|
||||
{% if i == data.paginator.ELLIPSIS %}
|
||||
<li class="page-item"><span class="page-link">{{ i }}</span></li>
|
||||
{% else %}
|
||||
<li class="page-item"><a class="page-link" href="{% url 'filtered_pagination' _filter=filter search=search page=i %}#main-content">{{ i }}</a></li>
|
||||
<li class="page-item"><a class="page-link" href="{% url 'filtered' _filter=filter search=search page=i %}#main-content">{{ i }}</a></li>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if data.has_next %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="{% url 'filtered_pagination' _filter=filter search=search page=data.next_page_number %}#main-content" tabindex="-1"><i class="bi bi-chevron-right"></i></a>
|
||||
<a class="page-link" href="{% url 'filtered' _filter=filter search=search page=data.next_page_number %}#main-content" tabindex="-1"><i class="bi bi-chevron-right"></i></a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item disabled">
|
||||
|
||||
@@ -3,3 +3,18 @@
|
||||
{% block header %}
|
||||
<div class="text-body-secondary">{{ site_conf.about | safe }}</div>
|
||||
{% endblock %}
|
||||
{% block cards %}
|
||||
{% for d in data %}
|
||||
{% include "cards/roster.html" %}
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
|
||||
{% block pagination %}
|
||||
<nav aria-label="Page navigation">
|
||||
<ul class="pagination flex-wrap justify-content-center mt-4 mb-0">
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="{% url "roster" %}#main-content" tabindex="-1">Go to the roster <i class="bi bi-chevron-right"></i></a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
{% endblock %}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<ul class="pagination flex-wrap justify-content-center mt-4 mb-0">
|
||||
{% if data.has_previous %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="{% url 'manufacturer_pagination' manufacturer=manufacturer.slug search=search page=data.previous_page_number %}#main-content" tabindex="-1"><i class="bi bi-chevron-left"></i></a>
|
||||
<a class="page-link" href="{% url 'manufacturer' manufacturer=manufacturer.slug search=search page=data.previous_page_number %}#main-content" tabindex="-1"><i class="bi bi-chevron-left"></i></a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item disabled">
|
||||
@@ -21,13 +21,13 @@
|
||||
{% if i == data.paginator.ELLIPSIS %}
|
||||
<li class="page-item"><span class="page-link">{{ i }}</span></li>
|
||||
{% else %}
|
||||
<li class="page-item"><a class="page-link" href="{% url 'manufacturer_pagination' manufacturer=manufacturer.slug search=search page=i %}#main-content">{{ i }}</a></li>
|
||||
<li class="page-item"><a class="page-link" href="{% url 'manufacturer' manufacturer=manufacturer.slug search=search page=i %}#main-content">{{ i }}</a></li>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if data.has_next %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="{% url 'manufacturer_pagination' manufacturer=manufacturer.slug search=search page=data.next_page_number %}#main-content" tabindex="-1"><i class="bi bi-chevron-right"></i></a>
|
||||
<a class="page-link" href="{% url 'manufacturer' manufacturer=manufacturer.slug search=search page=data.next_page_number %}#main-content" tabindex="-1"><i class="bi bi-chevron-right"></i></a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item disabled">
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<ul class="pagination flex-wrap justify-content-center mt-4 mb-0">
|
||||
{% if data.has_previous %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="{% dynamic_pagination type page=data.previous_page_number %}#main-content" tabindex="-1"><i class="bi bi-chevron-left"></i></a>
|
||||
<a class="page-link" href="{% url request.resolver_match.url_name page=data.previous_page_number %}#main-content" tabindex="-1"><i class="bi bi-chevron-left"></i></a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item disabled">
|
||||
@@ -23,13 +23,13 @@
|
||||
{% if i == data.paginator.ELLIPSIS %}
|
||||
<li class="page-item"><span class="page-link">{{ i }}</span></li>
|
||||
{% else %}
|
||||
<li class="page-item"><a class="page-link" href="{% dynamic_pagination type page=i %}#main-content">{{ i }}</a></li>
|
||||
<li class="page-item"><a class="page-link" href="{% url request.resolver_match.url_name page=i %}#main-content">{{ i }}</a></li>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if data.has_next %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="{% dynamic_pagination type page=data.next_page_number %}#main-content" tabindex="-1"><i class="bi bi-chevron-right"></i></a>
|
||||
<a class="page-link" href="{% url request.resolver_match.url_name page=data.next_page_number %}#main-content" tabindex="-1"><i class="bi bi-chevron-right"></i></a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item disabled">
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
{% extends "cards.html" %}
|
||||
{% block pagination %}
|
||||
{% if data.has_other_pages %}
|
||||
{% with data.0.item.category as c %}
|
||||
{% with data.0.category as c %}
|
||||
<nav aria-label="Page navigation">
|
||||
<ul class="pagination flex-wrap justify-content-center mt-4 mb-0">
|
||||
{% if data.has_previous %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="{% url 'manufacturers_pagination' category=c page=data.previous_page_number %}#main-content" tabindex="-1"><i class="bi bi-chevron-left"></i></a>
|
||||
<a class="page-link" href="{% url 'manufacturers' category=c page=data.previous_page_number %}#main-content" tabindex="-1"><i class="bi bi-chevron-left"></i></a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item disabled">
|
||||
@@ -22,13 +22,13 @@
|
||||
{% if i == data.paginator.ELLIPSIS %}
|
||||
<li class="page-item"><span class="page-link">{{ i }}</span></li>
|
||||
{% else %}
|
||||
<li class="page-item"><a class="page-link" href="{% url 'manufacturers_pagination' category=c page=i %}#main-content">{{ i }}</a></li>
|
||||
<li class="page-item"><a class="page-link" href="{% url 'manufacturers' category=c page=i %}#main-content">{{ i }}</a></li>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if data.has_next %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="{% url 'manufacturers_pagination' category=c page=data.next_page_number %}#main-content" tabindex="-1"><i class="bi bi-chevron-right"></i></a>
|
||||
<a class="page-link" href="{% url 'manufacturers' category=c page=data.next_page_number %}#main-content" tabindex="-1"><i class="bi bi-chevron-right"></i></a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item disabled">
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<ul class="pagination flex-wrap justify-content-center mt-4 mb-0">
|
||||
{% if data.has_previous %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="{% url 'search_pagination' search=encoded_search page=data.previous_page_number %}#main-content" tabindex="-1"><i class="bi bi-chevron-left"></i></a>
|
||||
<a class="page-link" href="{% url 'search' search=encoded_search page=data.previous_page_number %}#main-content" tabindex="-1"><i class="bi bi-chevron-left"></i></a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item disabled">
|
||||
@@ -22,13 +22,13 @@
|
||||
{% if i == data.paginator.ELLIPSIS %}
|
||||
<li class="page-item"><span class="page-link">{{ i }}</span></li>
|
||||
{% else %}
|
||||
<li class="page-item"><a class="page-link" href="{% url 'search_pagination' search=encoded_search page=i %}#main-content">{{ i }}</a></li>
|
||||
<li class="page-item"><a class="page-link" href="{% url 'search' search=encoded_search page=i %}#main-content">{{ i }}</a></li>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if data.has_next %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="{% url 'search_pagination' search=encoded_search page=data.next_page_number %}#main-content" tabindex="-1"><i class="bi bi-chevron-right"></i></a>
|
||||
<a class="page-link" href="{% url 'search' search=encoded_search page=data.next_page_number %}#main-content" tabindex="-1"><i class="bi bi-chevron-right"></i></a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item disabled">
|
||||
|
||||
@@ -12,10 +12,3 @@ def dynamic_admin_url(app_name, model_name, object_id=None):
|
||||
args=[object_id]
|
||||
)
|
||||
return reverse(f'admin:{app_name}_{model_name}_changelist')
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def dynamic_pagination(reverse_name, page):
|
||||
if reverse_name.endswith('y'):
|
||||
return reverse(f'{reverse_name[:-1]}ies_pagination', args=[page])
|
||||
return reverse(f'{reverse_name}s_pagination', args=[page])
|
||||
|
||||
11
ram/portal/templatetags/shuffle.py
Normal file
11
ram/portal/templatetags/shuffle.py
Normal file
@@ -0,0 +1,11 @@
|
||||
import random
|
||||
from django import template
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
@register.filter
|
||||
def shuffle(items):
|
||||
shuffled_items = list(items)
|
||||
random.shuffle(shuffled_items)
|
||||
return shuffled_items
|
||||
@@ -1,7 +1,7 @@
|
||||
from django.urls import path
|
||||
|
||||
from portal.views import (
|
||||
GetData,
|
||||
GetHome,
|
||||
GetRoster,
|
||||
GetObjectsFiltered,
|
||||
GetManufacturerItem,
|
||||
@@ -23,123 +23,75 @@ from portal.views import (
|
||||
)
|
||||
|
||||
urlpatterns = [
|
||||
path("", GetData.as_view(template="home.html"), name="index"),
|
||||
path("", GetHome.as_view(), name="index"),
|
||||
path("roster", GetRoster.as_view(), name="roster"),
|
||||
path(
|
||||
"roster/page/<int:page>",
|
||||
GetRoster.as_view(),
|
||||
name="rosters_pagination"
|
||||
),
|
||||
path("roster/page/<int:page>", GetRoster.as_view(), name="roster"),
|
||||
path(
|
||||
"page/<str:flatpage>",
|
||||
GetFlatpage.as_view(),
|
||||
name="flatpage",
|
||||
),
|
||||
path(
|
||||
"consists",
|
||||
Consists.as_view(),
|
||||
name="consists"
|
||||
),
|
||||
path(
|
||||
"consists/page/<int:page>",
|
||||
Consists.as_view(),
|
||||
name="consists_pagination"
|
||||
),
|
||||
path("consists", Consists.as_view(), name="consists"),
|
||||
path("consists/page/<int:page>", Consists.as_view(), name="consists"),
|
||||
path("consist/<uuid:uuid>", GetConsist.as_view(), name="consist"),
|
||||
path(
|
||||
"consist/<uuid:uuid>/page/<int:page>",
|
||||
GetConsist.as_view(),
|
||||
name="consist_pagination",
|
||||
),
|
||||
path(
|
||||
"companies",
|
||||
Companies.as_view(),
|
||||
name="companies"
|
||||
name="consist",
|
||||
),
|
||||
path("companies", Companies.as_view(), name="companies"),
|
||||
path(
|
||||
"companies/page/<int:page>",
|
||||
Companies.as_view(),
|
||||
name="companies_pagination",
|
||||
name="companies",
|
||||
),
|
||||
path(
|
||||
"manufacturers/<str:category>",
|
||||
Manufacturers.as_view(template="pagination_manufacturers.html"),
|
||||
name="manufacturers"
|
||||
name="manufacturers",
|
||||
),
|
||||
path(
|
||||
"manufacturers/<str:category>/page/<int:page>",
|
||||
Manufacturers.as_view(template="pagination_manufacturers.html"),
|
||||
name="manufacturers_pagination",
|
||||
),
|
||||
path(
|
||||
"scales",
|
||||
Scales.as_view(),
|
||||
name="scales"
|
||||
),
|
||||
path(
|
||||
"scales/page/<int:page>",
|
||||
Scales.as_view(),
|
||||
name="scales_pagination"
|
||||
),
|
||||
path(
|
||||
"types",
|
||||
Types.as_view(),
|
||||
name="rolling_stock_types"
|
||||
),
|
||||
path(
|
||||
"types/page/<int:page>",
|
||||
Types.as_view(),
|
||||
name="rolling_stock_types_pagination"
|
||||
),
|
||||
path(
|
||||
"bookshelf/books",
|
||||
Books.as_view(),
|
||||
name="books"
|
||||
),
|
||||
path(
|
||||
"bookshelf/books/page/<int:page>",
|
||||
Books.as_view(),
|
||||
name="books_pagination"
|
||||
name="manufacturers",
|
||||
),
|
||||
path("scales", Scales.as_view(), name="scales"),
|
||||
path("scales/page/<int:page>", Scales.as_view(), name="scales"),
|
||||
path("types", Types.as_view(), name="rolling_stock_types"),
|
||||
path("types/page/<int:page>", Types.as_view(), name="rolling_stock_types"),
|
||||
path("bookshelf/books", Books.as_view(), name="books"),
|
||||
path("bookshelf/books/page/<int:page>", Books.as_view(), name="books"),
|
||||
path(
|
||||
"bookshelf/magazine/<uuid:uuid>",
|
||||
GetMagazine.as_view(),
|
||||
name="magazine"
|
||||
name="magazine",
|
||||
),
|
||||
path(
|
||||
"bookshelf/magazine/<uuid:uuid>/page/<int:page>",
|
||||
GetMagazine.as_view(),
|
||||
name="magazine_pagination",
|
||||
name="magazine",
|
||||
),
|
||||
path(
|
||||
"bookshelf/magazine/<uuid:magazine>/issue/<uuid:uuid>",
|
||||
GetMagazineIssue.as_view(),
|
||||
name="issue",
|
||||
),
|
||||
path(
|
||||
"bookshelf/magazines",
|
||||
Magazines.as_view(),
|
||||
name="magazines"
|
||||
),
|
||||
path("bookshelf/magazines", Magazines.as_view(), name="magazines"),
|
||||
path(
|
||||
"bookshelf/magazines/page/<int:page>",
|
||||
Magazines.as_view(),
|
||||
name="magazines_pagination"
|
||||
name="magazines",
|
||||
),
|
||||
path(
|
||||
"bookshelf/<str:selector>/<uuid:uuid>",
|
||||
GetBookCatalog.as_view(),
|
||||
name="bookshelf_item"
|
||||
),
|
||||
path(
|
||||
"bookshelf/catalogs",
|
||||
Catalogs.as_view(),
|
||||
name="catalogs"
|
||||
name="bookshelf_item",
|
||||
),
|
||||
path("bookshelf/catalogs", Catalogs.as_view(), name="catalogs"),
|
||||
path(
|
||||
"bookshelf/catalogs/page/<int:page>",
|
||||
Catalogs.as_view(),
|
||||
name="catalogs_pagination"
|
||||
name="catalogs",
|
||||
),
|
||||
path(
|
||||
"search",
|
||||
@@ -149,7 +101,7 @@ urlpatterns = [
|
||||
path(
|
||||
"search/<str:search>/page/<int:page>",
|
||||
SearchObjects.as_view(),
|
||||
name="search_pagination",
|
||||
name="search",
|
||||
),
|
||||
path(
|
||||
"manufacturer/<str:manufacturer>",
|
||||
@@ -159,7 +111,7 @@ urlpatterns = [
|
||||
path(
|
||||
"manufacturer/<str:manufacturer>/page/<int:page>",
|
||||
GetManufacturerItem.as_view(),
|
||||
name="manufacturer_pagination",
|
||||
name="manufacturer",
|
||||
),
|
||||
path(
|
||||
"manufacturer/<str:manufacturer>/<str:search>",
|
||||
@@ -169,7 +121,7 @@ urlpatterns = [
|
||||
path(
|
||||
"manufacturer/<str:manufacturer>/<str:search>/page/<int:page>",
|
||||
GetManufacturerItem.as_view(),
|
||||
name="manufacturer_pagination",
|
||||
name="manufacturer",
|
||||
),
|
||||
path(
|
||||
"<str:_filter>/<str:search>",
|
||||
@@ -179,7 +131,7 @@ urlpatterns = [
|
||||
path(
|
||||
"<str:_filter>/<str:search>/page/<int:page>",
|
||||
GetObjectsFiltered.as_view(),
|
||||
name="filtered_pagination",
|
||||
name="filtered",
|
||||
),
|
||||
path("<uuid:uuid>", GetRollingStock.as_view(), name="rolling_stock"),
|
||||
]
|
||||
|
||||
@@ -4,6 +4,7 @@ from itertools import chain
|
||||
from functools import reduce
|
||||
from urllib.parse import unquote
|
||||
|
||||
from django.conf import settings
|
||||
from django.views import View
|
||||
from django.http import Http404, HttpResponseBadRequest
|
||||
from django.db.utils import OperationalError, ProgrammingError
|
||||
@@ -32,7 +33,7 @@ def get_items_per_page():
|
||||
items_per_page = get_site_conf().items_per_page
|
||||
except (OperationalError, ProgrammingError):
|
||||
items_per_page = 6
|
||||
return items_per_page
|
||||
return int(items_per_page)
|
||||
|
||||
|
||||
def get_order_by_field():
|
||||
@@ -62,9 +63,8 @@ class Render404(View):
|
||||
|
||||
|
||||
class GetData(View):
|
||||
title = "Home"
|
||||
title = None
|
||||
template = "pagination.html"
|
||||
item_type = "roster"
|
||||
filter = Q() # empty filter by default
|
||||
|
||||
def get_data(self, request):
|
||||
@@ -75,15 +75,10 @@ class GetData(View):
|
||||
)
|
||||
|
||||
def get(self, request, page=1):
|
||||
data = []
|
||||
for item in self.get_data(request):
|
||||
data.append(
|
||||
{
|
||||
"type": self.item_type,
|
||||
"label": self.item_type.capitalize(),
|
||||
"item": item,
|
||||
}
|
||||
)
|
||||
if self.title is None or self.template is None:
|
||||
raise Exception("title and template must be defined")
|
||||
|
||||
data = list(self.get_data(request))
|
||||
|
||||
paginator = Paginator(data, get_items_per_page())
|
||||
data = paginator.get_page(page)
|
||||
@@ -96,7 +91,6 @@ class GetData(View):
|
||||
self.template,
|
||||
{
|
||||
"title": self.title,
|
||||
"type": self.item_type,
|
||||
"data": data,
|
||||
"matches": paginator.count,
|
||||
"page_range": page_range,
|
||||
@@ -104,18 +98,36 @@ class GetData(View):
|
||||
)
|
||||
|
||||
|
||||
class GetRoster(GetData):
|
||||
title = "The Roster"
|
||||
item_type = "roster"
|
||||
class GetHome(GetData):
|
||||
title = "Home"
|
||||
template = "home.html"
|
||||
|
||||
def get_data(self, request):
|
||||
return RollingStock.objects.get_published(request.user).order_by(
|
||||
*get_order_by_field()
|
||||
)
|
||||
max_items = min(settings.FEATURED_ITEMS_MAX, get_items_per_page())
|
||||
return (
|
||||
RollingStock.objects.get_published(request.user)
|
||||
.filter(featured=True)
|
||||
.order_by(*get_order_by_field())[:max_items]
|
||||
) or super().get_data(request)
|
||||
|
||||
|
||||
class GetRoster(GetData):
|
||||
title = "The Roster"
|
||||
|
||||
|
||||
class SearchObjects(View):
|
||||
def run_search(self, request, search, _filter, page=1):
|
||||
"""
|
||||
Run the search query on the database and return the results.
|
||||
param request: HTTP request
|
||||
param search: search string
|
||||
param _filter: filter to apply (type, company, manufacturer, scale)
|
||||
param page: page number for pagination
|
||||
return: tuple (data, matches, page_range)
|
||||
1. data: list of dicts with keys "type" and "item"
|
||||
2. matches: total number of matches
|
||||
3. page_range: elided page range for pagination
|
||||
"""
|
||||
if _filter is None:
|
||||
query = reduce(
|
||||
operator.or_,
|
||||
@@ -158,15 +170,13 @@ class SearchObjects(View):
|
||||
# FIXME duplicated code!
|
||||
# FIXME see if it makes sense to filter calatogs and books by scale
|
||||
# and manufacturer as well
|
||||
data = []
|
||||
roster = (
|
||||
RollingStock.objects.get_published(request.user)
|
||||
.filter(query)
|
||||
.distinct()
|
||||
.order_by(*get_order_by_field())
|
||||
)
|
||||
for item in roster:
|
||||
data.append({"type": "roster", "item": item})
|
||||
data = list(roster)
|
||||
|
||||
if _filter is None:
|
||||
consists = (
|
||||
@@ -179,8 +189,7 @@ class SearchObjects(View):
|
||||
)
|
||||
.distinct()
|
||||
)
|
||||
for item in consists:
|
||||
data.append({"type": "consist", "item": item})
|
||||
data = list(chain(data, consists))
|
||||
books = (
|
||||
Book.objects.get_published(request.user)
|
||||
.filter(
|
||||
@@ -201,14 +210,7 @@ class SearchObjects(View):
|
||||
)
|
||||
.distinct()
|
||||
)
|
||||
for item in list(chain(books, catalogs)):
|
||||
data.append(
|
||||
{
|
||||
"type": item._meta.model_name,
|
||||
"label": item._meta.object_name,
|
||||
"item": item,
|
||||
}
|
||||
)
|
||||
data = list(chain(data, books, catalogs))
|
||||
magazine_issues = (
|
||||
MagazineIssue.objects.get_published(request.user)
|
||||
.filter(
|
||||
@@ -219,14 +221,7 @@ class SearchObjects(View):
|
||||
)
|
||||
.distinct()
|
||||
)
|
||||
for item in magazine_issues:
|
||||
data.append(
|
||||
{
|
||||
"type": "book",
|
||||
"label": "Magazine Issue",
|
||||
"item": item,
|
||||
}
|
||||
)
|
||||
data = list(chain(data, magazine_issues))
|
||||
|
||||
paginator = Paginator(data, get_items_per_page())
|
||||
data = paginator.get_page(page)
|
||||
@@ -282,10 +277,25 @@ class SearchObjects(View):
|
||||
|
||||
class GetManufacturerItem(View):
|
||||
def get(self, request, manufacturer, search="all", page=1):
|
||||
"""
|
||||
Get all items from a specific manufacturer. If `search` is not "all",
|
||||
filter by item number as well, for example to get all itmes from the
|
||||
same set.
|
||||
The view returns both rolling stock and catalogs.
|
||||
param request: HTTP request
|
||||
param manufacturer: Manufacturer slug
|
||||
param search: item number slug or "all"
|
||||
param page: page number for pagination
|
||||
return: rendered template
|
||||
1. manufacturer: Manufacturer object
|
||||
2. search: item number slug or "all"
|
||||
3. data: list of dicts with keys "type" and "item"
|
||||
4. matches: total number of matches
|
||||
5. page_range: elided page range for pagination
|
||||
"""
|
||||
manufacturer = get_object_or_404(
|
||||
Manufacturer, slug__iexact=manufacturer
|
||||
)
|
||||
|
||||
if search != "all":
|
||||
roster = get_list_or_404(
|
||||
RollingStock.objects.get_published(request.user).order_by(
|
||||
@@ -296,6 +306,7 @@ class GetManufacturerItem(View):
|
||||
& Q(item_number_slug__exact=search)
|
||||
),
|
||||
)
|
||||
catalogs = [] # no catalogs when searching for a specific item
|
||||
title = "{0}: {1}".format(
|
||||
manufacturer,
|
||||
# all returned records must have the same `item_number``;
|
||||
@@ -317,20 +328,7 @@ class GetManufacturerItem(View):
|
||||
)
|
||||
title = "Manufacturer: {0}".format(manufacturer)
|
||||
|
||||
data = []
|
||||
for item in roster:
|
||||
data.append({"type": "roster", "item": item})
|
||||
|
||||
if catalogs is not None:
|
||||
for item in catalogs:
|
||||
data.append(
|
||||
{
|
||||
"type": "catalog",
|
||||
"label": "Catalog",
|
||||
"item": item,
|
||||
}
|
||||
)
|
||||
|
||||
data = list(chain(roster, catalogs))
|
||||
paginator = Paginator(data, get_items_per_page())
|
||||
data = paginator.get_page(page)
|
||||
page_range = paginator.get_elided_page_range(
|
||||
@@ -379,9 +377,7 @@ class GetObjectsFiltered(View):
|
||||
.order_by(*get_order_by_field())
|
||||
)
|
||||
|
||||
data = []
|
||||
for item in roster:
|
||||
data.append({"type": "roster", "item": item})
|
||||
data = list(roster)
|
||||
|
||||
if _filter == "scale":
|
||||
catalogs = (
|
||||
@@ -389,14 +385,7 @@ class GetObjectsFiltered(View):
|
||||
.filter(scales__slug=search)
|
||||
.distinct()
|
||||
)
|
||||
for item in catalogs:
|
||||
data.append(
|
||||
{
|
||||
"type": "catalog",
|
||||
"label": "Catalog",
|
||||
"item": item,
|
||||
}
|
||||
)
|
||||
data = list(chain(data, catalogs))
|
||||
|
||||
try: # Execute only if query_2nd is defined
|
||||
consists = (
|
||||
@@ -404,8 +393,7 @@ class GetObjectsFiltered(View):
|
||||
.filter(query_2nd)
|
||||
.distinct()
|
||||
)
|
||||
for item in consists:
|
||||
data.append({"type": "consist", "item": item})
|
||||
data = list(chain(data, consists))
|
||||
if _filter == "tag": # Books can be filtered only by tag
|
||||
books = (
|
||||
Book.objects.get_published(request.user)
|
||||
@@ -417,27 +405,12 @@ class GetObjectsFiltered(View):
|
||||
.filter(query_2nd)
|
||||
.distinct()
|
||||
)
|
||||
for item in list(chain(books, catalogs)):
|
||||
data.append(
|
||||
{
|
||||
"type": item._meta.model_name,
|
||||
"label": item._meta.object_name,
|
||||
"item": item,
|
||||
}
|
||||
)
|
||||
magazine_issues = (
|
||||
MagazineIssue.objects.get_published(request.user)
|
||||
.filter(query_2nd)
|
||||
.distinct()
|
||||
)
|
||||
for item in magazine_issues:
|
||||
data.append(
|
||||
{
|
||||
"type": "book",
|
||||
"label": "Magazine Issue",
|
||||
"item": item,
|
||||
}
|
||||
)
|
||||
data = list(chain(data, books, catalogs, magazine_issues))
|
||||
except NameError:
|
||||
pass
|
||||
|
||||
@@ -491,16 +464,14 @@ class GetRollingStock(View):
|
||||
request.user
|
||||
)
|
||||
|
||||
consists = [
|
||||
{"type": "consist", "item": c}
|
||||
for c in Consist.objects.get_published(request.user).filter(
|
||||
consists = list(
|
||||
Consist.objects.get_published(request.user).filter(
|
||||
consist_item__rolling_stock=rolling_stock
|
||||
)
|
||||
] # A dict with "item" is required by the consists card
|
||||
)
|
||||
|
||||
set = [
|
||||
{"type": "set", "item": s}
|
||||
for s in RollingStock.objects.get_published(request.user)
|
||||
trainset = list(
|
||||
RollingStock.objects.get_published(request.user)
|
||||
.filter(
|
||||
Q(
|
||||
Q(item_number__exact=rolling_stock.item_number)
|
||||
@@ -508,7 +479,7 @@ class GetRollingStock(View):
|
||||
)
|
||||
)
|
||||
.order_by(*get_order_by_field())
|
||||
]
|
||||
)
|
||||
|
||||
return render(
|
||||
request,
|
||||
@@ -521,7 +492,7 @@ class GetRollingStock(View):
|
||||
"decoder_documents": decoder_documents,
|
||||
"documents": documents,
|
||||
"journal": journal,
|
||||
"set": set,
|
||||
"set": trainset,
|
||||
"consists": consists,
|
||||
},
|
||||
)
|
||||
@@ -529,7 +500,6 @@ class GetRollingStock(View):
|
||||
|
||||
class Consists(GetData):
|
||||
title = "Consists"
|
||||
item_type = "consist"
|
||||
|
||||
def get_data(self, request):
|
||||
return Consist.objects.get_published(request.user).all()
|
||||
@@ -543,16 +513,13 @@ class GetConsist(View):
|
||||
)
|
||||
except ObjectDoesNotExist:
|
||||
raise Http404
|
||||
data = [
|
||||
{
|
||||
"type": "roster",
|
||||
"item": RollingStock.objects.get_published(request.user).get(
|
||||
uuid=r.rolling_stock_id
|
||||
),
|
||||
}
|
||||
for r in consist.consist_item.all()
|
||||
]
|
||||
|
||||
data = list(
|
||||
RollingStock.objects.get_published(request.user).get(
|
||||
uuid=r.rolling_stock_id
|
||||
)
|
||||
for r in consist.consist_item.all()
|
||||
)
|
||||
paginator = Paginator(data, get_items_per_page())
|
||||
data = paginator.get_page(page)
|
||||
page_range = paginator.get_elided_page_range(
|
||||
@@ -573,7 +540,6 @@ class GetConsist(View):
|
||||
|
||||
class Manufacturers(GetData):
|
||||
title = "Manufacturers"
|
||||
item_type = "manufacturer"
|
||||
|
||||
def get_data(self, request):
|
||||
return (
|
||||
@@ -642,7 +608,6 @@ class Manufacturers(GetData):
|
||||
|
||||
class Companies(GetData):
|
||||
title = "Companies"
|
||||
item_type = "company"
|
||||
|
||||
def get_data(self, request):
|
||||
return (
|
||||
@@ -681,7 +646,6 @@ class Companies(GetData):
|
||||
|
||||
class Scales(GetData):
|
||||
title = "Scales"
|
||||
item_type = "scale"
|
||||
|
||||
def get_data(self, request):
|
||||
return (
|
||||
@@ -717,7 +681,6 @@ class Scales(GetData):
|
||||
|
||||
class Types(GetData):
|
||||
title = "Types"
|
||||
item_type = "rolling_stock_type"
|
||||
|
||||
def get_data(self, request):
|
||||
return RollingStockType.objects.annotate(
|
||||
@@ -734,7 +697,6 @@ class Types(GetData):
|
||||
|
||||
class Books(GetData):
|
||||
title = "Books"
|
||||
item_type = "book"
|
||||
|
||||
def get_data(self, request):
|
||||
return Book.objects.get_published(request.user).all()
|
||||
@@ -742,7 +704,6 @@ class Books(GetData):
|
||||
|
||||
class Catalogs(GetData):
|
||||
title = "Catalogs"
|
||||
item_type = "catalog"
|
||||
|
||||
def get_data(self, request):
|
||||
return Catalog.objects.get_published(request.user).all()
|
||||
@@ -750,7 +711,6 @@ class Catalogs(GetData):
|
||||
|
||||
class Magazines(GetData):
|
||||
title = "Magazines"
|
||||
item_type = "magazine"
|
||||
|
||||
def get_data(self, request):
|
||||
return (
|
||||
@@ -777,14 +737,7 @@ class GetMagazine(View):
|
||||
)
|
||||
except ObjectDoesNotExist:
|
||||
raise Http404
|
||||
data = [
|
||||
{
|
||||
"type": "magazineissue",
|
||||
"label": "Magazine issue",
|
||||
"item": i,
|
||||
}
|
||||
for i in magazine.issue.get_published(request.user).all()
|
||||
]
|
||||
data = list(magazine.issue.get_published(request.user).all())
|
||||
paginator = Paginator(data, get_items_per_page())
|
||||
data = paginator.get_page(page)
|
||||
page_range = paginator.get_elided_page_range(
|
||||
@@ -820,11 +773,9 @@ class GetMagazineIssue(View):
|
||||
"bookshelf/book.html",
|
||||
{
|
||||
"title": issue,
|
||||
"book": issue,
|
||||
"data": issue,
|
||||
"documents": documents,
|
||||
"properties": properties,
|
||||
"type": "magazineissue",
|
||||
"label": "Magazine issue",
|
||||
},
|
||||
)
|
||||
|
||||
@@ -851,11 +802,9 @@ class GetBookCatalog(View):
|
||||
"bookshelf/book.html",
|
||||
{
|
||||
"title": book,
|
||||
"book": book,
|
||||
"data": book,
|
||||
"documents": documents,
|
||||
"properties": properties,
|
||||
"type": selector,
|
||||
"label": selector.capitalize(),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user