django 2.2

This commit is contained in:
Jonas Legion 2021-06-10 13:57:59 +02:00
parent 7244fdc187
commit f6aeedb93e
17 changed files with 33 additions and 197 deletions

View File

@ -1,8 +0,0 @@
from django.contrib import admin
from django_tenants.admin import TenantAdminMixin
from Customers.models import Client
@admin.register(Client)
class ClientAdmin(TenantAdminMixin, admin.ModelAdmin):
list_display = ('name', 'paid_until')

View File

@ -1,5 +0,0 @@
from django.apps import AppConfig
class AdministrationConfig(AppConfig):
name = 'Administration'

View File

@ -1,3 +0,0 @@
from django.db import models
# Create your models here.

View File

@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View File

@ -1,3 +0,0 @@
from django.shortcuts import render
# Create your views here.

View File

@ -1,42 +0,0 @@
# Generated by Django 3.1 on 2021-06-10 10:54
from django.db import migrations, models
import django.db.models.deletion
import django_tenants.postgresql_backend.base
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Client',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('schema_name', models.CharField(db_index=True, max_length=63, unique=True, validators=[django_tenants.postgresql_backend.base._check_schema_name])),
('name', models.CharField(max_length=100)),
('paid_until', models.DateField()),
('on_trial', models.BooleanField()),
('created_on', models.DateField(auto_now_add=True)),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='Domain',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('domain', models.CharField(db_index=True, max_length=253, unique=True)),
('is_primary', models.BooleanField(db_index=True, default=True)),
('tenant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='domains', to='Customers.client')),
],
options={
'abstract': False,
},
),
]

View File

@ -1,46 +0,0 @@
# Generated by Django 3.1 on 2021-06-10 10:56
import os
from django.db import migrations
def create_premier_tenant(apps, schema_editor):
# We can't import the Person model directly as it may be a newer
# version than this migration expects. We use the historical version.
Client = apps.get_model('Customers', 'Client')
Domain = apps.get_model('Customers', 'Domain')
DNS = os.getenv('DOMAIN')
tenant_public = Client.objects.get_or_create(schema_name='public',
name='Tibillet Public',
paid_until='2200-12-05',
on_trial=False)[0]
# Add one or more domains for the tenant
domaine_seul = Domain.objects.get_or_create(domain=DNS,
tenant=tenant_public,
is_primary=True,
)
domaine_www = Domain.objects.get_or_create(domain=f'www.{DNS}',
tenant=tenant_public,
is_primary=False,
)
return tenant_public, domaine_seul[0], domaine_www[0]
def reverse(apps, schema_editor):
tenant_public, domaine_seul, domaine_www = create_premier_tenant(apps, schema_editor)
tenant_public.delete()
domaine_seul.delete()
domaine_www.delete()
class Migration(migrations.Migration):
dependencies = [
('Customers', '0001_initial'),
]
operations = [
migrations.RunPython(create_premier_tenant, reverse),
]

View File

@ -1,14 +1,3 @@
from django.db import models from django.db import models
from django_tenants.models import TenantMixin, DomainMixin
class Client(TenantMixin): # Create your models here.
name = models.CharField(max_length=100)
paid_until = models.DateField()
on_trial = models.BooleanField()
created_on = models.DateField(auto_now_add=True)
# default true, schema will be automatically created and synced when it is saved
auto_create_schema = True
class Domain(DomainMixin):
pass

View File

