mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 05:07:50 +02:00
Add search function and ui refactor
This commit is contained in:
174
ram/portal/templates/base.html
Normal file
174
ram/portal/templates/base.html
Normal file
@@ -0,0 +1,174 @@
|
||||
{% load static %}
|
||||
{% load solo_tags %}
|
||||
{% load markdown %}
|
||||
{% get_solo 'portal.SiteConfiguration' as site_conf %}
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
|
||||
<meta name="generator" content="Hugo 0.88.1">
|
||||
<title>{{ site_conf.site_name }}</title>
|
||||
<link rel="canonical" href="https://getbootstrap.com/docs/5.1/examples/album/">
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="{% static "css/main.css" %}" rel="stylesheet">
|
||||
|
||||
<style>
|
||||
.bd-placeholder-img {
|
||||
font-size: 1.125rem;
|
||||
text-anchor: middle;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.bd-placeholder-img-lg {
|
||||
font-size: 3.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header>
|
||||
<div class="navbar navbar-dark bg-dark shadow-sm">
|
||||
<div class="container">
|
||||
<a href="/" class="navbar-brand d-flex align-items-center">
|
||||
<svg class="me-2" width="26" height="16" enable-background="new 0 0 26 26" version="1" viewBox="0 0 26 16" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="m2.8125 0.0010991a1.0001 1.0001 0 0 0-0.8125 1c0 0.55455-0.44545 1-1 1a1.0001 1.0001 0 0 0-1 1v10a1.0001 1.0001 0 0 0 1 1c0.55455 0 1 0.44546 1 1a1.0001 1.0001 0 0 0 1 1h20a1.0001 1.0001 0 0 0 1-1c0-0.55454 0.44546-1 1-1a1.0001 1.0001 0 0 0 1-1v-10a1.0001 1.0001 0 0 0-1-1c-0.55454 0-1-0.44545-1-1a1.0001 1.0001 0 0 0-1-1h-20a1.0001 1.0001 0 0 0-0.09375 0 1.0001 1.0001 0 0 0-0.09375 0zm0.78125 2h14.406v1h2v-1h2.4062c0.30628 0.76906 0.82469 1.2875 1.5938 1.5938v8.8125c-0.76906 0.30628-1.2875 0.82469-1.5938 1.5938h-2.4062v-1h-2v1h-14.406c-0.30628-0.76906-0.82469-1.2875-1.5938-1.5938v-8.8125c0.76906-0.30628 1.2875-0.82469 1.5938-1.5938zm14.406 2v2h2v-2zm0 3v2h2v-2zm0 3v2h2v-2z" enable-background="accumulate" fill="#fff" overflow="visible" stroke-width="2" style="text-indent:0;text-transform:none"/>
|
||||
</svg>
|
||||
<strong>{{ site_conf.site_name }}</strong>
|
||||
</a>
|
||||
{% include 'includes/login.html' %}
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<div class="py-2 container">
|
||||
<nav class="navbar navbar-expand-lg navbar-light">
|
||||
<div class="container-fluid g-0">
|
||||
<a class="navbar-brand" href="/">Home</a>
|
||||
{% include 'includes/search.html' %}
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</div>
|
||||
<section class="py-4 text-center container">
|
||||
<div class="row">
|
||||
<div class="mx-auto">
|
||||
{% block header %}{% endblock %}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<div class="album py-5 bg-light">
|
||||
<div class="container">
|
||||
<a id="rolling-stock"></a>
|
||||
<div data-masonry='{"percentPosition": true }' class="row row-cols-1 row-cols-sm-2 row-cols-md-3 g-3">
|
||||
{% block cards %}
|
||||
{% for r in rolling_stock %}
|
||||
<div class="col">
|
||||
<div class="card shadow-sm">
|
||||
{% for i in r.image.all %}
|
||||
{% if i.is_thumbnail %}<a href="/portal/{{ r.uuid }}"><img src="{{ i.image.url }}" alt="Card image cap"></a>{% endif %}
|
||||
{% endfor %}
|
||||
<div class="card-body">
|
||||
<p class="card-text"><strong>{{ r }}</strong></p>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2" scope="row">Data</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th width="35%" scope="row">Type</th>
|
||||
<td>{{ r.rolling_class.type }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Company</th>
|
||||
<td><abbr title="{{ r.rolling_class.company.extended_name }}">{{ r.rolling_class.company }}</abbr></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Class</th>
|
||||
<td>{{ r.rolling_class.identifier }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Road number</th>
|
||||
<td>{{ r.road_number }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Era</th>
|
||||
<td>{{ r.era }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th width="35%" scope="row">Manufacturer</th>
|
||||
<td>{% if r.manufacturer.website %}<a href="{{ r.manufacturer.website }}">{% endif %}{{ r.manufacturer }}{% if r.manufacturer.website %}</a>{% endif %}</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Scale</th>
|
||||
<td><abbr title="{{ r.scale.ratio }} - {{ r.scale.gauge }}">{{ r.scale }}</abbr></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">SKU</th>
|
||||
<td>{{ r.sku }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
{% if r.decoder %}
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2" scope="row">DCC data</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th width="35%" scope="row">Decoder</th>
|
||||
<td>{{ r.decoder }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Address</th>
|
||||
<td>{{ r.address }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
<div class="btn-group mb-4">
|
||||
<a class="btn btn-sm btn-outline-primary" href="/portal/{{ r.uuid }}">Show all data</a>
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:roster_rollingstock_change' r.pk %}">Edit</a>{% endif %}
|
||||
</div>
|
||||
{% if r.tags.all %}
|
||||
<p class="card-text"><small>Tags:</small>
|
||||
{% for t in r.tags.all %}<span class="badge bg-primary">
|
||||
{{ t.name }}</span>{# new line is required #}
|
||||
{% endfor %}
|
||||
</p>
|
||||
{% endif %}
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<small class="text-muted">Updated {{ r.updated_time | date:"M d, Y H:m" }}</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="container">{% block pagination %}{% endblock %}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% block extra_content %}{% endblock %}
|
||||
</main>
|
||||
{% include 'includes/footer.html' %}
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/masonry-layout@4.2.2/dist/masonry.pkgd.min.js" integrity="sha384-GNFwBvfVxBkLMJpYMOABq3c+d3KnQxudP/mGPkzpZSTYykLBNsZEnG2D9G/X/+7D" crossorigin="anonymous" async></script>
|
||||
</body>
|
||||
</html>
|
@@ -1,175 +1,12 @@
|
||||
{% load static %}
|
||||
{% load solo_tags %}
|
||||
{% extends "base.html" %}
|
||||
{% load markdown %}
|
||||
{% get_solo 'portal.SiteConfiguration' as site_conf %}
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
|
||||
<meta name="generator" content="Hugo 0.88.1">
|
||||
<title>{{ site_conf.site_name }}</title>
|
||||
<link rel="canonical" href="https://getbootstrap.com/docs/5.1/examples/album/">
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="{% static "css/main.css" %}" rel="stylesheet">
|
||||
|
||||
<style>
|
||||
.bd-placeholder-img {
|
||||
font-size: 1.125rem;
|
||||
text-anchor: middle;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.bd-placeholder-img-lg {
|
||||
font-size: 3.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header>
|
||||
<div class="navbar navbar-dark bg-dark shadow-sm">
|
||||
<div class="container">
|
||||
<a href="/" class="navbar-brand d-flex align-items-center">
|
||||
<svg class="me-2" width="26" height="16" enable-background="new 0 0 26 26" version="1" viewBox="0 0 26 16" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="m2.8125 0.0010991a1.0001 1.0001 0 0 0-0.8125 1c0 0.55455-0.44545 1-1 1a1.0001 1.0001 0 0 0-1 1v10a1.0001 1.0001 0 0 0 1 1c0.55455 0 1 0.44546 1 1a1.0001 1.0001 0 0 0 1 1h20a1.0001 1.0001 0 0 0 1-1c0-0.55454 0.44546-1 1-1a1.0001 1.0001 0 0 0 1-1v-10a1.0001 1.0001 0 0 0-1-1c-0.55454 0-1-0.44545-1-1a1.0001 1.0001 0 0 0-1-1h-20a1.0001 1.0001 0 0 0-0.09375 0 1.0001 1.0001 0 0 0-0.09375 0zm0.78125 2h14.406v1h2v-1h2.4062c0.30628 0.76906 0.82469 1.2875 1.5938 1.5938v8.8125c-0.76906 0.30628-1.2875 0.82469-1.5938 1.5938h-2.4062v-1h-2v1h-14.406c-0.30628-0.76906-0.82469-1.2875-1.5938-1.5938v-8.8125c0.76906-0.30628 1.2875-0.82469 1.5938-1.5938zm14.406 2v2h2v-2zm0 3v2h2v-2zm0 3v2h2v-2z" enable-background="accumulate" fill="#fff" overflow="visible" stroke-width="2" style="text-indent:0;text-transform:none"/>
|
||||
</svg>
|
||||
<strong>{{ site_conf.site_name }}</strong>
|
||||
</a>
|
||||
{% include 'login.html' %}
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<section class="py-1 text-center container">
|
||||
<div class="row py-lg-4">
|
||||
<div class="mx-auto">
|
||||
{% block header %}
|
||||
<h1 class="fw-light">About</h1>
|
||||
<p class="lead text-muted">{{ site_conf.about | markdown | safe }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
{% endblock %}
|
||||
|
||||
<div class="album py-5 bg-light">
|
||||
<div class="container">
|
||||
<a id="rolling-stock"></a>
|
||||
<div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 g-3">
|
||||
{% for r in rolling_stock %}
|
||||
<div class="col">
|
||||
<div class="card shadow-sm">
|
||||
{% for i in r.image.all %}
|
||||
{% if i.is_thumbnail %}<a href="/portal/{{ r.uuid }}"><img src="{{ i.image.url }}" alt="Card image cap"></a>{% endif %}
|
||||
{% endfor %}
|
||||
<div class="card-body">
|
||||
<p class="card-text"><strong>{{ r }}</strong></p>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2" scope="row">Data</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th width="35%" scope="row">Type</th>
|
||||
<td>{{ r.rolling_class.type }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Company</th>
|
||||
<td><abbr title="{{ r.rolling_class.company.extended_name }}">{{ r.rolling_class.company }}</abbr></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Class</th>
|
||||
<td>{{ r.rolling_class.identifier }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Road number</th>
|
||||
<td>{{ r.road_number }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Era</th>
|
||||
<td>{{ r.era }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="collapse" id="collapseModel{{ r.pk }}">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2" scope="row">Model data</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th width="35%" scope="row">Manufacturer</th>
|
||||
<td>{% if r.manufacturer.website %}<a href="{{ r.manufacturer.website }}">{% endif %}{{ r.manufacturer }}{% if r.manufacturer.website %}</a>{% endif %}</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Scale</th>
|
||||
<td><abbr title="{{ r.scale.ratio }} - {{ r.scale.gauge }}">{{ r.scale }}</abbr></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">SKU</th>
|
||||
<td>{{ r.sku }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% if r.decoder %}
|
||||
<div class="collapse" id="collapseDCC{{ r.pk }}">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2" scope="row">DCC data</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th width="35%" scope="row">Decoder</th>
|
||||
<td>{{ r.decoder }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Address</th>
|
||||
<td>{{ r.address }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="btn-group mb-4">
|
||||
<button class="btn btn-outline-secondary btn-sm" type="button" data-bs-toggle="button"><span data-bs-toggle="collapse" data-bs-target="#collapseModel{{ r.pk }}" aria-expanded="false" aria-controls="collapseModel{{ r.pk }}">Model data</span></button>
|
||||
{% if r.decoder %}
|
||||
<button class="btn btn-outline-secondary btn-sm" type="button" data-bs-toggle="button"> <span data-bs-toggle="collapse" data-bs-target="#collapseDCC{{ r.pk }}" aria-expanded="false" aria-controls="collapseDCC{{ r.pk }}">DCC data</span></button>
|
||||
{% endif %}
|
||||
<a class="btn btn-sm btn-outline-primary" href="/portal/{{ r.uuid }}">Show all data</a>
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:roster_rollingstock_change' r.pk %}">Edit</a>{% endif %}
|
||||
</div>
|
||||
{% if r.tags.all %}
|
||||
<p class="card-text"><small>Tags:</small>
|
||||
{% for t in r.tags.all %}<span class="badge bg-primary">
|
||||
{{ t.name }}</span>{# new line is required #}
|
||||
{% endfor %}
|
||||
</p>
|
||||
{% endif %}
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<small class="text-muted">Updated {{ r.updated_time | date:"M d, Y H:m" }}</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="container">
|
||||
{% block pagination %}
|
||||
{% if rolling_stock.has_other_pages %}
|
||||
<nav aria-label="Page navigation example">
|
||||
<ul class="pagination justify-content-center mt-4">
|
||||
@@ -203,12 +40,4 @@
|
||||
</ul>
|
||||
</nav>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
{% include 'footer.html' %}
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
{% endblock %}
|
||||
|
5
ram/portal/templates/includes/search.html
Normal file
5
ram/portal/templates/includes/search.html
Normal file
@@ -0,0 +1,5 @@
|
||||
<form class="d-flex" action="/portal/search" method="POST">
|
||||
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search" value="{{ search }}" name="search">
|
||||
<button class="btn btn-outline-success" type="submit">Search</button>
|
||||
</form>
|
||||
|
@@ -1,78 +1,26 @@
|
||||
{% load static %}
|
||||
{% load solo_tags %}
|
||||
{% extends 'base.html' %}
|
||||
{% load markdown %}
|
||||
{% get_solo 'portal.SiteConfiguration' as site_conf %}
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
|
||||
<meta name="generator" content="Hugo 0.88.1">
|
||||
<title>{{ site_conf.site_name }}</title>
|
||||
<link rel="canonical" href="https://getbootstrap.com/docs/5.1/examples/album/">
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="{% static "css/main.css" %}" rel="stylesheet">
|
||||
|
||||
<style>
|
||||
.bd-placeholder-img {
|
||||
font-size: 1.125rem;
|
||||
text-anchor: middle;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.bd-placeholder-img-lg {
|
||||
font-size: 3.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header>
|
||||
<div class="navbar navbar-dark bg-dark shadow-sm">
|
||||
<div class="container">
|
||||
<a href="/" class="navbar-brand d-flex align-items-center">
|
||||
<svg class="me-2" width="26" height="16" enable-background="new 0 0 26 26" version="1" viewBox="0 0 26 16" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="m2.8125 0.0010991a1.0001 1.0001 0 0 0-0.8125 1c0 0.55455-0.44545 1-1 1a1.0001 1.0001 0 0 0-1 1v10a1.0001 1.0001 0 0 0 1 1c0.55455 0 1 0.44546 1 1a1.0001 1.0001 0 0 0 1 1h20a1.0001 1.0001 0 0 0 1-1c0-0.55454 0.44546-1 1-1a1.0001 1.0001 0 0 0 1-1v-10a1.0001 1.0001 0 0 0-1-1c-0.55454 0-1-0.44545-1-1a1.0001 1.0001 0 0 0-1-1h-20a1.0001 1.0001 0 0 0-0.09375 0 1.0001 1.0001 0 0 0-0.09375 0zm0.78125 2h14.406v1h2v-1h2.4062c0.30628 0.76906 0.82469 1.2875 1.5938 1.5938v8.8125c-0.76906 0.30628-1.2875 0.82469-1.5938 1.5938h-2.4062v-1h-2v1h-14.406c-0.30628-0.76906-0.82469-1.2875-1.5938-1.5938v-8.8125c0.76906-0.30628 1.2875-0.82469 1.5938-1.5938zm14.406 2v2h2v-2zm0 3v2h2v-2zm0 3v2h2v-2z" enable-background="accumulate" fill="#fff" overflow="visible" stroke-width="2" style="text-indent:0;text-transform:none"/>
|
||||
</svg>
|
||||
<strong>{{ site_conf.site_name }}</strong>
|
||||
</a>
|
||||
{% include 'login.html' %}
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<section class="py-1 text-start container">
|
||||
<div class="row py-lg-4">
|
||||
<div class="mx-auto">
|
||||
<nav style="--bs-breadcrumb-divider: '>';" aria-label="breadcrumb">
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><a href="/">Home</a></li>
|
||||
<li class="breadcrumb-item active" aria-current="page">{{ rolling_stock }}</li>
|
||||
</ol>
|
||||
</nav>
|
||||
{% block header %}
|
||||
<h1 class="fw-light">{{ rolling_stock }}</h1>
|
||||
{% if rolling_stock.tags.all %}
|
||||
<p><small>Tags:</small>
|
||||
{% for t in rolling_stock.tags.all %}<span class="badge bg-primary">
|
||||
{{ t.name }}</span>{# new line is required #}
|
||||
{% if rolling_stock.tags.all %}
|
||||
<p><small>Tags:</small>
|
||||
{% for t in rolling_stock.tags.all %}<span class="badge bg-primary">
|
||||
{{ t.name }}</span>{# new line is required #}
|
||||
{% endfor %}
|
||||
</p>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% block cards %}
|
||||
{% for t in rolling_stock.image.all %}
|
||||
<div class="col">
|
||||
<img class="img-thumbnail" src="{{ t.image.url }}" alt="Rolling stock image">
|
||||
</div>
|
||||
{% endfor %}
|
||||
</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section class="py-1 text-start container">
|
||||
<div class="row py-lg-2">
|
||||
{% endblock %}
|
||||
{% block extra_content %}
|
||||
<section class="py-4 text-start container">
|
||||
<div class="row">
|
||||
<div class="mx-auto">
|
||||
<nav>
|
||||
<div class="nav nav-tabs" id="nav-tab" role="tablist">
|
||||
@@ -299,20 +247,4 @@
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<div class="album py-5 bg-light">
|
||||
<div class="container">
|
||||
<a id="rolling-stock"></a>
|
||||
<div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 g-3">
|
||||
{% for t in rolling_stock.image.all %}
|
||||
<div class="col">
|
||||
<img class="img-thumbnail" src="{{ t.image.url }}" alt="Rolling stock image">
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
{% include 'footer.html' %}
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
{% endblock %}
|
||||
|
41
ram/portal/templates/search.html
Normal file
41
ram/portal/templates/search.html
Normal file
@@ -0,0 +1,41 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block header %}
|
||||
<h1 class="fw-light">Search: {{ search }}</h1>
|
||||
<p class="lead text-muted">Results found: {{ rolling_stock | length }}</p>
|
||||
{% endblock %}
|
||||
{% block pagination %}
|
||||
{% if rolling_stock.has_other_pages %}
|
||||
<nav aria-label="Page navigation example">
|
||||
<ul class="pagination justify-content-center mt-4">
|
||||
{% if rolling_stock.has_previous %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="/portal/search/{{ search }}/{{ rolling_stock.previous_page_number }}#rolling_stock" tabindex="-1">Previous</a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item disabled">
|
||||
<span class="page-link">Previous</span>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% for i in rolling_stock.paginator.page_range %}
|
||||
{% if rolling_stock.number == i %}
|
||||
<li class="page-item active">
|
||||
<span class="page-link">{{ i }}</span></span>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item"><a class="page-link" href="/portal/search/{{ search }}/{{ i }}#rolling-stock">{{ i }}</a></li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if rolling_stock.has_next %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="/portal/search/{{ search }}/{{ rolling_stock.next_page_number }}#rolling-stock" tabindex="-1">Next</a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item disabled">
|
||||
<span class="page-link">Next</span>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</nav>
|
||||
{% endif %}
|
||||
{% endblock %}
|
@@ -1,8 +1,18 @@
|
||||
from django.urls import path
|
||||
|
||||
from portal.views import GetHome, GetRollingStock
|
||||
from portal.views import GetHome, GetHomeFiltered, GetRollingStock
|
||||
|
||||
urlpatterns = [
|
||||
path("", GetHome.as_view(), name='index'),
|
||||
path("<int:page>", GetHome.as_view(), name='index_pagination'),
|
||||
path(
|
||||
"search",
|
||||
GetHomeFiltered.as_view(http_method_names=['post']),
|
||||
name='index_filtered'
|
||||
),
|
||||
path("search/<str:search>",
|
||||
GetHomeFiltered.as_view(), name='index_filtered'),
|
||||
path("search/<str:search>/<int:page>",
|
||||
GetHomeFiltered.as_view(), name='index_filtered_pagination'),
|
||||
path("<uuid:uuid>", GetRollingStock.as_view(), name='rolling_stock'),
|
||||
]
|
||||
|
@@ -1,16 +1,20 @@
|
||||
import operator
|
||||
from functools import reduce
|
||||
|
||||
from django.views import View
|
||||
from django.http import Http404
|
||||
from django.db.models import Q
|
||||
from django.shortcuts import render
|
||||
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
||||
|
||||
from portal.utils import get_site_conf
|
||||
from roster.models import RollingStock, RollingStockImage
|
||||
from roster.models import RollingStock
|
||||
|
||||
|
||||
class GetHome(View):
|
||||
def get(self, request, page=1):
|
||||
site_conf = get_site_conf()
|
||||
rolling_stock = RollingStock.objects.all()
|
||||
thumbnails = RollingStockImage.objects.filter(is_thumbnail=True)
|
||||
paginator = Paginator(rolling_stock, site_conf.items_per_page)
|
||||
|
||||
try:
|
||||
@@ -20,9 +24,59 @@ class GetHome(View):
|
||||
except EmptyPage:
|
||||
rolling_stock = paginator.page(paginator.num_pages)
|
||||
|
||||
return render(request, 'home.html', {
|
||||
'rolling_stock': rolling_stock,
|
||||
'thumbnails': thumbnails
|
||||
return render(request, "home.html", {
|
||||
"rolling_stock": rolling_stock
|
||||
})
|
||||
|
||||
|
||||
class GetHomeFiltered(View):
|
||||
def run_search(self, request, search, page=1):
|
||||
# if not hasattr(RollingStock, _filter):
|
||||
# raise Http404
|
||||
site_conf = get_site_conf()
|
||||
# query = {
|
||||
# _filter: _value
|
||||
# }
|
||||
query = reduce(operator.or_, (Q(
|
||||
Q(rolling_class__identifier__icontains=s) |
|
||||
Q(rolling_class__description__icontains=s) |
|
||||
Q(rolling_class__type__type__icontains=s) |
|
||||
Q(road_number__icontains=s) |
|
||||
Q(rolling_class__company__name__icontains=s) |
|
||||
Q(rolling_class__company__country__icontains=s) |
|
||||
Q(manufacturer__name__icontains=s) |
|
||||
Q(scale__scale__icontains=s) |
|
||||
Q(tags__name__icontains=s)
|
||||
) for s in search.split()))
|
||||
rolling_stock = RollingStock.objects.filter(query)
|
||||
paginator = Paginator(rolling_stock, site_conf.items_per_page)
|
||||
|
||||
try:
|
||||
rolling_stock = paginator.page(page)
|
||||
except PageNotAnInteger:
|
||||
rolling_stock = paginator.page(1)
|
||||
except EmptyPage:
|
||||
rolling_stock = paginator.page(paginator.num_pages)
|
||||
|
||||
return rolling_stock
|
||||
|
||||
def get(self, request, search, page=1):
|
||||
rolling_stock = self.run_search(request, search, page)
|
||||
|
||||
return render(request, "search.html", {
|
||||
"search": search,
|
||||
"rolling_stock": rolling_stock
|
||||
})
|
||||
|
||||
def post(self, request, page=1):
|
||||
search = request.POST.get("search")
|
||||
if not search:
|
||||
raise Http404
|
||||
rolling_stock = self.run_search(request, search, page)
|
||||
|
||||
return render(request, "search.html", {
|
||||
"search": search,
|
||||
"rolling_stock": rolling_stock
|
||||
})
|
||||
|
||||
|
||||
@@ -30,6 +84,6 @@ class GetRollingStock(View):
|
||||
def get(self, request, uuid):
|
||||
rolling_stock = RollingStock.objects.get(uuid=uuid)
|
||||
|
||||
return render(request, 'page.html', {
|
||||
'rolling_stock': rolling_stock,
|
||||
return render(request, "page.html", {
|
||||
"rolling_stock": rolling_stock,
|
||||
})
|
||||
|
@@ -28,7 +28,7 @@ SECRET_KEY = (
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = []
|
||||
ALLOWED_HOSTS = ["*"]
|
||||
|
||||
|
||||
# Application definition
|
||||
|
@@ -14,18 +14,18 @@ Including another URLconf
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.conf import settings
|
||||
from django.shortcuts import redirect
|
||||
from django.conf.urls.static import static
|
||||
from django.contrib import admin
|
||||
from django.urls import include, path
|
||||
|
||||
from portal.utils import get_site_conf
|
||||
from portal.views import GetHome
|
||||
|
||||
site_conf = get_site_conf()
|
||||
admin.site.site_header = site_conf.site_name
|
||||
|
||||
urlpatterns = [
|
||||
path("", GetHome.as_view(), name="index"),
|
||||
path("", lambda r: redirect("/portal/")),
|
||||
path("portal/", include("portal.urls")),
|
||||
path("ht/", include("health_check.urls")),
|
||||
path("admin/", admin.site.urls),
|
||||
|
Reference in New Issue
Block a user