item: Fix label printing

d42/ebin
informatic 2017-12-13 21:21:13 +01:00
parent 0fa55f7bd1
commit c1cada3de7
4 changed files with 24 additions and 3 deletions

View File

@ -189,4 +189,4 @@ REST_FRAMEWORK = {
]
}
LABEL_API = 'http://label.waw.hackerspace.pl:5678'
LABEL_API = 'http://label.waw.hackerspace.pl:4567'

View File

@ -20,3 +20,13 @@
padding-left: 0.5rem;
font-weight: bold;
}
.label-item {
background: #f5f5f5;
border-radius: 3px;
display: inline-block;
}
.label-item code {
margin: 0em 1em;
}

View File

@ -1,6 +1,7 @@
from rest_framework import viewsets, generics, filters
from rest_framework.response import Response
from rest_framework.decorators import detail_route
from rest_framework.permissions import AllowAny
from storage.models import Item, Label
from storage.serializers import ItemSerializer, LabelSerializer
@ -29,6 +30,12 @@ class LabelViewSet(viewsets.ModelViewSet):
queryset = Label.objects
serializer_class = LabelSerializer
@detail_route(methods=['post'], permission_classes=[AllowAny])
def print(self, request, pk):
obj = self.get_object()
obj.print()
return obj
class ItemViewSet(viewsets.ModelViewSet):
"""

View File

@ -84,8 +84,12 @@
<h3>Labels</h3>
<iframe name="printframe" style="display: none"></iframe>
{% for label in labels %}
<form action="http://label.waw.hackerspace.pl:4567/api/1/print/{{ label.id }}" method="POST" target="printframe" onsubmit="return confirm('Want to print this label?')">
<button class="btn btn-xs btn-default" title="Print">{{label.id}}</button>
<form action="/api/1/labels/{{ label.id }}/print/" method="POST" target="printframe" onsubmit="return confirm('Want to print this label?')">
{% csrf_token %}
<div class="label-item">
<button class="btn btn-default btn-sm"><i class="glyphicon glyphicon-print"></i></button>
<code>{{ label.id }}</code>
</div>
</form>
{% endfor %}
{% endif %}