From 5b04abb26281e695a8514450a1fc6701e15c42b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniele=20Vigan=C3=B2?= Date: Sun, 17 Jul 2022 12:25:09 +0200 Subject: [PATCH] Add countries and scales pages --- ram/portal/templates/base.html | 6 ++ ram/portal/templates/companies.html | 93 +++++++++++++++++++++++++++++ ram/portal/templates/consists.html | 2 +- ram/portal/templates/scales.html | 81 +++++++++++++++++++++++++ ram/portal/urls.py | 14 +++++ ram/portal/views.py | 33 ++++++++++ ram/ram/__init__.py | 2 +- 7 files changed, 229 insertions(+), 2 deletions(-) create mode 100644 ram/portal/templates/companies.html create mode 100644 ram/portal/templates/scales.html diff --git a/ram/portal/templates/base.html b/ram/portal/templates/base.html index f75f625..17470d6 100644 --- a/ram/portal/templates/base.html +++ b/ram/portal/templates/base.html @@ -57,6 +57,12 @@ + + {% include 'includes/search.html' %} diff --git a/ram/portal/templates/companies.html b/ram/portal/templates/companies.html new file mode 100644 index 0000000..73741ee --- /dev/null +++ b/ram/portal/templates/companies.html @@ -0,0 +1,93 @@ +{% extends "base.html" %} +{% load markdown %} + + {% block header %} +

Companies

+ {% endblock %} + {% block cards %} + {% for c in company %} +
+
+
+

{{ c.name }}

+ + + + + + + + {% if c.logo %} + + + + + {% endif %} + + + + + + + + + + + + {% if c.freelance %} + + + + + {% endif %} + +
Company
Logo
Name{{ c.extended_name }}
Abbreviation{{ c }}
Country{{ c.country.name }} {{ c.country }} +
NotesA freelance company
+
+ Show all rolling stock + {% if request.user.is_staff %}Edit{% endif %} +
+
+
+
+ {% endfor %} + {% endblock %} + {% block pagination %} + {% if company.has_other_pages %} + + {% endif %} + {% endblock %} diff --git a/ram/portal/templates/consists.html b/ram/portal/templates/consists.html index 0b9efe8..4a4d3ed 100644 --- a/ram/portal/templates/consists.html +++ b/ram/portal/templates/consists.html @@ -76,7 +76,7 @@ {{ i }} {% else %} - {% if i == rolling_stock.paginator.ELLIPSIS %} + {% if i == consist.paginator.ELLIPSIS %}
  • {{ i }}
  • {% else %}
  • {{ i }}
  • diff --git a/ram/portal/templates/scales.html b/ram/portal/templates/scales.html new file mode 100644 index 0000000..b801119 --- /dev/null +++ b/ram/portal/templates/scales.html @@ -0,0 +1,81 @@ +{% extends "base.html" %} +{% load markdown %} + + {% block header %} +

    Scales

    + {% endblock %} + {% block cards %} + {% for s in scale %} +
    +
    +
    +

    {{ s }}

    + + + + + + + + + + + + + + + + + + + + +
    Scale
    Name{{ s.scale }}
    Ratio{{ s.ratio }}
    Gauge{{ s.gauge }}
    +
    + Show all rolling stock + {% if request.user.is_staff %}Edit{% endif %} +
    +
    +
    +
    + {% endfor %} + {% endblock %} + {% block pagination %} + {% if scale.has_other_pages %} + + {% endif %} + {% endblock %} diff --git a/ram/portal/urls.py b/ram/portal/urls.py index d3be28d..3ae5731 100644 --- a/ram/portal/urls.py +++ b/ram/portal/urls.py @@ -6,6 +6,8 @@ from portal.views import ( GetRollingStock, GetConsist, Consists, + Companies, + Scales, ) urlpatterns = [ @@ -32,6 +34,18 @@ urlpatterns = [ GetConsist.as_view(), name="consist_pagination", ), + path("companies", Companies.as_view(), name="companies"), + path( + "companies/", + Companies.as_view(), + name="companies_pagination" + ), + path("scales", Scales.as_view(), name="scales"), + path( + "scales/", + Scales.as_view(), + name="scales_pagination" + ), path( "/", GetHomeFiltered.as_view(), diff --git a/ram/portal/views.py b/ram/portal/views.py index f0bc8b9..442f129 100644 --- a/ram/portal/views.py +++ b/ram/portal/views.py @@ -11,6 +11,7 @@ from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from portal.utils import get_site_conf from roster.models import RollingStock from consist.models import Consist +from metadata.models import Company, Scale def order_by_fields(): @@ -196,3 +197,35 @@ class GetConsist(View): "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}, + ) diff --git a/ram/ram/__init__.py b/ram/ram/__init__.py index e15a6f4..58d95ab 100644 --- a/ram/ram/__init__.py +++ b/ram/ram/__init__.py @@ -1,4 +1,4 @@ from ram.utils import git_suffix -__version__ = "0.0.6" +__version__ = "0.0.7" __version__ += git_suffix(__file__)