Merge pull request #6 from daniviga/gui

Implement the rolling stock view
This commit is contained in:
2022-04-12 22:53:33 +02:00
committed by GitHub
13 changed files with 421 additions and 108 deletions

View File

@@ -1,5 +1,5 @@
from django.contrib import admin from django.contrib import admin
from adminsortable2.admin import SortableInlineAdminMixin from adminsortable2.admin import SortableAdminBase, SortableInlineAdminMixin
from consist.models import Consist, ConsistItem from consist.models import Consist, ConsistItem
@@ -12,7 +12,7 @@ class ConsistItemInline(SortableInlineAdminMixin, admin.TabularInline):
@admin.register(Consist) @admin.register(Consist)
class ConsistAdmin(admin.ModelAdmin): class ConsistAdmin(SortableAdminBase, admin.ModelAdmin):
inlines = (ConsistItemInline,) inlines = (ConsistItemInline,)
readonly_fields = ( readonly_fields = (
"creation_time", "creation_time",

View File

@@ -6,6 +6,14 @@
display: inline-block; display: inline-block;
} }
.tab-pane {
min-height: 300px;
}
#nav-notes > p {
padding: .5rem;
}
#footer > p { #footer > p {
display: inline; display: inline;
} }

View File

@@ -1,75 +0,0 @@
{% load static %}
{% load breadcrumbs %}
{% load solo_tags %}
{% 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, shrink-to-fit=no">
<meta name="description" content="{{ site_conf.about }}">
<meta name="author" content="{{ site_conf.site_author }}">
<link rel="icon" type="image/png" href="{% static 'favicon-196x196.png' %}" sizes="196x196">
<link rel="icon" type="image/png" href="{% static 'favicon-128.png' %}" sizes="128x128">
<link rel="icon" type="image/png" href="{% static 'favicon-96x96.png' %}" sizes="96x96">
<link rel="icon" type="image/png" href="{% static 'favicon-32x32.png' %}" sizes="32x32">
<link rel="icon" type="image/png" href="{% static 'favicon-16x16.png' %}" sizes="16x16">
<title>{{ site_conf.site_name }} - {{ page.name }}</title>
<!-- Bootstrap core CSS -->
<link href="{% static "css/dist/bootstrap.min.css" %}" rel="stylesheet">
<link href="{% static "css/fonts.css" %}" rel="stylesheet">
<link href="{% static "css/main.css" %}" rel="stylesheet">
{% if site_conf.common_css %}<link rel="stylesheet" href="{{ site_conf.common_css.url }}">{% endif %}
</head>
<body class="bg-dark">
<div class="container-fluid h-100 d-flex flex-column">
<header>
{% include 'navbar.html' %}
<div class="row collapse bg-dark shadow-sm" id="navbarHeader">
<div class="container">
<div class="row">
<div class="col-sm-8 col-md-7 py-4">
{% if site_conf.about %}<h4 class="text-white">About</h4>
<p class="text-muted">{{ site_conf.about | safe }}</p>{% endif %}
{% breadcrumbs page.path %}
</div>
<div class="col-sm-4 offset-md-1 py-4 text-right">
{% if request.user.is_staff %}<div class="dropdown btn-group">
<button class="btn btn-sm btn-outline-danger dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Edit
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="{% url 'admin:portal_flatpage_change' page.pk %}">Edit page</a>
<a class="dropdown-item" href="{% url 'admin:portal_flatpage_history' page.pk %}">History</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item text-danger" href="{% url 'admin:portal_flatpage_delete' page.pk %}">Delete</a>
</div>
</div>{% endif %}
{% include 'login.html' %}
</div>
</div>
</div>
</div>
</header>
</div>
<main>
<div class="album py-5 bg-white">
<div class="container">
{{ content }}
</div>
</div>
</main>
{% include 'footer.html' %}
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="{% static "js/dist/jquery.min.js" %}"></script>
<script src="{% static "js/dist/bootstrap.bundle.min.js" %}"></script>
</body>
</html>

View File

@@ -1,6 +1,6 @@
{% load markdown %} {% load markdown %}
<footer class="text-muted py-5"> <footer class="text-muted py-4">
<div class="container"> <div class="container">
<p class="float-end mb-1"> <p class="float-end mb-1">
<a href="#">Back to top</a> <a href="#">Back to top</a>

View File

@@ -39,7 +39,7 @@
<header> <header>
<div class="navbar navbar-dark bg-dark shadow-sm"> <div class="navbar navbar-dark bg-dark shadow-sm">
<div class="container"> <div class="container">
<a href="#" class="navbar-brand d-flex align-items-center"> <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"> <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"/> <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> </svg>
@@ -51,8 +51,8 @@
</header> </header>
<main> <main>
<section class="py-1 text-start container"> <section class="py-1 text-center container">
<div class="row py-lg-5"> <div class="row py-lg-4">
<div class="mx-auto"> <div class="mx-auto">
<h1 class="fw-light">About</h1> <h1 class="fw-light">About</h1>
<p class="lead text-muted">{{ site_conf.about | markdown | safe }}</p> <p class="lead text-muted">{{ site_conf.about | markdown | safe }}</p>
@@ -67,11 +67,9 @@
{% for r in rolling_stock %} {% for r in rolling_stock %}
<div class="col"> <div class="col">
<div class="card shadow-sm"> <div class="card shadow-sm">
<a href="#"> {% for i in r.image.all %}
{% for t in r.thumbnail.all %}{% if t.is_thumbnail %}<img src="{{ t.image.url }}" alt="Card image cap"> {% if i.is_thumbnail %}<a href="/portal/{{ r.uuid }}"><img src="{{ i.image.url }}" alt="Card image cap"></a>{% endif %}
{% else %} {% endfor %}
<svg class="bd-placeholder-img card-img-top" width="100%" height="225" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Placeholder: Thumbnail" preserveAspectRatio="xMidYMid slice" focusable="false"><title>Placeholder</title><rect width="100%" height="100%" fill="#55595c"/><text x="50%" y="50%" fill="#eceeef" dy=".3em">Missing thumbnail</text></svg>
{% endif %}</a>{% endfor %}
<div class="card-body"> <div class="card-body">
<p class="card-text"><strong>{{ r }}</strong></p> <p class="card-text"><strong>{{ r }}</strong></p>
<table class="table table-striped"> <table class="table table-striped">
@@ -87,7 +85,7 @@
</tr> </tr>
<tr> <tr>
<th scope="row">Company</th> <th scope="row">Company</th>
<td>{{ r.rolling_class.company }}</td> <td><abbr title="{{ r.rolling_class.company.extended_name }}">{{ r.rolling_class.company }}</abbr></td>
</tr> </tr>
<tr> <tr>
<th scope="row">Class</th> <th scope="row">Class</th>
@@ -103,14 +101,6 @@
</tr> </tr>
</tbody> </tbody>
</table> </table>
<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="#">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>
<div class="collapse" id="collapseModel{{ r.pk }}"> <div class="collapse" id="collapseModel{{ r.pk }}">
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
@@ -121,11 +111,11 @@
<tbody> <tbody>
<tr> <tr>
<th width="35%" scope="row">Manufacturer</th> <th width="35%" scope="row">Manufacturer</th>
<td>{{ r.manufacturer }}</td> <td>{% if r.manufacturer.website %}<a href="{{ r.manufacturer.website }}">{% endif %}{{ r.manufacturer }}{% if r.manufacturer.website %}</a>{% endif %}</th>
</tr> </tr>
<tr> <tr>
<th scope="row">Scale</th> <th scope="row">Scale</th>
<td>{{ r.scale }}</td> <td><abbr title="{{ r.scale.ratio }} - {{ r.scale.gauge }}">{{ r.scale }}</abbr></td>
</tr> </tr>
<tr> <tr>
<th scope="row">SKU</th> <th scope="row">SKU</th>
@@ -155,13 +145,21 @@
</table> </table>
</div> </div>
{% endif %} {% 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 %} {% if r.tags.all %}
<p class="card-text"><small>Tags:</small> <p class="card-text"><small>Tags:</small>
{% for t in r.tags.all %}<span class="badge bg-primary"> {% for t in r.tags.all %}<span class="badge bg-primary">
{{ t.name }}</span>{# new line is required #} {{ t.name }}</span>{# new line is required #}
{% endfor %} {% endfor %}
{% endif %}
</p> </p>
{% endif %}
<div class="d-flex justify-content-between align-items-center"> <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> <small class="text-muted">Updated {{ r.updated_time | date:"M d, Y H:m" }}</small>
</div> </div>
@@ -177,7 +175,7 @@
<ul class="pagination justify-content-center mt-4"> <ul class="pagination justify-content-center mt-4">
{% if rolling_stock.has_previous %} {% if rolling_stock.has_previous %}
<li class="page-item"> <li class="page-item">
<a class="page-link" href="/page/{{ rolling_stock.previous_page_number }}#rolling_stock" tabindex="-1">Previous</a> <a class="page-link" href="/portal/{{ rolling_stock.previous_page_number }}#rolling_stock" tabindex="-1">Previous</a>
</li> </li>
{% else %} {% else %}
<li class="page-item disabled"> <li class="page-item disabled">
@@ -190,12 +188,12 @@
<span class="page-link">{{ i }}</span></span> <span class="page-link">{{ i }}</span></span>
</li> </li>
{% else %} {% else %}
<li class="page-item"><a class="page-link" href="/page/{{ i }}#rolling-stock">{{ i }}</a></li> <li class="page-item"><a class="page-link" href="/portal/{{ i }}#rolling-stock">{{ i }}</a></li>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% if rolling_stock.has_next %} {% if rolling_stock.has_next %}
<li class="page-item"> <li class="page-item">
<a class="page-link" href="/page/{{ rolling_stock.next_page_number }}#rolling-stock" tabindex="-1">Next</a> <a class="page-link" href="/portal/{{ rolling_stock.next_page_number }}#rolling-stock" tabindex="-1">Next</a>
</li> </li>
{% else %} {% else %}
<li class="page-item disabled"> <li class="page-item disabled">

View File

@@ -0,0 +1,318 @@
{% 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 '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>
<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 #}
{% endfor %}
</p>
{% endif %}
</div>
</div>
</section>
<section class="py-1 text-start container">
<div class="row py-lg-2">
<div class="mx-auto">
<nav>
<div class="nav nav-tabs" id="nav-tab" role="tablist">
<button class="nav-link active" id="nav-summary-tab" data-bs-toggle="tab" data-bs-target="#nav-summary" type="button" role="tab" aria-controls="nav-summary" aria-selected="true">Summary</button>
<button class="nav-link" id="nav-model-tab" data-bs-toggle="tab" data-bs-target="#nav-model" type="button" role="tab" aria-controls="nav-model" aria-selected="false">Model data</button>
<button class="nav-link" id="nav-class-tab" data-bs-toggle="tab" data-bs-target="#nav-class" type="button" role="tab" aria-controls="nav-class" aria-selected="false">Class data</button>
{% if rolling_stock.decoder %}<button class="nav-link" id="nav-dcc-tab" data-bs-toggle="tab" data-bs-target="#nav-dcc" type="button" role="tab" aria-controls="nav-dcc" aria-selected="false">DCC</button>{% endif %}
{% if rolling_stock.notes %}<button class="nav-link" id="nav-notes-tab" data-bs-toggle="tab" data-bs-target="#nav-notes" type="button" role="tab" aria-controls="nav-notes" aria-selected="false">Notes</button>{% endif %}
{% if rolling_stock.property.count > 0 %}<button class="nav-link" id="nav-properties-tab" data-bs-toggle="tab" data-bs-target="#nav-properties" type="button" role="tab" aria-controls="nav-properties" aria-selected="false">Properties</button>{% endif %}
{% if rolling_stock.document.count > 0 %}<button class="nav-link" id="nav-documents-tab" data-bs-toggle="tab" data-bs-target="#nav-documents" type="button" role="tab" aria-controls="nav-documents" aria-selected="false">Documents</button>{% endif %}
</div>
</nav>
<div class="tab-content" id="nav-tabContent">
<div class="tab-pane fade show active" id="nav-summary" role="tabpanel" aria-labelledby="nav-summary-tab">
<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>{{ rolling_stock.rolling_class.type }}</td>
</tr>
<tr>
<th scope="row">Company</th>
<td><abbr title="{{ rolling_stock.rolling_class.company.extended_name }}">{{ rolling_stock.rolling_class.company }}</abbr></td>
</tr>
<tr>
<th scope="row">Class</th>
<td>{{ rolling_stock.rolling_class.identifier }}</td>
</tr>
<tr>
<th scope="row">Road number</th>
<td>{{ rolling_stock.road_number }}</td>
</tr>
<tr>
<th scope="row">Era</th>
<td>{{ rolling_stock.era }}</td>
</tr>
</tbody>
</table>
<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 rolling_stock.manufacturer.website %}<a href="{{ rolling_stock.manufacturer.website }}">{% endif %}{{ rolling_stock.manufacturer }}{% if rolling_stock.manufacturer.website %}</a>{% endif %}</th>
</tr>
<tr>
<th scope="row">Scale</th>
<td><abbr title="{{ rolling_stock.scale.ratio }} - {{ rolling_stock.scale.gauge }}">{{ rolling_stock.scale }}</abbr></td>
</tr>
<tr>
<th scope="row">SKU</th>
<td>{{ rolling_stock.sku }}</td>
</tr>
</tbody>
</table>
{% if rolling_stock.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>{{ rolling_stock.decoder }}</td>
</tr>
<tr>
<th scope="row">Address</th>
<td>{{ rolling_stock.address }}</td>
</tr>
</tbody>
</table>
{% endif %}
</div>
<div class="tab-pane fade" id="nav-model" role="tabpanel" aria-labelledby="nav-model-tab">
<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 rolling_stock.manufacturer.website %}<a href="{{ rolling_stock.manufacturer.website }}">{% endif %}{{ rolling_stock.manufacturer }}{% if rolling_stock.manufacturer.website %}</a>{% endif %}</th>
</tr>
<tr>
<th scope="row">Scale</th>
<td><abbr title="{{ rolling_stock.scale.ratio }} - {{ rolling_stock.scale.gauge }}">{{ rolling_stock.scale }}</abbr></td>
</tr>
<tr>
<th scope="row">SKU</th>
<td>{{ rolling_stock.sku }}</td>
</tr>
<tr>
<th scope="row">ERA</th>
<td>{{ rolling_stock.era }}</td>
</tr>
<tr>
<th scope="row">Production year</th>
<td>{{ rolling_stock.production_year | default_if_none:"" }}</td>
</tr>
<tr>
<th scope="row">Purchase date</th>
<td>{{ rolling_stock.purchase_date | default_if_none:"" }}</td>
</tr>
</tbody>
</table>
</div>
<div class="tab-pane fade" id="nav-class" role="tabpanel" aria-labelledby="nav-class-tab">
<table class="table table-striped">
<thead>
<tr>
<th colspan="2" scope="row">Class data</th>
</tr>
</thead>
<tbody>
<tr>
<th width="35%" scope="row">Class</th>
<td>{{ rolling_stock.rolling_class }}</td>
</tr>
<tr>
<th scope="row">Type</th>
<td>{{ rolling_stock.rolling_class.type }}</td>
</tr>
<tr>
<th scope="row">Company</th>
<td>{{ rolling_stock.rolling_class.company }} ({{ rolling_stock.rolling_class.company.extended_name }})</td>
</tr>
<tr>
<th scope="row">Country</th>
<td>{{ rolling_stock.rolling_class.company.country.name }}</td>
</tr>
<tr>
<th scope="row">Manufacturer</th>
<td>{{ rolling_stock.rolling_class.manufacturer }}</td>
</tr>
</tbody>
</table>
</div>
<div class="tab-pane fade" id="nav-dcc" role="tabpanel" aria-labelledby="nav-dcc-tab">
<table class="table table-striped">
<thead>
<tr>
<th colspan="2" scope="row">DCC data</th>
</tr>
</thead>
<tbody>
<tr>
<th width="35%" scope="row">Name</th>
<td>{{ rolling_stock.decoder.name }}</td>
</tr>
<tr>
<th scope="row">Manufacturer</th>
<td>{{ rolling_stock.decoder.manufacturer }}</td>
</tr>
<tr>
<th scope="row">Version</th>
<td>{{ rolling_stock.decoder.version }}</td>
</tr>
<tr>
<th scope="row">Interface</th>
<td>{{ rolling_stock.decoder.get_interface_display }}</td>
</tr>
<tr>
<th scope="row">Sound</th>
<td>{{ rolling_stock.decoder.sound | yesno:"Yes,No" }}</td>
</tr>
</tbody>
</table>
</div>
<div class="tab-pane fade" id="nav-notes" role="tabpanel" aria-labelledby="nav-notes-tab">
{{ rolling_stock.notes | markdown | safe }}
</div>
<div class="tab-pane fade" id="nav-properties" role="tabpanel" aria-labelledby="nav-properties-tab">
<table class="table table-striped">
<thead>
<tr>
<th colspan="2" scope="row">Properties</th>
</tr>
</thead>
<tbody>
{% for p in rolling_stock.property.all %}
<tr>
<th scope="row">{{ p.property }}</th>
<td>{{ p.value }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="tab-pane fade" id="nav-documents" role="tabpanel" aria-labelledby="nav-documents-tab">
<table class="table table-striped">
<thead>
<tr>
<th colspan="3" scope="row">Documents</th>
</tr>
</thead>
<tbody>
{% for d in rolling_stock.document.all %}
<tr>
<td>{{ d.description }}</td>
<td><a href="{{ d.file.url }}">{{ d.filename }}</a></td>
<td class="text-end">{{ d.file.size | filesizeformat }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</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="{% url 'admin:roster_rollingstock_change' rolling_stock.pk %}">Edit</a>{% endif %}
</div>
</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>

View File

@@ -1,7 +1,8 @@
from django.urls import path from django.urls import path
from portal.views import GetHome from portal.views import GetHome, GetRollingStock
urlpatterns = [ urlpatterns = [
path("<int:page>", GetHome.as_view(), name='index_pagination'), path("<int:page>", GetHome.as_view(), name='index_pagination'),
path("<uuid:uuid>", GetRollingStock.as_view(), name='rolling_stock'),
] ]

View File

@@ -24,3 +24,12 @@ class GetHome(View):
'rolling_stock': rolling_stock, 'rolling_stock': rolling_stock,
'thumbnails': thumbnails 'thumbnails': thumbnails
}) })
class GetRollingStock(View):
def get(self, request, uuid):
rolling_stock = RollingStock.objects.get(uuid=uuid)
return render(request, 'page.html', {
'rolling_stock': rolling_stock,
})

