From 5160052dfddb21c70ab0404e49927df4481492e5 Mon Sep 17 00:00:00 2001 From: radex Date: Wed, 20 May 2020 23:23:23 +0200 Subject: [PATCH] You can now print Items, w/o explicitly defining Labels --- storage/apiviews.py | 9 +++++++++ storage/models.py | 6 ++++++ storage/templates/item.html | 27 +++++++++++---------------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/storage/apiviews.py b/storage/apiviews.py index 6de797c..771d5ee 100644 --- a/storage/apiviews.py +++ b/storage/apiviews.py @@ -72,6 +72,15 @@ class ItemViewSet(viewsets.ModelViewSet): except Label.DoesNotExist: raise Http404() + @detail_route(methods=['post'], permission_classes=[AllowAny]) + def print(self, request, pk): + # todo: deduplicate + quantity = min(int(request.query_params.get('quantity', 1)), 5) + obj = self.get_object() + for _ in range(quantity): + obj.print() + return obj + @detail_route() def children(self, request, pk): item = self.get_object() diff --git a/storage/models.py b/storage/models.py index 9d8134a..8e6fe2b 100644 --- a/storage/models.py +++ b/storage/models.py @@ -89,6 +89,12 @@ class Item(models.Model, TreeModelMixin): def primary_category(self): return next((c for c in self.categories.all() if c.icon_id), None) + def print(self): + # todo: deduplicate + resp = requests.post( + '{}/api/1/print/{}'.format(settings.LABEL_API, self.short_id())) + resp.raise_for_status() + class Meta: ordering = ('path',) diff --git a/storage/templates/item.html b/storage/templates/item.html index 041a721..149e220 100644 --- a/storage/templates/item.html +++ b/storage/templates/item.html @@ -18,21 +18,16 @@
- {% for label in labels %} -
-
- {% csrf_token %} - -
-
- {% csrf_token %} - - {% if not has_one_label %} - {{ label.id }} - {% endif %} -
-
- {% endfor %} +
+
+ {% csrf_token %} + +
+
+ {% csrf_token %} + +
+
{% if item.owner %} @@ -75,7 +70,7 @@ {% endfor %} {% if labels %} -
a.k.a. +
legacy labels {% for label in labels %} {{ label.id }}, {% endfor %}