PK!*django_barcode/__init__.py__version__ = '0.1.0'PK!!11django_barcode/core.pyimport base64 from io import BytesIO from uuid import UUID from barcode.ean import EuropeanArticleNumber13 as BarcodeClass from django.utils.html import mark_safe class Barcode(BarcodeClass): '''EAN13 standard numeric barcode''' @property def bars(self): '''Barcode rendered as SVG (code displayed).''' return mark_safe(self.render(text=False).decode('utf-8')) @property def barcode(self): '''Barcode rendered as SVG (code displayed).''' return mark_safe(self.render().decode('utf-8')) PK!Q  django_barcode/fields.py from uuid import uuid4 from django.db import models from django.core import exceptions from django.utils.translation import gettext_lazy as _ from .core import Barcode from django.conf import settings from django.core import checks from django.utils.crypto import get_random_string default_country = getattr(settings,'BARCODE_COUNTRY','950') default_brand = getattr(settings,'BARCODE_BRAND','0000') class BarcodeFieldDescriptor(object): '''Field descriptor responsible for the seamless access of Barcode object properties''' def __init__(self,_name,_class): self._name = _name self._class = _class def __get__(self,instance=None,owner=None): value = instance.__dict__[self._name] if value is None: return value return self._class(value) def __set__(self,instance,value): instance.__dict__[self._name] = value class BarcodeField(models.CharField): '''Barcode model field based on a EAN13 standard and BigAutoField''' description = _('EAN13 Barcode.') def generate_default(self): return "".join([self.country,self.brand,get_random_string(5, '0123456789')]) def contribute_to_class(self, cls, name): super(BarcodeField, self).contribute_to_class(cls, name) setattr(cls, self.name, BarcodeFieldDescriptor(self.name,Barcode)) def __init__(self,country:str=default_country,brand:str=default_brand, **kwargs): self.country = country self.brand = brand kwargs['max_length']=13 kwargs['default']=self.generate_default() super().__init__(**kwargs) def deconstruct(self): name, path, args, kwargs = super().deconstruct() del kwargs['max_length'] del kwargs['default'] if self.country != default_country: kwargs['country'] = self.country if self.brand != default_brand: kwargs['brand'] = self.brand return name, path, args, kwargs def check(self, **kwargs): return [ *super().check(**kwargs), *self._check_country(), *self._check_brand(), ] def _check_country(self): if len(self.country) is not 3: return [ checks.Error( "%s's country argument must have a 3 digits." % self.__class__.__name__, obj=self, id='fields.E201', ) ] else: return [] def _check_brand(self): if len(self.brand) is not 4: return [ checks.Error( "%s's country argument must have a 4 digits." % self.__class__.__name__, obj=self, id='fields.E201', ) ] else: return [] PK!HڽTU$django_barcode-0.1.0.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!H~j'django_barcode-0.1.0.dist-info/METADATAAK@+樐,[#CZ,XLJv7&{'Umy7@=cBm9\*Q&oUI}FϴQ9C+u-}`XO DmVwQa#}Z_jKv f<)9m8~JZA7sq ]sL1+LϓRߴrgˡat6vz>W_^mOKr!&E_G+mB6#PK!HB)%django_barcode-0.1.0.dist-info/RECORD̹r@>vHAd!"Whv]C>3&)|2jQiA7xD.pX|`Zҁԛs Z/[Vk.` yKIgOTLCEH-W]MlO .dk bY4gU:<}v9FfI4#?TF0os*BR<$nvAh<)oVAVfT\]E;vڄ$KcX_gdu7 >v6b=[vv"wml ~PK!*django_barcode/__init__.pyPK!!11Mdjango_barcode/core.pyPK!Q  django_barcode/fields.pyPK!HڽTU$ django_barcode-0.1.0.dist-info/WHEELPK!H~j'django_barcode-0.1.0.dist-info/METADATAPK!HB)%django_barcode-0.1.0.dist-info/RECORDPKB