@ -1,16 +0,0 @@
"""
ASGI config for TiBillet project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'TiBillet.settings')
application = get_asgi_application()

View File

@ -1,67 +1,45 @@
""" """
Django settings for TiBillet project. Django settings for TiBillet project.
Generated by 'django-admin startproject' using Django 3.1. Generated by 'django-admin startproject' using Django 2.2.
For more information on this file, see For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/ https://docs.djangoproject.com/en/2.2/topics/settings/
For the full list of settings and their values, see For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/ https://docs.djangoproject.com/en/2.2/ref/settings/
""" """
import os
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'. import os
BASE_DIR = Path(__file__).resolve(strict=True).parent.parent
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production # Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret! # SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('DJANGO_SECRET') SECRET_KEY = '(4ux&3#$@yn=dxpi%sl^*&ib+mtg2c0-2gxwjl-m&^ci@+a!o!'
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
# noinspection DjangoDebugModeSettings DEBUG = True
if os.environ.get('DEBUG_DJANGO') == "True":
DEBUG = True ALLOWED_HOSTS = []
else:
DEBUG = False
ALLOWED_HOSTS = ['*']
# Application definition # Application definition
SHARED_APPS = ( INSTALLED_APPS = [
'django_tenants', # mandatory
'Customers', # you must list the app where your tenant model resides in
'django.contrib.contenttypes',
# everything below here is optional
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin', 'django.contrib.admin',
'django_extensions', 'django.contrib.auth',
'Administration',
)
TENANT_APPS = (
# The following Django contrib apps must be in TENANT_APPS
'django.contrib.contenttypes', 'django.contrib.contenttypes',
'django.contrib.sessions',
# your tenant-specific apps 'django.contrib.messages',
) 'django.contrib.staticfiles',
]
INSTALLED_APPS = list(SHARED_APPS) + [app for app in TENANT_APPS if app not in SHARED_APPS]
TENANT_MODEL = "Customers.Client" # app.Model
TENANT_DOMAIN_MODEL = "Customers.Domain" # app.Model
MIDDLEWARE = [ MIDDLEWARE = [
'django_tenants.middleware.main.TenantMainMiddleware',
'django.middleware.security.SecurityMiddleware', 'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
@ -91,26 +69,20 @@ TEMPLATES = [
WSGI_APPLICATION = 'TiBillet.wsgi.application' WSGI_APPLICATION = 'TiBillet.wsgi.application'
# Database # Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases # https://docs.djangoproject.com/en/2.2/ref/settings/#databases
DATABASES = { DATABASES = {
'default': { 'default': {
'ENGINE': 'django_tenants.postgresql_backend', # Add 'postgresql', 'mysql', 'sqlite3' or 'oracle'. 'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.environ.get('POSTGRES_DB'), 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'USER': os.environ.get('POSTGRES_USER'),
'PASSWORD': os.environ.get('POSTGRES_PASSWORD'),
'HOST': os.environ.get('POSTGRES_HOST'),
'PORT': os.environ.get('POSTGRES_PORT', '5432'),
} }
} }
DATABASE_ROUTERS = (
'django_tenants.routers.TenantSyncRouter',
)
# Password validation # Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [ AUTH_PASSWORD_VALIDATORS = [
{ {
@ -127,8 +99,9 @@ AUTH_PASSWORD_VALIDATORS = [
}, },
] ]
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/ # https://docs.djangoproject.com/en/2.2/topics/i18n/
LANGUAGE_CODE = 'en-us' LANGUAGE_CODE = 'en-us'
@ -140,7 +113,8 @@ USE_L10N = True
USE_TZ = True USE_TZ = True
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/ # https://docs.djangoproject.com/en/2.2/howto/static-files/
STATIC_URL = '/static/' STATIC_URL = '/static/'

View File

@ -1,7 +1,7 @@
"""TiBillet URL Configuration """TiBillet URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see: The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.1/topics/http/urls/ https://docs.djangoproject.com/en/2.2/topics/http/urls/
Examples: Examples:
Function views Function views
1. Add an import: from my_app import views 1. Add an import: from my_app import views

View File

@ -4,7 +4,7 @@ WSGI config for TiBillet project.
It exposes the WSGI callable as a module-level variable named ``application``. It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see For more information on this file, see
https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/ https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/
""" """
import os import os

View File

@ -1 +1 @@
sleep 36d sleep 30d

View File

@ -5,7 +5,6 @@ import sys
def main(): def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'TiBillet.settings') os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'TiBillet.settings')
try: try:
from django.core.management import execute_from_command_line from django.core.management import execute_from_command_line

View File

@ -6,7 +6,7 @@ RUN apt-get upgrade -y
RUN pip install pip --upgrade RUN pip install pip --upgrade
## PYTHON ## PYTHON
RUN pip install django==3.1 RUN pip install django==2.2
RUN pip install djangorestframework==3.11 RUN pip install djangorestframework==3.11
RUN pip install requests RUN pip install requests
RUN pip install django-jet RUN pip install django-jet