Initial label printing integration

d42/ebin
informatic 2017-05-28 22:00:54 +02:00
parent 3fe571c32b
commit c4c21e0ec1
5 changed files with 67 additions and 5 deletions

View File

@ -1,3 +1,5 @@
certifi==2017.4.17
chardet==3.0.3
Django==1.10.1
git+https://github.com/djangonauts/django-hstore@61427e474cb2f4be8fdfce225d78a5330bc77eb0#egg=django-hstore
git+https://github.com/informatic/django-tree@993cec827ed989d3c162698a739da95b9227604b#egg=django-tree
@ -9,3 +11,5 @@ Pillow==3.3.1
psycopg2==2.6.2
djangorestframework-hstore==1.3
pyldap==2.4.28
requests==2.16.5
urllib3==1.21.1

View File

@ -182,3 +182,5 @@ REST_FRAMEWORK = {
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
]
}
LABEL_API = 'http://label.waw.hackerspace.pl:5678'

View File

@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.1 on 2017-05-28 19:45
from __future__ import unicode_literals
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('storage', '0003_auto_20170424_2002'),
]
operations = [
migrations.RemoveField(
model_name='label',
name='revision',
),
migrations.AddField(
model_name='label',
name='created',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
migrations.AddField(
model_name='label',
name='style',
field=models.CharField(choices=[('basic_99012_v1', 'Basic Dymo 89x36mm label')], default='basic_99012_v1', max_length=32),
),
]

View File

@ -1,13 +1,17 @@
from __future__ import unicode_literals
import uuid
import re
from django.db import models
from django.conf import settings
from django.contrib.auth.models import User
from django_hstore import hstore
import uuid
from tree.fields import PathField
from tree.models import TreeModelMixin
import requests
STATES = (
('present', 'Present'),
@ -17,7 +21,6 @@ STATES = (
)
# Create your models here.
class Category(models.Model):
name = models.CharField(max_length=127)
@ -53,6 +56,17 @@ class Item(models.Model, TreeModelMixin):
from django.urls import reverse
return reverse('item-display', kwargs={'pk': str(self.pk)})
def get_or_create_label(self, **kwargs):
defaults = {
'id': re.sub('[^A-Z0-9]', '', self.name.upper())[:16],
}
defaults.update(kwargs)
obj, created = self.labels.get_or_create(**kwargs, defaults=defaults)
return obj
class Meta:
ordering = ('path',)
@ -65,4 +79,15 @@ class ItemImage(models.Model):
class Label(models.Model):
id = models.CharField(max_length=64, primary_key=True)
item = models.ForeignKey(Item, related_name='labels')
revision = models.IntegerField()
style = models.CharField(max_length=32, choices=(
('basic_99012_v1', 'Basic Dymo 89x36mm label'),
), default='basic_99012_v1')
created = models.DateTimeField(auto_now_add=True, blank=True)
def __str__(self):
return self.id
def print(self):
resp = requests.post(
'{}/api/1/print/{}'.format(settings.LABEL_API, self.id))
resp.raise_for_status()

View File

@ -12,4 +12,4 @@ class LabelSerializer(serializers.ModelSerializer):
item = ItemSerializer()
class Meta:
model = Label
fields = ('id', 'item', 'revision')
fields = ('id', 'item', 'style')