View File

@@ -42,10 +42,10 @@ INSTALLED_APPS = [
"django.contrib.staticfiles", "django.contrib.staticfiles",
"health_check", "health_check",
"health_check.db", "health_check.db",
"adminsortable2",
"django_countries", "django_countries",
"solo", "solo",
"rest_framework", "rest_framework",
"adminsortable2",
"ram", "ram",
"portal", "portal",
"driver", "driver",

View File

@@ -26,7 +26,7 @@ admin.site.site_header = site_conf.site_name
urlpatterns = [ urlpatterns = [
path("", GetHome.as_view(), name="index"), path("", GetHome.as_view(), name="index"),
path("page/", include("portal.urls")), path("portal/", include("portal.urls")),
path("ht/", include("health_check.urls")), path("ht/", include("health_check.urls")),
path("admin/", admin.site.urls), path("admin/", admin.site.urls),
path("api/v1/consist/", include("consist.urls")), path("api/v1/consist/", include("consist.urls")),

View File

@@ -0,0 +1,24 @@
# Generated by Django 4.0.3 on 2022-04-12 19:20
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('roster', '0003_alter_rollingstockimage_rolling_stock'),
]
operations = [
migrations.AlterField(
model_name='rollingstockdocument',
name='rolling_stock',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='document', to='roster.rollingstock'),
),
migrations.AlterField(
model_name='rollingstockimage',
name='rolling_stock',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='image', to='roster.rollingstock'),
),
]

