From 45268cd6993bb1260d371009a79a402dce2b660a Mon Sep 17 00:00:00 2001 From: bkfox Date: Fri, 28 Oct 2016 12:18:12 +0200 Subject: [PATCH] work on admin interface, fix bugs --- aircox/models.py | 4 +- aircox/static/aircox/css/layout.css | 58 +++++++++++++++++ .../aircox/controllers/base_site.html | 27 ++++++++ .../templates/aircox/controllers/stats.html | 64 +++++++++++++------ aircox/urls.py | 1 - aircox/views.py | 5 +- instance/base_settings.py | 2 +- instance/urls.py | 1 + 8 files changed, 138 insertions(+), 24 deletions(-) create mode 100644 aircox/static/aircox/css/layout.css create mode 100644 aircox/templates/aircox/controllers/base_site.html diff --git a/aircox/models.py b/aircox/models.py index b9497a6..8f3ff16 100755 --- a/aircox/models.py +++ b/aircox/models.py @@ -208,6 +208,8 @@ class Station(Nameable): logs.filter(date__gt = diff.end, date__lt = diff_.start) \ if diff_ else \ logs.filter(date__gt = diff.end) + print(diff.end, *[str(log.date > diff.end) + " " + str(log.date) for log in logs]) + diff_ = diff items.extend(logs_) items.append(diff) @@ -217,7 +219,7 @@ class Station(Nameable): if diff_: if count and len(items) >= count: return items[:count] - logs_ = logs.filter(date__lt = diff_.end) + logs_ = logs.filter(date__lt = diff_.start) else: logs_ = logs.all() diff --git a/aircox/static/aircox/css/layout.css b/aircox/static/aircox/css/layout.css new file mode 100644 index 0000000..6f0d0bb --- /dev/null +++ b/aircox/static/aircox/css/layout.css @@ -0,0 +1,58 @@ + +body { + background-color: #373737; + background-color: #F2F2F2; + font-family: 'Myriad Pro', Calibri, Helvetica, Arial, sans-serif; + font-size: 18px; + line-height: 1.5; +} + +main { + padding: 1em; +} + + +input { + padding: 0.4em; +} + + +table { + background-color: #f2f2f2; + border: 1px black solid; + width: 80%; + margin: auto; +} + +td { + margin: 0; + padding: 0 0.4em; +} + +th { + text-align: left; + font-weight: normal; + margin: 0; + padding: 0.4em; +} + +tr:not(.header):hover { + background-color: rgba(0, 0, 0, 0.1); +} + +tr.header { + background-color: #212121; + color: #eee; +} + +tr.bottom > td { + vertical-align: top; + padding: 0.4em; +} + +tr.subdata { + font-style: italic; + font-size: 0.9em; +} + + diff --git a/aircox/templates/aircox/controllers/base_site.html b/aircox/templates/aircox/controllers/base_site.html new file mode 100644 index 0000000..e844cde --- /dev/null +++ b/aircox/templates/aircox/controllers/base_site.html @@ -0,0 +1,27 @@ +{% load static %} + + + + Aircox + + + + + + +
+ {% block title %} +

{{ title|default:"Aircox" }}

+ {% endblock %} + +
+ {% block content %} + + {% endblock %} +
+
+ + + + + diff --git a/aircox/templates/aircox/controllers/stats.html b/aircox/templates/aircox/controllers/stats.html index 931d673..0b45b46 100644 --- a/aircox/templates/aircox/controllers/stats.html +++ b/aircox/templates/aircox/controllers/stats.html @@ -1,46 +1,77 @@ +{% extends "aircox/controllers/base_site.html" %} {% load i18n %} +{% block title %} +

Statistics of the stations

+{% endblock %} + +{% block content %}
+ + {# TODO here #} +
+ Go to this date: + + + + +
+ + {% for stats in statistics %}
-

{{ stats.station.name }}

-

- {{ stats.date|date:'l d F Y' }}

+

{{ stats.station.name }}, + {{ stats.date|date:'l d F Y' }}

- - +
+ + + {% for item in stats.items %} - - + + + - {% for track in item.tracks %} - - + + + {% endfor %} {% endfor %} - + + {# TODO: translation block #} - + @@ -48,9 +79,6 @@ {% endfor %} - - - - +{% endblock %} diff --git a/aircox/urls.py b/aircox/urls.py index 437bbf9..dad9b18 100644 --- a/aircox/urls.py +++ b/aircox/urls.py @@ -1,4 +1,3 @@ - from django.conf.urls import include, url import aircox.views as views diff --git a/aircox/views.py b/aircox/views.py index 69e829c..9cd2616 100755 --- a/aircox/views.py +++ b/aircox/views.py @@ -181,7 +181,7 @@ class StatisticsView(View,TemplateResponseMixin,LoginRequiredMixin): items = [], tags = {}) last_item = None - for elm in station.on_air(date): + for elm in reversed(station.on_air(date)): qs = None item = None if type(elm) == models.Diffusion: @@ -215,7 +215,7 @@ class StatisticsView(View,TemplateResponseMixin,LoginRequiredMixin): stats.items.append(item) elm.related.date = elm.date - item.tracks.insert(0, elm.related) + item.tracks.append(elm.related) item.date = min(elm.date, item.date) item.add_tags(qs) stats.count += 1 @@ -223,7 +223,6 @@ class StatisticsView(View,TemplateResponseMixin,LoginRequiredMixin): last_item = item stats.add_tags(qs) - print(stats.tags) stats.tags = [ (name, count, count / stats.count * 100) for name, count in stats.tags.items() diff --git a/instance/base_settings.py b/instance/base_settings.py index 8b2f60d..0983590 100644 --- a/instance/base_settings.py +++ b/instance/base_settings.py @@ -17,7 +17,7 @@ USE_L10N = True USE_TZ = True LANGUAGE_CODE = os.environ.get('LANG') or 'en_US' -TIME_ZONE = os.environ.get('TZ') or 'Europe/Brussels' +TIME_ZONE = 'UTC' # os.environ.get('TZ') or 'Europe/Brussels' try: import locale diff --git a/instance/urls.py b/instance/urls.py index ef3532b..2d3cfee 100644 --- a/instance/urls.py +++ b/instance/urls.py @@ -45,3 +45,4 @@ if settings.DEBUG: ) urlpatterns.append(url(r'', include(wagtail_urls))) +
{% trans "Date" %}{% trans "Type" %} {# Translators "Header for statistics view" #} - {% trans "Diffusion or sound played" %} - {% trans "Diffusion or sound played" %} + {% trans "Tags" %}
{{ item.date|date:"H:i" }}
{{ item.date|time:"H:i" }}{{ item.type }} {{ item.name }} {% for tag,count in item.tags.items %} {{ tag }}: {{ count }}; {% endfor %}{{ item.type }}
{{ track.date|date:"H:i" }}
{{ track.date|time:"H:i" }}{% trans "Track" %} {{ track.artist }} -- {{ track.title }} {{ track.version }} {{ track.tags.all|join:', ' }}
{{ stats.date|date:'d/m/Y' }}{% trans "Total" %}{% trans "Total and average" %} ({{ stats.count }} tracks) + {% with stats.items|length as items_count %} + {% with stats.count as tracks_count %} + {% blocktrans %} + {{ items_count }} items, with a total of {{ tracks_count }} tracks + {% endblocktrans %} + {% endwith %} + {% endwith %} + {% for tag, count, average in stats.tags %} - {{ tag }}: {{ count }} / {{ average|floatformat }}%; + {{ tag }}: {{ average|floatformat }}% ({{ count }})
{% endfor %}