PK!*django_barcode/__init__.py__version__ = '0.1.0'PK!??django_barcode/admin.pyfrom django.contrib import admin # Register your models here. PK! z``django_barcode/apps.pyfrom django.apps import AppConfig class BarCodeConfig(AppConfig): name = 'django_barcode' 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!R.  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''' 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!e|9django_barcode/models.pyfrom django.db import models from .fields import BarcodeField class Barcode(models.Model): bc = BarcodeField() class BarcodePK(models.Model): bc = BarcodeField(primary_key=True) class BarcodeUnique(models.Model): bc = BarcodeField(unique=True) class BarcodeCB(models.Model): bc = BarcodeField(country='123',brand='1234') class BarcodeAll(models.Model): bc = BarcodeField(primary_key=True,unique=True,country='123',brand='1234')PK!],django_barcode/templates/barcode_create.htmlBarcode Create
{% csrf_token %} {{form}}
PK!@I(,django_barcode/templates/barcode_delete.htmlBarcode Delete Barcode Create
{% csrf_token %} {{form}}

Are you sure you want to delete {{object}}:{{object.bc}} ?

PK!$GRR,django_barcode/templates/barcode_detail.html
ID
CODE BARS BARCODE
{{object.id}} {{object.bc}} {{object.bc.bars}} {{object.bc.barcode}}
Update DeletePK!)݈*django_barcode/templates/barcode_list.htmlBarcode List {% for object in object_list %} {% endfor %}
{{object.bc}}
PK!,django_barcode/templates/barcode_update.htmlBarcode Update
{% csrf_token %} {{form}}
PK!\ffdjango_barcode/tests.pyfrom django.test import TestCase from .models import Barcode, BarcodePK, BarcodeUnique, BarcodeCB, BarcodeAll class BarcodeTestCase(TestCase): def setUp(self): Barcode.objects.create() BarcodePK.objects.create() BarcodeUnique.objects.create() BarcodeCB.objects.create() BarcodeAll.objects.create() def test_barcode(self): """ Test simple barcode creation """ bc = Barcode.objects.all().first() bcpk = BarcodePK.objects.all().first() bcu = BarcodeUnique.objects.all().first() bccb = BarcodeCB.objects.all().first() bcall = BarcodeAll.objects.all().first() self.assertEqual(bc!=None,True) self.assertEqual(bcpk!=None,True) self.assertEqual(bcu!=None,True) self.assertEqual(bccb!=None,True) self.assertEqual(bcall!=None,True) PK!Sdjango_barcode/urls.pyfrom django.urls import path from . import views urlpatterns = [ path('',views.BarcodeListView.as_view(), name="list"), path('create', views.BarcodeCreateView.as_view(),name="create"), path('detail/', views.BarcodeDetailView.as_view(), name="detail"), path('update/', views.BarcodeUpdateView.as_view(),name="update"), path('delete/',views.BarcodeDeleteView.as_view(),name="delete") ] PK!7TTdjango_barcode/views.pyfrom .models import Barcode from django.shortcuts import render from django.urls import reverse_lazy from django.views import generic class BarcodeListView(generic.ListView): queryset = Barcode.objects.all() template_name = "barcode_list.html" class BarcodeCreateView(generic.CreateView): model = Barcode fields = '__all__' template_name = "barcode_create.html" success_url = reverse_lazy('list') class BarcodeDetailView(generic.DetailView): model = Barcode template_name = "barcode_detail.html" class BarcodeUpdateView(generic.UpdateView): model = Barcode fields = '__all__' template_name = "barcode_update.html" success_url = reverse_lazy('list') class BarcodeDeleteView(generic.DeleteView): model = Barcode template_name = "barcode_delete.html" success_url = reverse_lazy('list') PK!HڽTU$django_barcode-0.1.1.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!H-$'django_barcode-0.1.1.dist-info/METADATAN0D=X.EEDiEE%(*K Fɡ&jqK'f<)9M8\RZA#sr][n֋TϒRu`Vj;5sװԃL6zvpI>?Ҏ<j6I.PK!Ha%django_barcode-0.1.1.dist-info/RECORDɎ0{? t/9BdX,N7!<0-C,!]%YP]k]T J{>;b?7y^!i.rzi):KoE~? .IC]3`KytyoζU{yO' Njq4 [B.63H4? v$6W\D>a@#m /M7Y`dʈ{ȶ!ZrEmgb,vK 2V6Zkh(/n|ĥfnaVǦSA,`(x zz7*r0aSx{.KrN,*b2w%婊IB0^8$+~t OKuXhmgqp,+iQ "PٻSKM5_R%_Ɍ2.[})p:%ȉ2ÿ>CoVSaPK!*django_barcode/__init__.pyPK!??Mdjango_barcode/admin.pyPK! z``django_barcode/apps.pyPK!!11Udjango_barcode/core.pyPK!R.  django_barcode/fields.pyPK!e|9django_barcode/models.pyPK!],django_barcode/templates/barcode_create.htmlPK!@I(,django_barcode/templates/barcode_delete.htmlPK!$GRR,django_barcode/templates/barcode_detail.htmlPK!)݈*django_barcode/templates/barcode_list.htmlPK!,zdjango_barcode/templates/barcode_update.htmlPK!\ffbdjango_barcode/tests.pyPK!Sdjango_barcode/urls.pyPK!7TTdjango_barcode/views.pyPK!HڽTU$_ django_barcode-0.1.1.dist-info/WHEELPK!H-$' django_barcode-0.1.1.dist-info/METADATAPK!Ha%>"django_barcode-0.1.1.dist-info/RECORDPK)%