mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 13:17:50 +02:00
Add countries and scales pages
This commit is contained in:
@@ -57,6 +57,12 @@
|
|||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="{% url 'consists' %}">Consists</a>
|
<a class="nav-link" href="{% url 'consists' %}">Consists</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="{% url 'companies' %}">Companies</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="{% url 'scales' %}">Scales</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
{% include 'includes/search.html' %}
|
{% include 'includes/search.html' %}
|
||||||
</div>
|
</div>
|
||||||
|
93
ram/portal/templates/companies.html
Normal file
93
ram/portal/templates/companies.html
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% load markdown %}
|
||||||
|
|
||||||
|
{% block header %}
|
||||||
|
<h1 class="fw-light">Companies</h1>
|
||||||
|
{% endblock %}
|
||||||
|
{% block cards %}
|
||||||
|
{% for c in company %}
|
||||||
|
<div class="col">
|
||||||
|
<div class="card shadow-sm">
|
||||||
|
<div class="card-body">
|
||||||
|
<p class="card-text"><strong>{{ c.name }}</strong></p>
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th colspan="2" scope="row">Company</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% if c.logo %}
|
||||||
|
<tr>
|
||||||
|
<th width="35%" scope="row">Logo</th>
|
||||||
|
<td><img style="max-height: 48px" src="{{ c.logo.url }}" /></td>
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
|
<tr>
|
||||||
|
<th width="35%" scope="row">Name</th>
|
||||||
|
<td>{{ c.extended_name }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th width="35%" scope="row">Abbreviation</th>
|
||||||
|
<td>{{ c }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th width="35%" scope="row">Country</th>
|
||||||
|
<td>{{ c.country.name }} <img src="{{ c.country.flag }}" alt="{{ c.country }}" />
|
||||||
|
</tr>
|
||||||
|
{% if c.freelance %}
|
||||||
|
<tr>
|
||||||
|
<th width="35%" scope="row">Notes</th>
|
||||||
|
<td>A <em>freelance</em> company</td>
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<div class="btn-group mb-4">
|
||||||
|
<a class="btn btn-sm btn-outline-primary" href="{% url 'filtered' _filter="company" search=c %}">Show all rolling stock</a>
|
||||||
|
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:metadata_company_change' c.pk %}">Edit</a>{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
{% endblock %}
|
||||||
|
{% block pagination %}
|
||||||
|
{% if company.has_other_pages %}
|
||||||
|
<nav aria-label="Page navigation example">
|
||||||
|
<ul class="pagination justify-content-center mt-4">
|
||||||
|
{% if company.has_previous %}
|
||||||
|
<li class="page-item">
|
||||||
|
<a class="page-link" href="{% url 'company_pagination' page=company.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 page_range %}
|
||||||
|
{% if company.number == i %}
|
||||||
|
<li class="page-item active">
|
||||||
|
<span class="page-link">{{ i }}</span></span>
|
||||||
|
</li>
|
||||||
|
{% else %}
|
||||||
|
{% if i == company.paginator.ELLIPSIS %}
|
||||||
|
<li class="page-item"><span class="page-link">{{ i }}</span></li>
|
||||||
|
{% else %}
|
||||||
|
<li class="page-item"><a class="page-link" href="{% url 'company_pagination' page=i %}#rolling-stock">{{ i }}</a></li>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% if company.has_next %}
|
||||||
|
<li class="page-item">
|
||||||
|
<a class="page-link" href="{% url 'company_pagination' page=company.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 %}
|
@@ -76,7 +76,7 @@
|
|||||||
<span class="page-link">{{ i }}</span></span>
|
<span class="page-link">{{ i }}</span></span>
|
||||||
</li>
|
</li>
|
||||||
{% else %}
|
{% else %}
|
||||||
{% if i == rolling_stock.paginator.ELLIPSIS %}
|
{% if i == consist.paginator.ELLIPSIS %}
|
||||||
<li class="page-item"><span class="page-link">{{ i }}</span></li>
|
<li class="page-item"><span class="page-link">{{ i }}</span></li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li class="page-item"><a class="page-link" href="{% url 'consists_pagination' page=i %}#rolling-stock">{{ i }}</a></li>
|
<li class="page-item"><a class="page-link" href="{% url 'consists_pagination' page=i %}#rolling-stock">{{ i }}</a></li>
|
||||||
|
81
ram/portal/templates/scales.html
Normal file
81
ram/portal/templates/scales.html
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% load markdown %}
|
||||||
|
|
||||||
|
{% block header %}
|
||||||
|
<h1 class="fw-light">Scales</h1>
|
||||||
|
{% endblock %}
|
||||||
|
{% block cards %}
|
||||||
|
{% for s in scale %}
|
||||||
|
<div class="col">
|
||||||
|
<div class="card shadow-sm">
|
||||||
|
<div class="card-body">
|
||||||
|
<p class="card-text"><strong>{{ s }}</strong></p>
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th colspan="2" scope="row">Scale</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th width="35%" scope="row">Name</th>
|
||||||
|
<td>{{ s.scale }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th width="35%" scope="row">Ratio</th>
|
||||||
|
<td>{{ s.ratio }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th width="35%" scope="row">Gauge</th>
|
||||||
|
<td>{{ s.gauge }}</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<div class="btn-group mb-4">
|
||||||
|
<a class="btn btn-sm btn-outline-primary" href="{% url 'filtered' _filter="scale" search=s %}">Show all rolling stock</a>
|
||||||
|
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:metadata_scale_change' s.pk %}">Edit</a>{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
{% endblock %}
|
||||||
|
{% block pagination %}
|
||||||
|
{% if scale.has_other_pages %}
|
||||||
|
<nav aria-label="Page navigation example">
|
||||||
|
<ul class="pagination justify-content-center mt-4">
|
||||||
|
{% if scale.has_previous %}
|
||||||
|
<li class="page-item">
|
||||||
|
<a class="page-link" href="{% url 'scale_pagination' page=scale.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 page_range %}
|
||||||
|
{% if scale.number == i %}
|
||||||
|
<li class="page-item active">
|
||||||
|
<span class="page-link">{{ i }}</span></span>
|
||||||
|
</li>
|
||||||
|
{% else %}
|
||||||
|
{% if i == scale.paginator.ELLIPSIS %}
|
||||||
|
<li class="page-item"><span class="page-link">{{ i }}</span></li>
|
||||||
|
{% else %}
|
||||||
|
<li class="page-item"><a class="page-link" href="{% url 'scale_pagination' page=i %}#rolling-stock">{{ i }}</a></li>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% if scale.has_next %}
|
||||||
|
<li class="page-item">
|
||||||
|
<a class="page-link" href="{% url 'scale_pagination' page=scale.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 %}
|
@@ -6,6 +6,8 @@ from portal.views import (
|
|||||||
GetRollingStock,
|
GetRollingStock,
|
||||||
GetConsist,
|
GetConsist,
|
||||||
Consists,
|
Consists,
|
||||||
|
Companies,
|
||||||
|
Scales,
|
||||||
)
|
)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
@@ -32,6 +34,18 @@ urlpatterns = [
|
|||||||
GetConsist.as_view(),
|
GetConsist.as_view(),
|
||||||
name="consist_pagination",
|
name="consist_pagination",
|
||||||
),
|
),
|
||||||
|
path("companies", Companies.as_view(), name="companies"),
|
||||||
|
path(
|
||||||
|
"companies/<int:page>",
|
||||||
|
Companies.as_view(),
|
||||||
|
name="companies_pagination"
|
||||||
|
),
|
||||||
|
path("scales", Scales.as_view(), name="scales"),
|
||||||
|
path(
|
||||||
|
"scales/<int:page>",
|
||||||
|
Scales.as_view(),
|
||||||
|
name="scales_pagination"
|
||||||
|
),
|
||||||
path(
|
path(
|
||||||
"<str:_filter>/<str:search>",
|
"<str:_filter>/<str:search>",
|
||||||
GetHomeFiltered.as_view(),
|
GetHomeFiltered.as_view(),
|
||||||
|
@@ -11,6 +11,7 @@ from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
|||||||
from portal.utils import get_site_conf
|
from portal.utils import get_site_conf
|
||||||
from roster.models import RollingStock
|
from roster.models import RollingStock
|
||||||
from consist.models import Consist
|
from consist.models import Consist
|
||||||
|
from metadata.models import Company, Scale
|
||||||
|
|
||||||
|
|
||||||
def order_by_fields():
|
def order_by_fields():
|
||||||
@@ -196,3 +197,35 @@ class GetConsist(View):
|
|||||||
"page_range": page_range,
|
"page_range": page_range,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class Companies(View):
|
||||||
|
def get(self, request, page=1):
|
||||||
|
site_conf = get_site_conf()
|
||||||
|
company = Company.objects.all()
|
||||||
|
|
||||||
|
paginator = Paginator(company, site_conf.items_per_page)
|
||||||
|
company = paginator.get_page(page)
|
||||||
|
page_range = paginator.get_elided_page_range(company.number)
|
||||||
|
|
||||||
|
return render(
|
||||||
|
request,
|
||||||
|
"companies.html",
|
||||||
|
{"company": company, "page_range": page_range},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class Scales(View):
|
||||||
|
def get(self, request, page=1):
|
||||||
|
site_conf = get_site_conf()
|
||||||
|
scale = Scale.objects.all()
|
||||||
|
|
||||||
|
paginator = Paginator(scale, site_conf.items_per_page)
|
||||||
|
scale = paginator.get_page(page)
|
||||||
|
page_range = paginator.get_elided_page_range(scale.number)
|
||||||
|
|
||||||
|
return render(
|
||||||
|
request,
|
||||||
|
"scales.html",
|
||||||
|
{"scale": scale, "page_range": page_range},
|
||||||
|
)
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
from ram.utils import git_suffix
|
from ram.utils import git_suffix
|
||||||
|
|
||||||
__version__ = "0.0.6"
|
__version__ = "0.0.7"
|
||||||
__version__ += git_suffix(__file__)
|
__version__ += git_suffix(__file__)
|
||||||
|
Reference in New Issue
Block a user