From 9f32739d15c064890164d8c8985f2e448cc0c03a Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Wed, 26 Sep 2018 18:42:56 +0300 Subject: Accounts app --- .envrc | 2 + .vscode/settings.json | 3 + README.md | 15 +++++ TODO.md | 2 + motor/accounts/__init__.py | 0 motor/accounts/admin.py | 3 + motor/accounts/apps.py | 5 ++ motor/accounts/migrations/__init__.py | 0 motor/accounts/models.py | 4 ++ motor/accounts/tests.py | 3 + motor/accounts/views.py | 3 + motor/manage.py | 15 +++++ motor/motor/__init__.py | 0 motor/motor/settings.py | 123 ++++++++++++++++++++++++++++++++++ motor/motor/urls.py | 21 ++++++ motor/motor/wsgi.py | 16 +++++ requirements.pip | 3 + 17 files changed, 218 insertions(+) create mode 100644 .envrc create mode 100644 .vscode/settings.json create mode 100644 TODO.md create mode 100644 motor/accounts/__init__.py create mode 100644 motor/accounts/admin.py create mode 100644 motor/accounts/apps.py create mode 100644 motor/accounts/migrations/__init__.py create mode 100644 motor/accounts/models.py create mode 100644 motor/accounts/tests.py create mode 100644 motor/accounts/views.py create mode 100755 motor/manage.py create mode 100644 motor/motor/__init__.py create mode 100644 motor/motor/settings.py create mode 100644 motor/motor/urls.py create mode 100644 motor/motor/wsgi.py create mode 100644 requirements.pip diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..271d6d4 --- /dev/null +++ b/.envrc @@ -0,0 +1,2 @@ +. .env/bin/activate + diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..d90c903 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "${workspaceFolder}/.env/bin/python" +} \ No newline at end of file diff --git a/README.md b/README.md index 0fe0437..224dce2 100644 --- a/README.md +++ b/README.md @@ -1 +1,16 @@ # motor + +The front-end for the multi-tenant version of Servo. + + +## Reading list + +- https://www.citusdata.com/blog/2016/10/03/designing-your-saas-database-for-high-scalability/ +- https://github.com/citusdata/django-multitenant +- https://www.vinta.com.br/blog/2017/multitenancy-juggling-customer-data-django/ +- https://django-tenants.readthedocs.io/en/latest/ + + +## Running it + + DBHOST=localhost DBNAME=motor DBUSER=servo DBPW='' ./manage.py runserver diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..1a86f37 --- /dev/null +++ b/TODO.md @@ -0,0 +1,2 @@ +- Registration page +- Backend routing logic diff --git a/motor/accounts/__init__.py b/motor/accounts/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/motor/accounts/admin.py b/motor/accounts/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/motor/accounts/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/motor/accounts/apps.py b/motor/accounts/apps.py new file mode 100644 index 0000000..9b3fc5a --- /dev/null +++ b/motor/accounts/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class AccountsConfig(AppConfig): + name = 'accounts' diff --git a/motor/accounts/migrations/__init__.py b/motor/accounts/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/motor/accounts/models.py b/motor/accounts/models.py new file mode 100644 index 0000000..1593487 --- /dev/null +++ b/motor/accounts/models.py @@ -0,0 +1,4 @@ +from django.db import models + +class Client(models.Model): + pass diff --git a/motor/accounts/tests.py b/motor/accounts/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/motor/accounts/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/motor/accounts/views.py b/motor/accounts/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/motor/accounts/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/motor/manage.py b/motor/manage.py new file mode 100755 index 0000000..ce7f12b --- /dev/null +++ b/motor/manage.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == '__main__': + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'motor.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) diff --git a/motor/motor/__init__.py b/motor/motor/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/motor/motor/settings.py b/motor/motor/settings.py new file mode 100644 index 0000000..e770955 --- /dev/null +++ b/motor/motor/settings.py @@ -0,0 +1,123 @@ +""" +Django settings for motor project. + +Generated by 'django-admin startproject' using Django 2.1.1. + +For more information on this file, see +https://docs.djangoproject.com/en/2.1/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.1/ref/settings/ +""" + +import os + +# 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 +# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '9#)@&5$8pi!39gaxy92w^t(kvmpw(l4#ysqnfn9nkx0=n1!qfj' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'motor.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'motor.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.1/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE' : 'django.db.backends.postgresql_psycopg2', + 'HOST' : os.getenv('DBHOST'), + 'NAME' : os.getenv('DBNAME'), + 'USER' : os.getenv('DBUSER'), + 'PASSWORD' : os.getenv('DBPW'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/2.1/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.1/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/motor/motor/urls.py b/motor/motor/urls.py new file mode 100644 index 0000000..bd6ad50 --- /dev/null +++ b/motor/motor/urls.py @@ -0,0 +1,21 @@ +"""motor URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.1/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path + +urlpatterns = [ + path('admin/', admin.site.urls), +] diff --git a/motor/motor/wsgi.py b/motor/motor/wsgi.py new file mode 100644 index 0000000..5e294c6 --- /dev/null +++ b/motor/motor/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for motor project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'motor.settings') + +application = get_wsgi_application() diff --git a/requirements.pip b/requirements.pip new file mode 100644 index 0000000..e8ed7a6 --- /dev/null +++ b/requirements.pip @@ -0,0 +1,3 @@ +django +psycopg2-binary +django-bootstrap4 -- cgit v1.2.3