From 1efda993fd9f8570e54460ee12f035558216ffc9 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Wed, 27 May 2020 15:06:38 +0200 Subject: [PATCH] Create LongCharField to make code prettier Create Models for clients and dummy model for brands --- core/fields/__init__.py | 0 core/fields/base.py | 6 ++++++ core/models/brands.py | 4 ++++ core/models/cron.py | 6 ++++-- core/models/files.py | 5 +++-- core/models/local.py | 6 ++++-- core/models/products.py | 7 ++++--- core/models/profiles.py | 37 +++++++++++++++++++++++++++++++++---- requirements.txt | 2 ++ 9 files changed, 60 insertions(+), 13 deletions(-) create mode 100644 core/fields/__init__.py create mode 100644 core/fields/base.py create mode 100644 core/models/brands.py diff --git a/core/fields/__init__.py b/core/fields/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/core/fields/base.py b/core/fields/base.py new file mode 100644 index 0000000..381b64e --- /dev/null +++ b/core/fields/base.py @@ -0,0 +1,6 @@ +from django.db.models import CharField + +class LongCharField(CharField): + def __init__(self, *args, **kwargs): + kwargs['max_length'] = 255 + super().__init__(*args, **kwargs) \ No newline at end of file diff --git a/core/models/brands.py b/core/models/brands.py new file mode 100644 index 0000000..481ed3b --- /dev/null +++ b/core/models/brands.py @@ -0,0 +1,4 @@ +from django.db.models import Model + +class Brand(Model): + pass \ No newline at end of file diff --git a/core/models/cron.py b/core/models/cron.py index 63d1a13..7b633ea 100644 --- a/core/models/cron.py +++ b/core/models/cron.py @@ -1,6 +1,8 @@ -from django.db.models import Model, CharField, DateTimeField, BooleanField +from django.db.models import Model, DateTimeField, BooleanField + +from core.fields.base import LongCharField class CronLog(Model): - task = CharField(max_length=255) + task = LongCharField() execution = DateTimeField(auto_now_add=True) locked = BooleanField(default=True) diff --git a/core/models/files.py b/core/models/files.py index eaa4cb0..7ebd7d6 100644 --- a/core/models/files.py +++ b/core/models/files.py @@ -1,15 +1,16 @@ -from django.db.models import Model, CharField, ImageField, FileField, ManyToManyField, ForeignKey, BooleanField, CASCADE +from django.db.models import Model, ImageField, FileField, ManyToManyField, ForeignKey, BooleanField, CASCADE from django.contrib.auth import get_user_model from polymorphic.models import PolymorphicModel from core.helpers.files import generate_storage_filename from core.models.profiles import Profile +from core.fields.base import LongCharField # Create your models here. class BaseFile(PolymorphicModel): - filename = CharField(max_length=255) + filename = LongCharField() class ImageFile(BaseFile): rawfile = ImageField(upload_to=generate_storage_filename) diff --git a/core/models/local.py b/core/models/local.py index 157362b..eb4c376 100644 --- a/core/models/local.py +++ b/core/models/local.py @@ -2,8 +2,10 @@ from django.db.models import Model, CharField, BooleanField, DecimalField, Forei from django_countries.fields import CountryField +from core.fields.base import LongCharField + class Currency(Model): - name = CharField(max_length=255, unique=True) + name = LongCharField(unique=True) code = CharField(max_length=16, unique=True) symbol = CharField(max_length=8) base = BooleanField(default=False) @@ -18,7 +20,7 @@ class Currency(Model): return cls.objects.get(base=True) class TaxPolicy(Model): - name = CharField(max_length=255, blank=True) + name = LongCharField(blank=True) default_rate = DecimalField(default=0, max_digits=10, decimal_places=5) def get_applicable_rate(self, country, reverse_charge=False): diff --git a/core/models/products.py b/core/models/products.py index c1b9cbb..75ed463 100644 --- a/core/models/products.py +++ b/core/models/products.py @@ -1,4 +1,5 @@ from core.models.billable import CycleChoices +from core.fields.base import LongCharField from django.db.models import Model, IntegerChoices, PositiveIntegerField, DecimalField, ForeignKey, CASCADE, CharField, TextField, ManyToManyField @@ -9,12 +10,12 @@ import logging logger = logging.getLogger(__name__) class ProductGroup(Model): - name = CharField(max_length=255) + name = LongCharField() class Product(Model): - name = CharField(max_length=255) + name = LongCharField() description = TextField(null=True, blank=True) - handler_module = CharField(max_length=255, null=True, blank=True) + handler_module = LongCharField(null=True, blank=True) product_groups = ManyToManyField(ProductGroup) @property diff --git a/core/models/profiles.py b/core/models/profiles.py index f1340b3..e0a0a70 100644 --- a/core/models/profiles.py +++ b/core/models/profiles.py @@ -1,20 +1,49 @@ from polymorphic.models import PolymorphicModel from phonenumber_field.modelfields import PhoneNumberField +from internationalflavor.vat_number.models import VATNumberField +from django_countries.fields import CountryField -from django.db.models import OneToOneField, CASCADE, CharField, ImageField +from django.db.models import OneToOneField, CASCADE, ImageField, Model, ForeignKey, SET_DEFAULT, ManyToManyField, DateTimeField, TextField from django.contrib.auth import get_user_model from core.helpers.files import generate_storage_filename +from core.models.local import Currency +from core.models.brands import Brand +from core.fields.base import LongCharField + +class ClientGroup(Model): + name = LongCharField() class Profile(PolymorphicModel): user = OneToOneField(get_user_model(), CASCADE) mobile = PhoneNumberField(blank=True) class AdminProfile(Profile): - role = CharField(max_length=255) + role = LongCharField() image = ImageField(null=True, blank=True, upload_to=generate_storage_filename) - display_name = CharField("Internal Display Name", max_length=255, null=True, blank=True) + display_name = LongCharField("Internal Display Name", null=True, blank=True) @property def get_internal_name(self): - return self.display_name if self.display_name else self.user.get_full_name \ No newline at end of file + return self.display_name if self.display_name else self.user.get_full_name + +class ClientProfile(Profile): + company = LongCharField() + address1 = LongCharField() + address2 = LongCharField() + zip = LongCharField() + city = LongCharField() + state = LongCharField() + country = CountryField() + vat_id = VATNumberField() + company_id = LongCharField() + default_currency = ForeignKey(Currency, on_delete=SET_DEFAULT, default=Currency.get_base) + client_groups = ManyToManyField(ClientGroup) + brands = ManyToManyField(Brand) + marketing_opt_in = DateTimeField(null=True) + pgp_key = TextField(null=True) + main_client = ForeignKey("self", null=True, on_delete=SET_DEFAULT, default=None) + + @property + def get_nda(self): + return None \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index acbcb4a..c3fa172 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,3 +15,5 @@ python-memcached django-countries pyuca git+https://kumig.it/kumisystems/parse_crontab.git +django-internationalflavor +suds-jurko