View File

@@ -0,0 +1,19 @@
# Generated by Django 4.0.3 on 2022-04-12 19:35
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('roster', '0004_alter_rollingstockdocument_rolling_stock_and_more'),
]
operations = [
migrations.AlterField(
model_name='rollingstockproperty',
name='rolling_stock',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='property', to='roster.rollingstock'),
),
]

View File

@@ -1,7 +1,7 @@
import os import os
from uuid import uuid4 from uuid import uuid4
from django.db import models from django.db import models
from django.urls import reverse
# from django.core.files.storage import FileSystemStorage # from django.core.files.storage import FileSystemStorage
# from django.dispatch import receiver # from django.dispatch import receiver
@@ -100,6 +100,9 @@ class RollingStock(models.Model):
def __str__(self): def __str__(self):
return "{0} {1}".format(self.rolling_class, self.road_number) return "{0} {1}".format(self.rolling_class, self.road_number)
def get_absolute_url(self):
return reverse("rolling_stock", kwargs={"uuid": self.uuid})
def country(self): def country(self):
return str(self.rolling_class.company.country) return str(self.rolling_class.company.country)
@@ -108,7 +111,11 @@ class RollingStock(models.Model):
class RollingStockDocument(models.Model): class RollingStockDocument(models.Model):
rolling_stock = models.ForeignKey(RollingStock, on_delete=models.CASCADE) rolling_stock = models.ForeignKey(
RollingStock,
on_delete=models.CASCADE,
related_name="document"
)
description = models.CharField(max_length=128, blank=True) description = models.CharField(max_length=128, blank=True)
file = models.FileField(upload_to="files/", null=True, blank=True) file = models.FileField(upload_to="files/", null=True, blank=True)
@@ -117,14 +124,17 @@ class RollingStockDocument(models.Model):
def __str__(self): def __str__(self):
return "{0}".format(os.path.basename(self.file.name)) return "{0}".format(os.path.basename(self.file.name))
# return "{0}".format(self.description)
def filename(self):
return os.path.basename(self.file.name)
class RollingStockImage(models.Model): class RollingStockImage(models.Model):
rolling_stock = models.ForeignKey( rolling_stock = models.ForeignKey(
RollingStock, RollingStock,
on_delete=models.CASCADE, on_delete=models.CASCADE,
related_name="thumbnail") related_name="image"
)
image = models.ImageField(upload_to="images/", null=True, blank=True) image = models.ImageField(upload_to="images/", null=True, blank=True)
is_thumbnail = models.BooleanField() is_thumbnail = models.BooleanField()
@@ -147,6 +157,7 @@ class RollingStockProperty(models.Model):
rolling_stock = models.ForeignKey( rolling_stock = models.ForeignKey(
RollingStock, RollingStock,
on_delete=models.CASCADE, on_delete=models.CASCADE,
related_name="property",
null=False, null=False,
blank=False blank=False
) )