From 644765ec5f707c6489c1aeb8999fc10e078d3d04 Mon Sep 17 00:00:00 2001 From: Piotr Dobrowolski Date: Tue, 24 Oct 2017 20:59:08 +0200 Subject: [PATCH] Implement container icons, extract item generic list widget --- static/css/custom.css | 11 ++++ static/icons/pappis.svg | 61 +++++++++++++++++++++ static/icons/samla.svg | 47 ++++++++++++++++ storage/migrations/0006_category_icon_id.py | 20 +++++++ storage/models.py | 6 ++ storage/templates/item.html | 30 ++++++---- storage/templates/results.html | 13 +---- storage/views.py | 3 +- templates/widgets/categoryicon.html | 3 + templates/widgets/itemlist.html | 32 +++++++++++ 10 files changed, 202 insertions(+), 24 deletions(-) create mode 100644 static/icons/pappis.svg create mode 100644 static/icons/samla.svg create mode 100644 storage/migrations/0006_category_icon_id.py create mode 100644 templates/widgets/categoryicon.html create mode 100644 templates/widgets/itemlist.html diff --git a/static/css/custom.css b/static/css/custom.css index 00c5657..7b23a1a 100644 --- a/static/css/custom.css +++ b/static/css/custom.css @@ -9,3 +9,14 @@ color: inherit; font-weight: bold; } + +.containericon { + white-space: nowrap; + display: inline-block; + vertical-align: middle; +} + +.containericon span { + padding-left: 0.5rem; + font-weight: bold; +} diff --git a/static/icons/pappis.svg b/static/icons/pappis.svg new file mode 100644 index 0000000..b314a3d --- /dev/null +++ b/static/icons/pappis.svg @@ -0,0 +1,61 @@ + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + diff --git a/static/icons/samla.svg b/static/icons/samla.svg new file mode 100644 index 0000000..a645f4a --- /dev/null +++ b/static/icons/samla.svg @@ -0,0 +1,47 @@ + + + + + + + image/svg+xml + + + + + + + + + + + + + diff --git a/storage/migrations/0006_category_icon_id.py b/storage/migrations/0006_category_icon_id.py new file mode 100644 index 0000000..89898d0 --- /dev/null +++ b/storage/migrations/0006_category_icon_id.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.1 on 2017-10-24 17:48 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('storage', '0005'), + ] + + operations = [ + migrations.AddField( + model_name='category', + name='icon_id', + field=models.CharField(blank=True, max_length=64, null=True), + ), + ] diff --git a/storage/models.py b/storage/models.py index a198a28..edd40dc 100644 --- a/storage/models.py +++ b/storage/models.py @@ -24,6 +24,8 @@ STATES = ( class Category(models.Model): name = models.CharField(max_length=127) + icon_id = models.CharField(max_length=64, null=True, blank=True) + def __str__(self): return self.name @@ -74,6 +76,10 @@ class Item(models.Model, TreeModelMixin): return obj + @property + def primary_category(self): + return next((c for c in self.categories.all() if c.icon_id), None) + class Meta: ordering = ('path',) diff --git a/storage/templates/item.html b/storage/templates/item.html index 3da0747..f105b6a 100644 --- a/storage/templates/item.html +++ b/storage/templates/item.html @@ -10,6 +10,8 @@

+ + {% include "widgets/categoryicon.html" with category=item.primary_category %} {{ item.name }} {{ item.pk }}

@@ -49,6 +51,22 @@ {% endfor %} + {% if categories %} +

Categories

+ + {% for category in categories %} + + + + + {% endfor %} +
+ {% include "widgets/categoryicon.html" with category=category %} + + {{ category.name }} +
+ {% endif %} + {% if images %}

Photos

@@ -80,17 +98,7 @@ {% endif %}

Children

- - {% for child in children|dictsort:"name" %} - - {% endfor %} - -
{{ child.name }}
- - - Add child - -
+ {% include "widgets/itemlist.html" with list=children|dictsort:"name" item=item %}
{% endblock %} diff --git a/storage/templates/results.html b/storage/templates/results.html index 4d61920..ce5f7f4 100644 --- a/storage/templates/results.html +++ b/storage/templates/results.html @@ -1,16 +1,5 @@ {% extends "base.html" %} {% block content %} - - {% for item in results %} - - - - {% endfor %} -
- {% for parent in item.get_ancestors %} - {{ parent.name }} » - {% endfor %} - {{ item.name }} -
+ {% include "widgets/itemlist.html" with list=results show_paths=True show_placeholder=True %} {% endblock %} diff --git a/storage/views.py b/storage/views.py index 4d6088e..c66ed13 100644 --- a/storage/views.py +++ b/storage/views.py @@ -62,10 +62,11 @@ def item_display(request, pk): return render(request, 'item.html', { 'item': item, + 'categories': item.categories.all(), 'images': item.images.all(), 'labels': item.labels.all(), 'ancestors': item.get_ancestors(), - 'children': item.get_children(), + 'children': item.get_children().prefetch_related('categories'), }) def label_lookup(request, pk): diff --git a/templates/widgets/categoryicon.html b/templates/widgets/categoryicon.html new file mode 100644 index 0000000..e3b6b20 --- /dev/null +++ b/templates/widgets/categoryicon.html @@ -0,0 +1,3 @@ +{% if category and category.icon_id %} +
+{% endif %} diff --git a/templates/widgets/itemlist.html b/templates/widgets/itemlist.html new file mode 100644 index 0000000..f58ecbf --- /dev/null +++ b/templates/widgets/itemlist.html @@ -0,0 +1,32 @@ + + {% for item in list %} + + + + + {% empty %} + {% if show_placeholder %} + + + + {% endif %} + {% endfor %} + + {% if item %} + + {% endif %} +
+ {% include "widgets/categoryicon.html" with category=item.primary_category %} + + {% if show_paths %} + {% for parent in item.get_ancestors %} + {{ parent.name }} » + {% endfor %} + {% endif %} + {{ item.name }} +
Nothing found
+ + + Add child + +