Check in whatever is there - haven't touched that in a while...
This commit is contained in:
parent
c5d320dc1a
commit
1dbafe914e
9 changed files with 82 additions and 0 deletions
|
@ -28,13 +28,20 @@ ALLOWED_HOSTS = ["*"] # Let the web server handle that. That's its job.
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
|
# Django internals
|
||||||
'django.contrib.admin',
|
'django.contrib.admin',
|
||||||
'django.contrib.auth',
|
'django.contrib.auth',
|
||||||
'django.contrib.contenttypes',
|
'django.contrib.contenttypes',
|
||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
|
|
||||||
|
# Third party apps
|
||||||
|
'polymorphic',
|
||||||
|
|
||||||
|
# In-project apps
|
||||||
'dbsettings',
|
'dbsettings',
|
||||||
|
'profiles',
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
|
0
profiles/__init__.py
Normal file
0
profiles/__init__.py
Normal file
3
profiles/admin.py
Normal file
3
profiles/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
5
profiles/apps.py
Normal file
5
profiles/apps.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class ProfilesConfig(AppConfig):
|
||||||
|
name = 'profiles'
|
5
profiles/helpers.py
Normal file
5
profiles/helpers.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
CLIENT_PERMISSION_CHOICES = (
|
||||||
|
)
|
||||||
|
|
||||||
|
OPERATOR_PERMISSION_CHOICES = (
|
||||||
|
)
|
54
profiles/models.py
Normal file
54
profiles/models.py
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
from django.db.models import OneToOneField, SET_NULL, Model, ForeignKey, CASCADE, CharField
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
|
||||||
|
from polymorphic.models import PolymorphicModel
|
||||||
|
from multiselectfield import MultiSelectField
|
||||||
|
from django_countries.fields import CountryField
|
||||||
|
from vies.types import MEMBER_COUNTRY_CODES, VATIN
|
||||||
|
|
||||||
|
from profiles.helpers import CLIENT_PERMISSION_CHOICES, OPERATOR_PERMISSION_CHOICES
|
||||||
|
|
||||||
|
# Create your models here.
|
||||||
|
|
||||||
|
class Client(Model):
|
||||||
|
company = CharField(max_length=255, blank=True, null=True)
|
||||||
|
country = CountryField()
|
||||||
|
vatid = CharField(max_length=255, blank=True, null=True)
|
||||||
|
|
||||||
|
def validate_vatid(self):
|
||||||
|
if not self.vatid:
|
||||||
|
return -1
|
||||||
|
if self.vatid.lower().startswith("eu"): # pylint: disable=no-member
|
||||||
|
return -2
|
||||||
|
if not (self.vatid.upper()[:2]) in list(MEMBER_COUNTRY_CODES): # pylint: disable=no-member
|
||||||
|
return -3
|
||||||
|
if not ((self.country.code == self.vatid.upper()[:2]) or (self.country.code == "GR" and self.vatid.upper()[:2] == "EL")): # pylint: disable=no-member
|
||||||
|
return -4
|
||||||
|
return 1 if VATIN.from_str(self.vatid).is_valid else 0
|
||||||
|
|
||||||
|
def vatid_data(self, force=False):
|
||||||
|
if force or self.validate_vatid() == 1:
|
||||||
|
return VATIN.from_str(self.vatid).data
|
||||||
|
raise ValueError("VAT ID is not valid or cannot be validated")
|
||||||
|
|
||||||
|
class Profile(PolymorphicModel):
|
||||||
|
user = OneToOneField(get_user_model(), on_delete=SET_NULL, null=True)
|
||||||
|
client = ForeignKey(Client, on_delete=CASCADE)
|
||||||
|
first_name = CharField(max_length=255)
|
||||||
|
last_name = CharField(max_length=255)
|
||||||
|
|
||||||
|
class ClientProfile(Profile):
|
||||||
|
permissions = MultiSelectField(choices=CLIENT_PERMISSION_CHOICES, null=True)
|
||||||
|
address1 = CharField(max_length=255)
|
||||||
|
address2 = CharField(max_length=255, null=True, blank=True)
|
||||||
|
|
||||||
|
class OperatorProfile(Profile):
|
||||||
|
permissions = MultiSelectField(choices=OPERATOR_PERMISSION_CHOICES, null=True)
|
||||||
|
|
||||||
|
class ClientPermissionGroup(Model):
|
||||||
|
name = CharField(max_length=255)
|
||||||
|
permissions = MultiSelectField(choices=CLIENT_PERMISSION_CHOICES, null=True)
|
||||||
|
|
||||||
|
class OperatorPermissionGroup(Model):
|
||||||
|
name = CharField(max_length=255)
|
||||||
|
permissions = MultiSelectField(choices=OPERATOR_PERMISSION_CHOICES, null=True)
|
3
profiles/tests.py
Normal file
3
profiles/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
3
profiles/views.py
Normal file
3
profiles/views.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
# Create your views here.
|
|
@ -1,2 +1,4 @@
|
||||||
django[argon2]
|
django[argon2]
|
||||||
mysqlclient
|
mysqlclient
|
||||||
|
django-polymorphic
|
||||||
|
django-vies
|
Loading…
Reference in a new issue