diff --git a/dcc/dcc/__init__.py b/dcc/dcc/__init__.py index e69de29..fab61a8 100644 --- a/dcc/dcc/__init__.py +++ b/dcc/dcc/__init__.py @@ -0,0 +1,23 @@ +import os +import subprocess + + +def git_suffix(fname): + """ + :returns: `` if Git repository found + """ + try: + gh = subprocess.check_output( + ['git', 'rev-parse', '--short', 'HEAD'], + stderr=open(os.devnull, 'w')).strip() + gh = "-git" + gh.decode() if gh else '' + except Exception: + # trapping everything on purpose; git may not be installed or it + # may not work properly + gh = '' + + return gh + + +__version__ = '0.0.1' +__version__ += git_suffix(__file__) diff --git a/dcc/dcc/urls.py b/dcc/dcc/urls.py index be838b7..278fe87 100644 --- a/dcc/dcc/urls.py +++ b/dcc/dcc/urls.py @@ -27,6 +27,7 @@ admin.site.site_header = "Trains assets manager" urlpatterns = [ path('', GetHome.as_view(), name='index'), + path('page/', GetHome.as_view(), name='index_pagination'), path("ht/", include("health_check.urls")), path("admin/", admin.site.urls), path("api/v1/consist/", include(consist_urls)), diff --git a/dcc/portal/migrations/0003_rename_maps_per_page_siteconfiguration_items_per_page.py b/dcc/portal/migrations/0003_rename_maps_per_page_siteconfiguration_items_per_page.py new file mode 100644 index 0000000..012a56e --- /dev/null +++ b/dcc/portal/migrations/0003_rename_maps_per_page_siteconfiguration_items_per_page.py @@ -0,0 +1,18 @@ +# Generated by Django 4.0.3 on 2022-04-09 20:31 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('portal', '0002_alter_siteconfiguration_site_name'), + ] + + operations = [ + migrations.RenameField( + model_name='siteconfiguration', + old_name='maps_per_page', + new_name='items_per_page', + ), + ] diff --git a/dcc/portal/migrations/0004_rename_footer_short_siteconfiguration_footer_extended_and_more.py b/dcc/portal/migrations/0004_rename_footer_short_siteconfiguration_footer_extended_and_more.py new file mode 100644 index 0000000..0cd1cd7 --- /dev/null +++ b/dcc/portal/migrations/0004_rename_footer_short_siteconfiguration_footer_extended_and_more.py @@ -0,0 +1,22 @@ +# Generated by Django 4.0.3 on 2022-04-09 20:37 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('portal', '0003_rename_maps_per_page_siteconfiguration_items_per_page'), + ] + + operations = [ + migrations.RenameField( + model_name='siteconfiguration', + old_name='footer_short', + new_name='footer_extended', + ), + migrations.RemoveField( + model_name='siteconfiguration', + name='show_copyright', + ), + ] diff --git a/dcc/portal/models.py b/dcc/portal/models.py index dc741c5..cdfd8c3 100644 --- a/dcc/portal/models.py +++ b/dcc/portal/models.py @@ -1,6 +1,7 @@ import django from django.db import models +from dcc import __version__ as app_version from solo.models import SingletonModel @@ -10,7 +11,7 @@ class SiteConfiguration(SingletonModel): default="Trains assets manager") site_author = models.CharField(max_length=256, blank=True) about = models.TextField(blank=True) - maps_per_page = models.CharField( + items_per_page = models.CharField( max_length=2, choices=[ (str(x * 3), str(x * 3)) for x in range(2, 11)], default='6' @@ -18,9 +19,7 @@ class SiteConfiguration(SingletonModel): homepage_content = models.TextField(blank=True) footer = models.TextField(blank=True) - footer_short = models.TextField(blank=True) - show_copyright = models.BooleanField(default=True) - + footer_extended = models.TextField(blank=True) show_version = models.BooleanField(default=True) class Meta: @@ -29,8 +28,8 @@ class SiteConfiguration(SingletonModel): def __str__(self): return "Site Configuration" - # def version(self): - # return app_version + def version(self): + return app_version def django_version(self): return django.get_version() diff --git a/dcc/portal/static/css/fonts.css b/dcc/portal/static/css/fonts.css deleted file mode 100644 index 1117d12..0000000 --- a/dcc/portal/static/css/fonts.css +++ /dev/null @@ -1,29 +0,0 @@ -/* titillium-web-regular - latin */ -@font-face { - font-family: 'Titillium Web'; - font-style: normal; - font-weight: 400; - src: local('Titillium Web Regular'), local('TitilliumWeb-Regular'), - url('../fonts/titillium-web-v6-latin-regular.woff2') format('woff2'), /* Chrome 26+, Opera 23+, Firefox 39+ */ - url('../fonts/titillium-web-v6-latin-regular.woff') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */ -} - -/* titillium-web-italic - latin */ -@font-face { - font-family: 'Titillium Web'; - font-style: italic; - font-weight: 400; - src: local('Titillium Web Italic'), local('TitilliumWeb-Italic'), - url('../fonts/titillium-web-v6-latin-italic.woff2') format('woff2'), /* Chrome 26+, Opera 23+, Firefox 39+ */ - url('../fonts/titillium-web-v6-latin-italic.woff') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */ -} - -/* titillium-web-700 - latin */ -@font-face { - font-family: 'Titillium Web'; - font-style: normal; - font-weight: 700; - src: local('Titillium Web Bold'), local('TitilliumWeb-Bold'), - url('../fonts/titillium-web-v6-latin-700.woff2') format('woff2'), /* Chrome 26+, Opera 23+, Firefox 39+ */ - url('../fonts/titillium-web-v6-latin-700.woff') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */ -} diff --git a/dcc/portal/static/css/main.css b/dcc/portal/static/css/main.css index 7313045..d06f61a 100644 --- a/dcc/portal/static/css/main.css +++ b/dcc/portal/static/css/main.css @@ -1,61 +1,3 @@ -body { - font-family: 'Titillium Web','Segoe UI',Arial,sans-serif; -} -:root { - --jumbotron-padding-y: 3rem; -} -#navbarHeader p { - color: #6c757d; -} -.jumbotron { - padding-top: var(--jumbotron-padding-y); - padding-bottom: var(--jumbotron-padding-y); - margin-bottom: 0; - border-radius: 0; - background-color: #fff; -} -.jumbotron p:last-child { - margin-bottom: 0; -} -.jumbotron-heading { - font-weight: 300; -} -.jumbotron .container { - max-width: 40rem; -} .card > a > img { width: 100%; } -.published-info { - text-align: right; - font-size: .7rem; -} -.navbar img#site-logo { - max-width: 200px; - max-height: 100px; -} -.page-item.active .page-link { - background-color: #343a40; - border-color: #343a40; -} -footer { - padding-top: 3rem; - padding-bottom: 3rem; -} -footer a { - color: #fff; - font-weight: bold; -} -footer a:hover { - color: #fff; -} -footer p { - display: inline; - margin-bottom: .25rem; -} -footer p.float-right > a { - font-weight: normal; -} -.box-shadow { - box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); -} diff --git a/dcc/portal/static/fonts/titillium-web-v6-latin-700.woff b/dcc/portal/static/fonts/titillium-web-v6-latin-700.woff deleted file mode 100644 index bd57a14..0000000 Binary files a/dcc/portal/static/fonts/titillium-web-v6-latin-700.woff and /dev/null differ diff --git a/dcc/portal/static/fonts/titillium-web-v6-latin-700.woff2 b/dcc/portal/static/fonts/titillium-web-v6-latin-700.woff2 deleted file mode 100644 index 5ca391f..0000000 Binary files a/dcc/portal/static/fonts/titillium-web-v6-latin-700.woff2 and /dev/null differ diff --git a/dcc/portal/static/fonts/titillium-web-v6-latin-italic.woff b/dcc/portal/static/fonts/titillium-web-v6-latin-italic.woff deleted file mode 100644 index ca1ed24..0000000 Binary files a/dcc/portal/static/fonts/titillium-web-v6-latin-italic.woff and /dev/null differ diff --git a/dcc/portal/static/fonts/titillium-web-v6-latin-italic.woff2 b/dcc/portal/static/fonts/titillium-web-v6-latin-italic.woff2 deleted file mode 100644 index 76271ba..0000000 Binary files a/dcc/portal/static/fonts/titillium-web-v6-latin-italic.woff2 and /dev/null differ diff --git a/dcc/portal/static/fonts/titillium-web-v6-latin-regular.woff b/dcc/portal/static/fonts/titillium-web-v6-latin-regular.woff deleted file mode 100644 index 2a18ab0..0000000 Binary files a/dcc/portal/static/fonts/titillium-web-v6-latin-regular.woff and /dev/null differ diff --git a/dcc/portal/static/fonts/titillium-web-v6-latin-regular.woff2 b/dcc/portal/static/fonts/titillium-web-v6-latin-regular.woff2 deleted file mode 100644 index 6636691..0000000 Binary files a/dcc/portal/static/fonts/titillium-web-v6-latin-regular.woff2 and /dev/null differ diff --git a/dcc/portal/static/img/empty.svg b/dcc/portal/static/img/empty.svg deleted file mode 100644 index 2629937..0000000 --- a/dcc/portal/static/img/empty.svg +++ /dev/null @@ -1 +0,0 @@ -Missing thumbnail diff --git a/dcc/portal/templates/breadcrumbs.html b/dcc/portal/templates/breadcrumbs.html deleted file mode 100644 index 6cd18da..0000000 --- a/dcc/portal/templates/breadcrumbs.html +++ /dev/null @@ -1,10 +0,0 @@ - diff --git a/dcc/portal/templates/footer.html b/dcc/portal/templates/footer.html index f9c0318..b8a683a 100644 --- a/dcc/portal/templates/footer.html +++ b/dcc/portal/templates/footer.html @@ -1,17 +1,14 @@ -
-
-

