Browse Source

Project initialization

master
alfred 3 months ago
commit
33648832b7

+ 11
- 0
.gitignore View File

@@ -0,0 +1,11 @@
1
+*.pyc
2
+.DS_Store
3
+env
4
+venv
5
+.idea/
6
+**.css.map
7
+node_modules
8
+*.sqlite3
9
+*.pyc
10
+**/__pycache__/*
11
+**/.sass-cache/*

+ 0
- 0
README.md View File


+ 0
- 0
apps/__init__.py View File


+ 0
- 0
apps/base/__init__.py View File


+ 3
- 0
apps/base/admin.py View File

@@ -0,0 +1,3 @@
1
+from django.contrib import admin
2
+
3
+# Register your models here.

+ 5
- 0
apps/base/apps.py View File

@@ -0,0 +1,5 @@
1
+from django.apps import AppConfig
2
+
3
+
4
+class BaseConfig(AppConfig):
5
+    name = 'base'

+ 0
- 0
apps/base/management/__init__.py View File


+ 0
- 0
apps/base/management/commands/__init__.py View File


+ 35
- 0
apps/base/management/commands/install.py View File

@@ -0,0 +1,35 @@
1
+#!/usr/bin/env python
2
+# -*- coding: utf-8 -*-
3
+
4
+from django.core.management.base import BaseCommand
5
+from django.core.management.commands.makemigrations import Command as Makemigrations
6
+from django.core.management.commands.migrate import Command as Migrate
7
+
8
+
9
+class Command(BaseCommand):
10
+    def create_database(self):
11
+        import psycopg2
12
+        from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT
13
+        import warnings
14
+        from django.conf import settings
15
+
16
+        db_config = settings.DATABASES['default']
17
+        try:
18
+            con = psycopg2.connect(
19
+                dbname='postgres',
20
+                user=db_config['USER'],
21
+                host=db_config['HOST'],
22
+                password=db_config['PASSWORD']
23
+            )
24
+            con.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
25
+            cur = con.cursor()
26
+            cur.execute(f"CREATE DATABASE {db_config['NAME']}")
27
+        except Exception as e:
28
+            warnings.warn(f"Database {db_config['NAME']} already exists", Warning)
29
+
30
+    def handle(self, *args, **options):
31
+        import sys
32
+
33
+        self.create_database()
34
+        Makemigrations().run_from_argv(sys.argv)
35
+        Migrate().run_from_argv(sys.argv)

+ 0
- 0
apps/base/migrations/__init__.py View File


+ 3
- 0
apps/base/models.py View File

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

+ 3
- 0
apps/base/tests.py View File

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

+ 3
- 0
apps/base/views.py View File

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

+ 0
- 0
apps/projects/__init__.py View File


+ 3
- 0
apps/projects/admin.py View File

@@ -0,0 +1,3 @@
1
+from django.contrib import admin
2
+
3
+# Register your models here.

+ 5
- 0
apps/projects/apps.py View File

@@ -0,0 +1,5 @@
1
+from django.apps import AppConfig
2
+
3
+
4
+class ProjectsConfig(AppConfig):
5
+    name = 'projects'

+ 0
- 0
apps/projects/migrations/__init__.py View File


+ 3
- 0
apps/projects/models.py View File

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

+ 3
- 0
apps/projects/tests.py View File

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

+ 3
- 0
apps/projects/views.py View File

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

+ 0
- 0
djawth/__init__.py View File


+ 16
- 0
djawth/asgi.py View File

@@ -0,0 +1,16 @@
1
+"""
2
+ASGI config for djawth project.
3
+
4
+It exposes the ASGI callable as a module-level variable named ``application``.
5
+
6
+For more information on this file, see
7
+https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/
8
+"""
9
+
10
+import os
11
+
12
+from django.core.asgi import get_asgi_application
13
+
14
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djawth.settings')
15
+
16
+application = get_asgi_application()

+ 1
- 0
djawth/settings/__init__.py View File

@@ -0,0 +1 @@
1
+from .dev import *

+ 126
- 0
djawth/settings/dev.py View File

@@ -0,0 +1,126 @@
1
+"""
2
+Django settings for djawth project.
3
+
4
+Generated by 'django-admin startproject' using Django 3.0.1.
5
+
6
+For more information on this file, see
7
+https://docs.djangoproject.com/en/3.0/topics/settings/
8
+
9
+For the full list of settings and their values, see
10
+https://docs.djangoproject.com/en/3.0/ref/settings/
11
+"""
12
+
13
+import os
14
+import sys
15
+
16
+# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
17
+BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
18
+sys.path.insert(0, os.path.abspath(os.path.join(BASE_DIR, './apps')))
19
+
20
+# Quick-start development settings - unsuitable for production
21
+# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
22
+
23
+# SECURITY WARNING: keep the secret key used in production secret!
24
+SECRET_KEY = '%hy=^u=8z#r+n^((zilqsf*awmv8j@b6h1lfznddq6goxn5*r8'
25
+
26
+# SECURITY WARNING: don't run with debug turned on in production!
27
+DEBUG = True
28
+
29
+ALLOWED_HOSTS = []
30
+
31
+
32
+# Application definition
33
+
34
+INSTALLED_APPS = [
35
+    'django.contrib.auth',
36
+    'django.contrib.contenttypes',
37
+    'django.contrib.sessions',
38
+    'django.contrib.messages',
39
+    'django.contrib.staticfiles',
40
+    'apps.base',
41
+    'apps.projects'
42
+]
43
+
44
+MIDDLEWARE = [
45
+    'django.middleware.security.SecurityMiddleware',
46
+    'django.contrib.sessions.middleware.SessionMiddleware',
47
+    'django.middleware.common.CommonMiddleware',
48
+    'django.middleware.csrf.CsrfViewMiddleware',
49
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
50
+    'django.contrib.messages.middleware.MessageMiddleware',
51
+    'django.middleware.clickjacking.XFrameOptionsMiddleware',
52
+]
53
+
54
+ROOT_URLCONF = 'djawth.urls'
55
+
56
+TEMPLATES = [
57
+    {
58
+        'BACKEND': 'django.template.backends.django.DjangoTemplates',
59
+        'DIRS': [],
60
+        'APP_DIRS': True,
61
+        'OPTIONS': {
62
+            'context_processors': [
63
+                'django.template.context_processors.debug',
64
+                'django.template.context_processors.request',
65
+                'django.contrib.auth.context_processors.auth',
66
+                'django.contrib.messages.context_processors.messages',
67
+            ],
68
+        },
69
+    },
70
+]
71
+
72
+WSGI_APPLICATION = 'djawth.wsgi.application'
73
+
74
+
75
+# Database
76
+# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
77
+
78
+DATABASES = {
79
+    'default': {
80
+        'ENGINE': 'django.db.backends.postgresql',
81
+        'NAME': 'trackmanager',
82
+        'USER': 'postgres',
83
+        'PASSWORD': 'mysecretpassword',
84
+        'HOST': os.environ.get('DB_HOST', '127.0.0.1'),
85
+    }
86
+}
87
+
88
+
89
+# Password validation
90
+# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
91
+
92
+AUTH_PASSWORD_VALIDATORS = [
93
+    {
94
+        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
95
+    },
96
+    {
97
+        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
98
+    },
99
+    {
100
+        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
101
+    },
102
+    {
103
+        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
104
+    },
105
+]
106
+
107
+
108
+# Internationalization
109
+# https://docs.djangoproject.com/en/3.0/topics/i18n/
110
+
111
+LANGUAGE_CODE = 'en-us'
112
+
113
+TIME_ZONE = 'UTC'
114
+
115
+USE_I18N = True
116
+
117
+USE_L10N = True
118
+
119
+USE_TZ = True
120
+
121
+
122
+# Static files (CSS, JavaScript, Images)
123
+# https://docs.djangoproject.com/en/3.0/howto/static-files/
124
+
125
+STATIC_URL = '/static/'
126
+

+ 21
- 0
djawth/urls.py View File

@@ -0,0 +1,21 @@
1
+"""djawth URL Configuration
2
+
3
+The `urlpatterns` list routes URLs to views. For more information please see:
4
+    https://docs.djangoproject.com/en/3.0/topics/http/urls/
5
+Examples:
6
+Function views
7
+    1. Add an import:  from my_app import views
8
+    2. Add a URL to urlpatterns:  path('', views.home, name='home')
9
+Class-based views
10
+    1. Add an import:  from other_app.views import Home
11
+    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
12
+Including another URLconf
13
+    1. Import the include() function: from django.urls import include, path
14
+    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
15
+"""
16
+from django.contrib import admin
17
+from django.urls import path
18
+
19
+urlpatterns = [
20
+
21
+]

+ 16
- 0
djawth/wsgi.py View File

@@ -0,0 +1,16 @@
1
+"""
2
+WSGI config for djawth project.
3
+
4
+It exposes the WSGI callable as a module-level variable named ``application``.
5
+
6
+For more information on this file, see
7
+https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/
8
+"""
9
+
10
+import os
11
+
12
+from django.core.wsgi import get_wsgi_application
13
+
14
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djawth.settings')
15
+
16
+application = get_wsgi_application()

+ 21
- 0
docker/Dockerfile View File

@@ -0,0 +1,21 @@
1
+FROM python:3.6.8-alpine3.8
2
+ENV PYTHONUNBUFFERED 1
3
+
4
+ARG http_proxy
5
+ENV https_proxy=$http_proxy
6
+ENV http_proxy=$http_proxy
7
+ENV HTTP_PROXY=$http_proxy
8
+ENV HTTPS_PROXY=$http_proxy
9
+
10
+RUN apk update
11
+RUN apk add --no-cache python3-dev libffi-dev postgresql-libs postgresql-dev build-base
12
+
13
+RUN mkdir -p /srv/app
14
+WORKDIR /srv
15
+
16
+RUN pip install --upgrade pip
17
+COPY requirements.txt /srv/requirements.txt
18
+RUN pip install -r requirements.txt
19
+COPY ./ /srv/
20
+
21
+CMD python manage.py runserver 0.0.0.0:8000

+ 26
- 0
docker/docker-compose.yml View File

@@ -0,0 +1,26 @@
1
+version: "3.3"
2
+
3
+services:
4
+  trackmanager:
5
+    build:
6
+      context: ..
7
+      dockerfile: docker/Dockerfile.app
8
+    ports:
9
+      - 8000:8000
10
+    container_name: trackmanager
11
+    depends_on:
12
+      - postgres
13
+    environment:
14
+      - DB_HOST=postgres
15
+    volumes:
16
+      - ..:/srv
17
+    command: python manage.py runserver 0.0.0.0:8000
18
+  postgres:
19
+    container_name: postgres
20
+    image: postgres:10.6
21
+    volumes:
22
+      - $PG_DATAPATH:/var/lib/postgresql/data/
23
+    environment:
24
+      - POSTGRES_PASSWORD=mysecretpassword
25
+    ports:
26
+      - 5432:5432

+ 21
- 0
manage.py View File

@@ -0,0 +1,21 @@
1
+#!/usr/bin/env python
2
+"""Django's command-line utility for administrative tasks."""
3
+import os
4
+import sys
5
+
6
+
7
+def main():
8
+    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djawth.settings')
9
+    try:
10
+        from django.core.management import execute_from_command_line
11
+    except ImportError as exc:
12
+        raise ImportError(
13
+            "Couldn't import Django. Are you sure it's installed and "
14
+            "available on your PYTHONPATH environment variable? Did you "
15
+            "forget to activate a virtual environment?"
16
+        ) from exc
17
+    execute_from_command_line(sys.argv)
18
+
19
+
20
+if __name__ == '__main__':
21
+    main()

+ 5
- 0
requirements.txt View File

@@ -0,0 +1,5 @@
1
+asgiref==3.2.3
2
+Django==3.0.1
3
+psycopg2-binary==2.8.4
4
+pytz==2019.3
5
+sqlparse==0.3.0

Loading…
Cancel
Save