forked from wiktor/spejstore-new
You can now print Items, w/o explicitly defining Labels
This commit is contained in:
parent
2e0c031fab
commit
5160052dfd
|
@ -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()
|
||||
|
|
|
@ -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',)
|
||||
|
||||
|
|
|
@ -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">
|
||||
<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> PRINT x 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">
|
||||
<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>
|
||||
{% if not has_one_label %}
|
||||
<code>{{ label.id }}</code>
|
||||
{% endif %}
|
||||
</form>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
<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 %}
|
||||
|
|
Loading…
Reference in New Issue