- Back to top -

-

{% if site_conf.show_copyright %}© {% now "Y" %} {% endif %}

- {% if rolling_stock and site_conf.footer_short %} - {{ site_conf.footer_short | safe }} - {% else %} - {{ site_conf.footer | safe }} - {% endif %} -
- {% if site_conf.show_version and not map %}
-

Version: {{ site_conf.version }}

-
{% endif %} -
- +
+
+

+ Back to top +

+

© {% now "Y" %} {{ site_conf.footer }}

+

{{ site_conf.footer_extended }}

+
+ {% if site_conf.show_version %} +
+

Version: {{ site_conf.version }}

+
+ {% endif %} +
diff --git a/dcc/portal/templates/home.html b/dcc/portal/templates/home.html index 84ce8c2..77c8dbf 100644 --- a/dcc/portal/templates/home.html +++ b/dcc/portal/templates/home.html @@ -6,142 +6,214 @@ - - - - - - - - - + + + + {{ site_conf.site_name }} + + + + - - + + + + + - - -
-
- {% include 'navbar.html' %} - -
+ + +
+ +
-
-
-
- {{ site_conf.homepage_content | safe }} -
+
+
+
+
+

About

+

{{ site_conf.about | safe }}

+
+
- -
-
-
-
- {% if tags %}

