You can now print Items, w/o explicitly defining Labels

update
radex 2020-05-20 23:23:23 +02:00 zatwierdzone przez Piotr Dobrowolski
rodzic 2e0c031fab
commit 5160052dfd
3 zmienionych plików z 26 dodań i 16 usunięć

Wyświetl plik

@ -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()

Wyświetl plik

@ -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',)

Wyświetl plik

@ -18,21 +18,16 @@
<div class="col-md-4">
<iframe name="printframe" style="display: none"></iframe>
{% for label in labels %}
<div class="label-item">
<form action="/api/1/labels/{{ label.id }}/print/?quantity=2" method="POST" target="printframe" onsubmit="return confirm('Want to print 2 labels?')" style="display:inline-block">
{% csrf_token %}
<button class="btn btn-default btn-lg btn-primary"><i class="glyphicon glyphicon-print"></i>&nbsp;&nbsp;PRINT&nbsp;x&nbsp;2</button>
</form>
<form action="/api/1/labels/{{ label.id }}/print/" method="POST" target="printframe" onsubmit="return confirm('Want to print this labels?')" style="display:inline-block">
{% csrf_token %}
<button class="btn btn-default btn-lg"><i class="glyphicon glyphicon-print"></i></button>
{% if not has_one_label %}
<code>{{ label.id }}</code>
{% endif %}
</form>
</div>
{% endfor %}
<div class="label-item">
<form action="/api/1/items/{{ item.short_id }}/print/?quantity=2" method="POST" target="printframe" onsubmit="return confirm('Want to print 2 labels?')" style="display:inline-block">
{% csrf_token %}
<button class="btn btn-default btn-lg btn-primary"><i class="glyphicon glyphicon-print"></i>&nbsp;&nbsp;PRINT&nbsp;x&nbsp;2</button>
</form>
<form action="/api/1/items/{{ item.short_id }}/print/" method="POST" target="printframe" onsubmit="return confirm('Want to print this labels?')" style="display:inline-block">
{% csrf_token %}
<button class="btn btn-default btn-lg"><i class="glyphicon glyphicon-print"></i></button>
</form>
</div>
<table class="table table-hover table-striped">
{% if item.owner %}
@ -75,7 +70,7 @@
{% endfor %}
{% if labels %}
<tr><td>a.k.a.</td><td>
<tr><td>legacy labels</td><td>
{% for label in labels %}
<code>{{ label.id }}</code>,
{% endfor %}