sipp11
6 years ago
commit
0856ea3c55
19 changed files with 416 additions and 0 deletions
@ -0,0 +1,18 @@
|
||||
*.pyc |
||||
.DS_Store |
||||
|
||||
settings_prod.py |
||||
settings_local.py |
||||
|
||||
bower_components |
||||
node_modules |
||||
package-lock.json |
||||
*.pip |
||||
|
||||
*.sublime-workspace |
||||
*.db |
||||
*.pid |
||||
|
||||
celerybeat-schedule* |
||||
__pycache__ |
||||
*.sqlite3 |
@ -0,0 +1,22 @@
|
||||
{ |
||||
"python.pythonPath": "~/.virtualenvs/ismp/bin/python", |
||||
"python.formatting.provider": "yapf", |
||||
"python.linting.pylintArgs": [ |
||||
// "--disable=W0312" |
||||
"--disable=E0401", |
||||
"--disable=E1101" |
||||
], |
||||
"search.exclude": { |
||||
".git": true, |
||||
".eslintcache": true, |
||||
"__pycache__": true, |
||||
"node_modules": true, |
||||
"bower_components": true, |
||||
"yarn.lock": true |
||||
}, |
||||
"files.exclude": { |
||||
"**/__pycache__": true, |
||||
"**/*.pyc": true, |
||||
"**/._*": true |
||||
}, |
||||
} |
@ -0,0 +1,11 @@
|
||||
# ISMP |
||||
|
||||
Started on Jul 25, 2018. Will finish on? Let's see. |
||||
|
||||
## Dependencies |
||||
|
||||
* python3 |
||||
* PostgreSQL |
||||
* django |
||||
* restframework |
||||
|
@ -0,0 +1,190 @@
|
||||
import os |
||||
import json |
||||
import raven |
||||
from datetime import timedelta |
||||
|
||||
# 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.0/howto/deployment/checklist/ |
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret! |
||||
SECRET_KEY = 'ou1vb^1o^0!9i@h-0d!89+6nu#wxx=u5b+=2@y@vq+ixfrmq(n' |
||||
|
||||
# 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', |
||||
|
||||
'corsheaders', |
||||
'rest_framework', |
||||
'rest_framework_jwt', |
||||
'django_filters', |
||||
'raven.contrib.django.raven_compat', |
||||
|
||||
'people', |
||||
] |
||||
|
||||
AUTH_USER_MODEL = 'people.User' |
||||
|
||||
MIDDLEWARE = [ |
||||
'django.middleware.security.SecurityMiddleware', |
||||
'django.contrib.sessions.middleware.SessionMiddleware', |
||||
'corsheaders.middleware.CorsMiddleware', |
||||
'django.middleware.common.CommonMiddleware', |
||||
'django.middleware.csrf.CsrfViewMiddleware', |
||||
'django.contrib.auth.middleware.AuthenticationMiddleware', |
||||
'django.contrib.messages.middleware.MessageMiddleware', |
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware', |
||||
] |
||||
|
||||
ROOT_URLCONF = 'ismp.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 = 'ismp.wsgi.application' |
||||
|
||||
|
||||
# Database |
||||
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases |
||||
|
||||
DATABASES = { |
||||
'default': { |
||||
'ENGINE': 'django.db.backends.sqlite3', |
||||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), |
||||
} |
||||
} |
||||
|
||||
|
||||
# Password validation |
||||
# https://docs.djangoproject.com/en/2.0/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.0/topics/i18n/ |
||||
|
||||
LANGUAGE_CODE = 'en-us' |
||||
TIME_ZONE = 'Asia/Bangkok' |
||||
USE_I18N = True |
||||
USE_L10N = True |
||||
USE_TZ = True |
||||
|
||||
CORS_ORIGIN_ALLOW_ALL = True |
||||
|
||||
# Static files (CSS, JavaScript, Images) |
||||
# https://docs.djangoproject.com/en/2.0/howto/static-files/ |
||||
|
||||
STATIC_URL = '/static/' |
||||
STATIC_ROOT = os.path.join(BASE_DIR, 'public', 'static') |
||||
|
||||
|
||||
|
||||
# django restframework |
||||
|
||||
REST_FRAMEWORK = { |
||||
'DEFAULT_AUTHENTICATION_CLASSES': ( |
||||
'rest_framework.authentication.SessionAuthentication', |
||||
'rest_framework_jwt.authentication.JSONWebTokenAuthentication', |
||||
), |
||||
'DEFAULT_RENDERER_CLASSES': ( |
||||
# 'rest_framework.renderers.YAMLRenderer', |
||||
'rest_framework.renderers.JSONRenderer', |
||||
# 'rest_framework.renderers.BrowsableAPIRenderer', |
||||
), |
||||
'DEFAULT_PERMISSION_CLASSES': ( |
||||
'rest_framework.permissions.IsAuthenticatedOrReadOnly', |
||||
), |
||||
'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.DjangoFilterBackend',), |
||||
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination', |
||||
'PAGE_SIZE': 15, |
||||
'DEFAULT_THROTTLE_CLASSES': ( |
||||
'rest_framework.throttling.AnonRateThrottle', |
||||
'rest_framework.throttling.UserRateThrottle' |
||||
), |
||||
'DEFAULT_THROTTLE_RATES': { |
||||
'anon': '35/minute', |
||||
'user': '500/minute' |
||||
}, |
||||
'DEFAULT_PARSER_CLASSES': ( |
||||
'rest_framework.parsers.JSONParser', |
||||
# 'rest_framework.parsers.FormParser', |
||||
# 'rest_framework.parsers.MultiPartParser', |
||||
) |
||||
} |
||||
|
||||
JWT_AUTH = { |
||||
'JWT_ENCODE_HANDLER': |
||||
'rest_framework_jwt.utils.jwt_encode_handler', |
||||
|
||||
'JWT_DECODE_HANDLER': |
||||
'rest_framework_jwt.utils.jwt_decode_handler', |
||||
|
||||
'JWT_PAYLOAD_HANDLER': |
||||
'rest_framework_jwt.utils.jwt_payload_handler', |
||||
|
||||
'JWT_PAYLOAD_GET_USER_ID_HANDLER': |
||||
'rest_framework_jwt.utils.jwt_get_user_id_from_payload_handler', |
||||
|
||||
'JWT_RESPONSE_PAYLOAD_HANDLER': |
||||
'rest_framework_jwt.utils.jwt_response_payload_handler', |
||||
|
||||
'JWT_SECRET_KEY': SECRET_KEY, |
||||
'JWT_ALGORITHM': 'HS256', |
||||
'JWT_VERIFY': True, |
||||
'JWT_VERIFY_EXPIRATION': True, |
||||
'JWT_LEEWAY': 0, |
||||
|
||||
'JWT_EXPIRATION_DELTA': timedelta(days=14), |
||||
'JWT_AUDIENCE': None, |
||||
'JWT_ISSUER': None, |
||||
|
||||
'JWT_ALLOW_REFRESH': True, |
||||
'JWT_REFRESH_EXPIRATION_DELTA': timedelta(days=360), |
||||
'JWT_AUTH_HEADER_PREFIX': 'Bearer', # default: 'JWT' |
||||
} |
||||
|
||||
|
||||
if os.path.isfile(os.path.join(BASE_DIR, 'settings_local.py')): |
||||
from settings_local import * |
@ -0,0 +1,21 @@
|
||||
"""ismp URL Configuration |
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see: |
||||
https://docs.djangoproject.com/en/2.0/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), |
||||
] |
@ -0,0 +1,16 @@
|
||||
""" |
||||
WSGI config for ismp 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.0/howto/deployment/wsgi/ |
||||
""" |
||||
|
||||
import os |
||||
|
||||
from django.core.wsgi import get_wsgi_application |
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ismp.settings") |
||||
|
||||
application = get_wsgi_application() |
@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env python |
||||
import os |
||||
import sys |
||||
|
||||
if __name__ == "__main__": |
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ismp.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) |
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin |
||||
|
||||
# Register your models here. |
@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig |
||||
|
||||
|
||||
class PeopleConfig(AppConfig): |
||||
name = 'people' |
@ -0,0 +1,56 @@
|
||||
# Generated by Django 2.0.7 on 2018-07-24 17:15 |
||||
|
||||
from django.conf import settings |
||||
import django.contrib.auth.models |
||||
import django.contrib.auth.validators |
||||
from django.db import migrations, models |
||||
import django.utils.timezone |
||||
|
||||
|
||||
class Migration(migrations.Migration): |
||||
|
||||
initial = True |
||||
|
||||
dependencies = [ |
||||
('auth', '0009_alter_user_last_name_max_length'), |
||||
] |
||||
|
||||
operations = [ |
||||
migrations.CreateModel( |
||||
name='User', |
||||
fields=[ |
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
||||
('password', models.CharField(max_length=128, verbose_name='password')), |
||||
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), |
||||
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), |
||||
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')), |
||||
('first_name', models.CharField(blank=True, max_length=30, verbose_name='first name')), |
||||
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')), |
||||
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')), |
||||
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')), |
||||
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')), |
||||
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')), |
||||
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')), |
||||
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')), |
||||
], |
||||
options={ |
||||
'verbose_name': 'user', |
||||
'verbose_name_plural': 'users', |
||||
'abstract': False, |
||||
}, |
||||
managers=[ |
||||
('objects', django.contrib.auth.models.UserManager()), |
||||
], |
||||
), |
||||
migrations.CreateModel( |
||||
name='Organization', |
||||
fields=[ |
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
||||
('name', models.CharField(max_length=200, verbose_name='Organization Name')), |
||||
('users', models.ManyToManyField(to=settings.AUTH_USER_MODEL)), |
||||
], |
||||
options={ |
||||
'verbose_name_plural': 'Organizations', |
||||
}, |
||||
), |
||||
] |
@ -0,0 +1,34 @@
|
||||
from django.db.models import Model, CharField, ManyToManyField |
||||
from django.contrib.auth.models import AbstractUser |
||||
|
||||
|
||||
class User(AbstractUser): |
||||
"""User |
||||
|
||||
I don't know why I make it people.User though, but I do it anyway, |
||||
easier access maybe? |
||||
""" |
||||
|
||||
def __str__(self): |
||||
return self.username |
||||
|
||||
@property |
||||
def organization(self): |
||||
try: |
||||
return self.organization_set.all()[0] |
||||
except: |
||||
return None |
||||
|
||||
|
||||
class Organization(Model): |
||||
"""Organization to hold all models together |
||||
""" |
||||
name = CharField('Organization Name', max_length=200) |
||||
users = ManyToManyField('User') |
||||
|
||||
|
||||
class Meta: |
||||
verbose_name_plural = "Organizations" |
||||
|
||||
def __str__(self): |
||||
return self.name |
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase |
||||
|
||||
# Create your tests here. |
@ -0,0 +1,3 @@
|
||||
from django.shortcuts import render |
||||
|
||||
# Create your views here. |
@ -0,0 +1,8 @@
|
||||
django>2 |
||||
psycopg2-binary |
||||
djangorestframework |
||||
djangorestframework-jwt |
||||
django-cors-headers |
||||
django-extra-fields |
||||
django-filter |
||||
raven |
@ -0,0 +1,10 @@
|
||||
django>2 |
||||
psycopg2-binary |
||||
djangorestframework |
||||
djangorestframework-jwt |
||||
django-cors-headers |
||||
django-extra-fields |
||||
django-filter |
||||
raven |
||||
|
||||
gunicorn |
Loading…
Reference in new issue