active filter: - {% for t in tags %}{{ t.tag }}{# new line is required #} - {% endfor %}

{% endif %} -
-
-
- {% for r in rolling_stock %} -
-
- - {% for t in r.thumbnail.all %}{% if t.is_thumbnail %}Card image cap - {% else %}{% endif %}{% endfor %} -
-

{{ r }}

{{ r.description|safe|truncatechars_html:256 }} -

- {% for t in r.tags.all %}{{ t.tag }}{# new line is required #} - {% endfor %} -

-
-
- View - {% if request.user.is_staff %}Edit{% endif %} -
- Last update: {{ r.updated_time | date:"M d, Y" }} -
-
+
+
+ +
+ {% for r in rolling_stock %} +
+
+ + {% for t in r.thumbnail.all %}{% if t.is_thumbnail %}Card image cap + {% else %} + PlaceholderMissing thumbnail + {% endif %}{% endfor %} +
+

{{ r }}

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Data
Type{{ r.rolling_class.type }}
Company{{ r.rolling_class.company }}
Class{{ r.rolling_class.identifier }}
Road number{{ r.road_number }}
Era{{ r.era }}
+
+ + {% if r.decoder %} + + {% endif %} + Show all data + {% if request.user.is_staff %}Edit{% endif %}
-
- {% endfor %} - {% if request.user.is_staff and not rolling_stock.has_next %} -
-
-
-
- -
-
+
+ + + + + + + + + + + + + + + + + + + + +
Model data
Manufacturer{{ r.manufacturer }}
Scale{{ r.scale }}
SKU{{ r.sku }}
-
- {% endif %} -
- {% if rolling_stock.has_other_pages %} - - {% endif %} + {% endif %} +

+
+ Updated {{ r.updated_time | date:"M d, Y H:m" }} +
+
+
+ {% endfor %}
-
+
+
+ {% if rolling_stock.has_other_pages %} + + {% endif %} +
+
+ + + +{% include 'footer.html' %} - {% include 'footer.html' %} - - - - - + diff --git a/dcc/portal/templates/login.html b/dcc/portal/templates/login.html index a7291f6..6ecd6f4 100644 --- a/dcc/portal/templates/login.html +++ b/dcc/portal/templates/login.html @@ -1,18 +1,20 @@ - {% if request.user.is_staff %} -
- - -
- {% else %} - Log in - {% endif %} - + {% if request.user.is_staff %} + + {% else %} + Log in + {% endif %} diff --git a/dcc/portal/templates/navbar.html b/dcc/portal/templates/navbar.html deleted file mode 100644 index 268aee6..0000000 --- a/dcc/portal/templates/navbar.html +++ /dev/null @@ -1,10 +0,0 @@ - - diff --git a/dcc/portal/utils.py b/dcc/portal/utils.py new file mode 100644 index 0000000..b14b91b --- /dev/null +++ b/dcc/portal/utils.py @@ -0,0 +1,6 @@ +from django.apps import apps + + +def get_site_conf(): + SiteConfiguration = apps.get_model('portal', 'SiteConfiguration') + return SiteConfiguration.get_solo() diff --git a/dcc/portal/views.py b/dcc/portal/views.py index a33c2fc..e63f588 100644 --- a/dcc/portal/views.py +++ b/dcc/portal/views.py @@ -2,14 +2,16 @@ from django.views import View 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 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, 6) + paginator = Paginator(rolling_stock, site_conf.items_per_page) try: rolling_stock = paginator.page(page)