From f91d94685d4374e3d326cd26db60f51606bb3c70 Mon Sep 17 00:00:00 2001 From: artus40 Date: Thu, 31 Aug 2017 19:57:55 +0200 Subject: [PATCH] customized admin styling, added get_absolute_url for Note model, added inline in Sujet admin to show FicheStatistique --- notes/admin.py | 13 +- notes/models.py | 5 +- statistiques/admin.py | 1 + statistiques/models.py | 6 + templates/admin/base.html | 2 +- templates/admin/change_list.html | 2 +- templates/admin/submit_line.html | 6 +- .../css/{base-admin.css => admin/base.css} | 26 +- website/static/css/admin/changelists.css | 344 ++++++++++++++++++ 9 files changed, 384 insertions(+), 21 deletions(-) rename website/static/css/{base-admin.css => admin/base.css} (95%) create mode 100644 website/static/css/admin/changelists.css diff --git a/notes/admin.py b/notes/admin.py index e0d3755..597e11c 100644 --- a/notes/admin.py +++ b/notes/admin.py @@ -1,17 +1,26 @@ from django.contrib import admin from .models import * +from statistiques.models import FicheStatistique # Register your models here. +class FicheStatistiqueInline(admin.StackedInline): + model = FicheStatistique + can_delete = False + + @admin.register(Sujet) class SujetAdmin(admin.ModelAdmin): fieldsets = [ - ('Identité', {'fields': [('nom', 'prenom'), 'genre']}), - ('Informations', {'fields': ['age', ]}), + ('Identité', {'fields': [('nom', 'surnom', 'prenom', ), ('genre', 'age')]}), ] + inlines = [ + FicheStatistiqueInline, + ] + @admin.register(Note) class NoteAdmin(admin.ModelAdmin): diff --git a/notes/models.py b/notes/models.py index b68d63e..857345a 100644 --- a/notes/models.py +++ b/notes/models.py @@ -2,7 +2,7 @@ import logging from django.utils import timezone from django.core.exceptions import ValidationError -from django.urls import reverse +from django.shortcuts import reverse from django.db import models from . import managers @@ -176,3 +176,6 @@ class Note(models.Model): return getter bg_colors = property(cached_attr('bg_colors'), doc="background color of header") labels = property(cached_attr('labels'), doc="list of string to display as labels") + + def get_absolute_url(self): + return reverse("notes:details-sujet", kwargs={"pk": self.sujet.pk}) \ No newline at end of file diff --git a/statistiques/admin.py b/statistiques/admin.py index 8c38f3f..ec50db8 100644 --- a/statistiques/admin.py +++ b/statistiques/admin.py @@ -1,3 +1,4 @@ from django.contrib import admin # Register your models here. + diff --git a/statistiques/models.py b/statistiques/models.py index 2729766..022a1f0 100644 --- a/statistiques/models.py +++ b/statistiques/models.py @@ -84,3 +84,9 @@ class FicheStatistique(models.Model): completed += 1 percentage = int(completed / len(observed) * 100) return percentage + + def __str__(self): + return "" % self.sujet + + class Meta: + verbose_name = "Fiche statistique" diff --git a/templates/admin/base.html b/templates/admin/base.html index 96ba7c8..5f65c63 100644 --- a/templates/admin/base.html +++ b/templates/admin/base.html @@ -3,7 +3,7 @@ {% get_current_language as LANGUAGE_CODE %}{% get_current_language_bidi as LANGUAGE_BIDI %} {% block extrastyle %} - + {% if LANGUAGE_BIDI %}{% endif %} {% endblock %} diff --git a/templates/admin/change_list.html b/templates/admin/change_list.html index 4d199ff..a58dfbb 100644 --- a/templates/admin/change_list.html +++ b/templates/admin/change_list.html @@ -3,7 +3,7 @@ {% block extrastyle %} {{ block.super }} - + {% if cl.formset %} {% endif %} diff --git a/templates/admin/submit_line.html b/templates/admin/submit_line.html index 4e0dcf0..d5ac1cb 100644 --- a/templates/admin/submit_line.html +++ b/templates/admin/submit_line.html @@ -3,9 +3,9 @@ {% if show_save %}{% endif %} {% if show_delete_link %} {% url opts|admin_urlname:'delete' original.pk|admin_urlquote as delete_url %} - + {% endif %} -{% if show_save_as_new %}{% endif %} + {% if show_save_as_new %}{% endif %} + {% if show_save_and_add_another %}{% endif %} {% if show_save_and_continue %}{% endif %} diff --git a/website/static/css/base-admin.css b/website/static/css/admin/base.css similarity index 95% rename from website/static/css/base-admin.css rename to website/static/css/admin/base.css index f3c591e..602de92 100644 --- a/website/static/css/base-admin.css +++ b/website/static/css/admin/base.css @@ -17,7 +17,7 @@ body { /* LINKS */ -a:link, a:visited { +/*a:link, a:visited { color: #447e9b; text-decoration: none; } @@ -32,7 +32,7 @@ a:focus { a img { border: none; -} +}*/ a.section:link, a.section:visited { color: #fff; @@ -361,7 +361,7 @@ table thead th.sorted .sortoptions a { width: 14px; height: 14px; display: inline-block; - background: url(../admin/img/sorting-icons.svg) 0 0 no-repeat; + background: url(../../admin/img/sorting-icons.svg) 0 0 no-repeat; background-size: 14px auto; } @@ -521,7 +521,7 @@ input[type=button][disabled].default { font-weight: 400; font-size: 13px; text-align: left; - background: #79aec8; + background: #2f2f2f; color: #fff; } @@ -549,18 +549,18 @@ ul.messagelist li { font-size: 13px; padding: 10px 10px 10px 65px; margin: 0 0 10px 0; - background: #dfd url(../admin/img/icon-yes.svg) 40px 12px no-repeat; + background: #dfd url(../../admin/img/icon-yes.svg) 40px 12px no-repeat; background-size: 16px auto; color: #333; } ul.messagelist li.warning { - background: #ffc url(../admin/img/icon-alert.svg) 40px 14px no-repeat; + background: #ffc url(../../admin/img/icon-alert.svg) 40px 14px no-repeat; background-size: 14px auto; } ul.messagelist li.error { - background: #ffefef url(../admin/img/icon-no.svg) 40px 12px no-repeat; + background: #ffefef url(../../admin/img/icon-no.svg) 40px 12px no-repeat; background-size: 16px auto; } @@ -634,7 +634,7 @@ div.system-message p.system-message-title { padding: 4px 5px 4px 25px; margin: 0; color: #c11; - background: #ffefef url(../admin/img/icon-no.svg) 5px 5px no-repeat; + background: #ffefef url(../../admin/img/icon-no.svg) 5px 5px no-repeat; } .description { @@ -665,17 +665,17 @@ div.breadcrumbs a:focus, div.breadcrumbs a:hover { .addlink { padding-left: 16px; - background: url(../admin/img/icon-addlink.svg) 0 1px no-repeat; + background: url(../../admin/img/icon-addlink.svg) 0 1px no-repeat; } .changelink, .inlinechangelink { padding-left: 16px; - background: url(../admin/img/icon-changelink.svg) 0 1px no-repeat; + background: url(../../admin/img/icon-changelink.svg) 0 1px no-repeat; } .deletelink { padding-left: 16px; - background: url(../admin/img/icon-deletelink.svg) 0 1px no-repeat; + background: url(../../admin/img/icon-deletelink.svg) 0 1px no-repeat; } a.deletelink:link, a.deletelink:visited { @@ -744,11 +744,11 @@ a.deletelink:focus, a.deletelink:hover { } .object-tools a.viewsitelink, .object-tools a.golink { - background-image: url(../admin/img/tooltag-arrowright.svg); + background-image: url(../../admin/img/tooltag-arrowright.svg); } .object-tools a.addlink { - background-image: url(../admin/img/tooltag-add.svg); + background-image: url(../../admin/img/tooltag-add.svg); } /* OBJECT HISTORY */ diff --git a/website/static/css/admin/changelists.css b/website/static/css/admin/changelists.css new file mode 100644 index 0000000..570532f --- /dev/null +++ b/website/static/css/admin/changelists.css @@ -0,0 +1,344 @@ +/* CHANGELISTS */ + +#changelist { + position: relative; + width: 100%; +} + +#changelist table { + width: 100%; +} + +.change-list .hiddenfields { display:none; } + +.change-list .filtered table { + border-right: none; +} + +.change-list .filtered { + min-height: 400px; +} + +.change-list .filtered .results, .change-list .filtered .paginator, +.filtered #toolbar, .filtered div.xfull { + margin-right: 280px; + width: auto; +} + +.change-list .filtered table tbody th { + padding-right: 1em; +} + +#changelist-form .results { + overflow-x: auto; +} + +#changelist .toplinks { + border-bottom: 1px solid #ddd; +} + +#changelist .paginator { + color: #666; + border-bottom: 1px solid #eee; + background: #fff; + overflow: hidden; +} + +/* CHANGELIST TABLES */ + +#changelist table thead th { + padding: 0; + white-space: nowrap; + vertical-align: middle; +} + +#changelist table thead th.action-checkbox-column { + width: 1.5em; + text-align: center; +} + +#changelist table tbody td.action-checkbox { + text-align: center; +} + +#changelist table tfoot { + color: #666; +} + +/* TOOLBAR */ + +#changelist #toolbar { + padding: 8px 10px; + margin-bottom: 15px; + border-top: 1px solid #eee; + border-bottom: 1px solid #eee; + background: #f8f8f8; + color: #666; +} + +#changelist #toolbar form input { + border-radius: 4px; + font-size: 14px; + padding: 5px; + color: #333; +} + +#changelist #toolbar form #searchbar { + height: 19px; + border: 1px solid #ccc; + padding: 2px 5px; + margin: 0; + vertical-align: top; + font-size: 13px; +} + +#changelist #toolbar form #searchbar:focus { + border-color: #999; +} + +#changelist #toolbar form input[type="submit"] { + border: 1px solid #ccc; + padding: 2px 10px; + margin: 0; + vertical-align: middle; + background: #fff; + box-shadow: 0 -15px 20px -10px rgba(0, 0, 0, 0.15) inset; + cursor: pointer; + color: #333; +} + +#changelist #toolbar form input[type="submit"]:focus, +#changelist #toolbar form input[type="submit"]:hover { + border-color: #999; +} + +#changelist #changelist-search img { + vertical-align: middle; + margin-right: 4px; +} + +/* FILTER COLUMN */ + +#changelist-filter { + position: absolute; + width: 240px; + background: #f8f8f8; + /*top: 0; + right: 0; + z-index: 1000; + border-left: none; + margin: 0;*/ +} + +#changelist-filter h2 { + font-size: 14px; + text-transform: uppercase; + letter-spacing: 0.5px; + padding: 5px 15px; + margin-bottom: 12px; + border-bottom: none; +} + +#changelist-filter h3 { + font-weight: 400; + font-size: 14px; + padding: 0 15px; + margin-bottom: 10px; +} + +#changelist-filter ul { + margin: 5px 0; + padding: 0 15px 15px; + border-bottom: 1px solid #eaeaea; +} + +#changelist-filter ul:last-child { + border-bottom: none; + padding-bottom: none; +} + +#changelist-filter li { + list-style-type: none; + margin-left: 0; + padding-left: 0; +} + +#changelist-filter a { + display: block; + color: #999; + text-overflow: ellipsis; + overflow-x: hidden; +} + +#changelist-filter li.selected { + border-left: 5px solid #eaeaea; + padding-left: 10px; + margin-left: -15px; +} + +#changelist-filter li.selected a { + color: #5b80b2; +} + +#changelist-filter a:focus, #changelist-filter a:hover, +#changelist-filter li.selected a:focus, +#changelist-filter li.selected a:hover { + color: #036; +} + +/* DATE DRILLDOWN */ + +.change-list ul.toplinks { + display: block; + float: left; + padding: 0; + margin: 0; + width: 100%; +} + +.change-list ul.toplinks li { + padding: 3px 6px; + font-weight: bold; + list-style-type: none; + display: inline-block; +} + +.change-list ul.toplinks .date-back a { + color: #999; +} + +.change-list ul.toplinks .date-back a:focus, +.change-list ul.toplinks .date-back a:hover { + color: #036; +} + +/* PAGINATOR */ + +.paginator { + font-size: 13px; + padding-top: 10px; + padding-bottom: 10px; + line-height: 22px; + margin: 0; + border-top: 1px solid #ddd; +} + +.paginator a:link, .paginator a:visited { + padding: 2px 6px; + background: #79aec8; + text-decoration: none; + color: #fff; +} + +.paginator a.showall { + padding: 0; + border: none; + background: none; + color: #5b80b2; +} + +.paginator a.showall:focus, .paginator a.showall:hover { + background: none; + color: #036; +} + +.paginator .end { + margin-right: 6px; +} + +.paginator .this-page { + padding: 2px 6px; + font-weight: bold; + font-size: 13px; + vertical-align: top; +} + +.paginator a:focus, .paginator a:hover { + color: white; + background: #036; +} + +/* ACTIONS */ + +.filtered .actions { + margin-right: 280px; + border-right: none; +} + +#changelist table input { + margin: 0; + vertical-align: baseline; +} + +#changelist table tbody tr.selected { + background-color: #FFFFCC; +} + +#changelist .actions { + padding: 10px; + background: #fff; + border-top: none; + border-bottom: none; + line-height: 24px; + color: #999; +} + +#changelist .actions.selected { + background: #fffccf; + border-top: 1px solid #fffee8; + border-bottom: 1px solid #edecd6; +} + +#changelist .actions span.all, +#changelist .actions span.action-counter, +#changelist .actions span.clear, +#changelist .actions span.question { + font-size: 13px; + margin: 0 0.5em; + display: none; +} + +#changelist .actions:last-child { + border-bottom: none; +} + +#changelist .actions select { + vertical-align: top; + height: 24px; + background: none; + color: #000; + border: 1px solid #ccc; + border-radius: 4px; + font-size: 14px; + padding: 0 0 0 4px; + margin: 0; + margin-left: 10px; +} + +#changelist .actions select:focus { + border-color: #999; +} + +#changelist .actions label { + display: inline-block; + vertical-align: middle; + font-size: 13px; +} + +#changelist .actions .button { + font-size: 13px; + border: 1px solid #ccc; + border-radius: 4px; + background: #fff; + box-shadow: 0 -15px 20px -10px rgba(0, 0, 0, 0.15) inset; + cursor: pointer; + height: 24px; + line-height: 1; + padding: 4px 8px; + margin: 0; + color: #333; +} + +#changelist .actions .button:focus, #changelist .actions .button:hover { + border-color: #999; +}