From aa28796afe2cf1275143beeb7c9d0fc7206bfec5 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Thu, 10 Oct 2019 09:18:34 +0200 Subject: [PATCH] Initial commit. Create app skeleton. --- .env.example | 3 + .gitignore | 104 ++++++++++++++++++++++++ CHANGELOG.md | 8 ++ README.md | 43 ++++++++++ manage.py | 21 +++++ musician/__init__.py | 0 musician/apps.py | 5 ++ musician/migrations/__init__.py | 0 musician/tests.py | 3 + musician/views.py | 3 + requirements.txt | 5 ++ setup.py | 39 +++++++++ userpanel/__init__.py | 0 userpanel/settings.py | 136 ++++++++++++++++++++++++++++++++ userpanel/urls.py | 29 +++++++ userpanel/wsgi.py | 16 ++++ 16 files changed, 415 insertions(+) create mode 100644 .env.example create mode 100644 .gitignore create mode 100644 CHANGELOG.md create mode 100644 README.md create mode 100755 manage.py create mode 100644 musician/__init__.py create mode 100644 musician/apps.py create mode 100644 musician/migrations/__init__.py create mode 100644 musician/tests.py create mode 100644 musician/views.py create mode 100644 requirements.txt create mode 100644 setup.py create mode 100644 userpanel/__init__.py create mode 100644 userpanel/settings.py create mode 100644 userpanel/urls.py create mode 100644 userpanel/wsgi.py diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..41acf39 --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +SECRET_KEY='$omeR@nd0mSecr3tKeyWith4V3ryL0ng$tring!?' +DEBUG=True +ALLOWED_HOSTS=.localhost,127.0.0.1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..894a44c --- /dev/null +++ b/.gitignore @@ -0,0 +1,104 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..505775f --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,8 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) +and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). + +## master + diff --git a/README.md b/README.md new file mode 100644 index 0000000..4b2fdc4 --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# django musician +Python code is written following [PEP 8](https://www.python.org/dev/peps/pep-0008/) sytle guide and it is based on [Django framework](https://djangoproject.com). + +## How do I get set up? + +1. Install Python and its packet manager (pip) +```bash +# on a Debian based environment: +apt=( + git + python3-pip + python3-setuptools +) +sudo apt-get install --no-install-recommends -y ${apt[@]} + +``` + +2. Install virtualenv (isolate app python related requirements) +```bash +sudo pip3 install virtualenv +``` + +3. Clone this repository +```bash +git clone https://github.pangea.org/slamora/django-musician.git +``` + +4. Prepare env and install requirements +```bash +cd django-musician +virtualenv env +source env/bin/activate +pip3 install -r requirements.txt +``` +5. Start django devel server (check everything is ok) +```bash +python manage.py migrate +python manage.py runserver +``` + +6. Open [http://127.0.0.1:8000/](http://127.0.0.1:8000/) in your browser. + +7. If everything works, follow [Django deployment instructions](https://docs.djangoproject.com/en/2.2/howto/deployment/). diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..79ff65e --- /dev/null +++ b/manage.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'userpanel.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) + + +if __name__ == '__main__': + main() diff --git a/musician/__init__.py b/musician/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/musician/apps.py b/musician/apps.py new file mode 100644 index 0000000..67c22b3 --- /dev/null +++ b/musician/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class MusicianConfig(AppConfig): + name = 'musician' diff --git a/musician/migrations/__init__.py b/musician/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/musician/tests.py b/musician/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/musician/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/musician/views.py b/musician/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/musician/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..def8cfc --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +django==2.2 +python-decouple==3.1 +django-extensions +dj_database_url==0.5.0 + diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..52382e2 --- /dev/null +++ b/setup.py @@ -0,0 +1,39 @@ +import os + +from setuptools import find_packages, setup + + +# allow setup.py to be run from any path +os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir))) + + +setup( + name="django-musician", + version="0.1", + url='https://gitlab.pangea.org/slamora/django-musician.git', + author='Santiago Lamora', + author_email='santiago@ribaguifi.com', + description=('Client of the django-orchestra web hosting control panel ' + 'for the final users.'), + #long_description='TODO', + #license = 'AGPLv3 License', + packages=find_packages(), + include_package_data = True, + zip_safe=False, + classifiers = [ + 'Development Status :: 2 - Pre-Alpha', + 'Environment :: Web Environment', + 'Framework :: Django', + 'Framework :: Django :: 2.1', + 'Operating System :: OS Independent', + 'Programming Language :: Python', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3 :: Only', + 'Topic :: Internet :: WWW/HTTP', + 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', + 'Topic :: Internet :: WWW/HTTP :: WSGI', + 'Topic :: Internet :: WWW/HTTP :: WSGI :: Application', + ], +) diff --git a/userpanel/__init__.py b/userpanel/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/userpanel/settings.py b/userpanel/settings.py new file mode 100644 index 0000000..5c0c8cc --- /dev/null +++ b/userpanel/settings.py @@ -0,0 +1,136 @@ +""" +Django settings for userpanel project. + +Generated by 'django-admin startproject' using Django 2.2. + +For more information on this file, see +https://docs.djangoproject.com/en/2.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.2/ref/settings/ +""" + +import os + +from decouple import config, Csv +from dj_database_url import parse as db_url +# 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.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = config('SECRET_KEY') + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = config('DEBUG', default=False, cast=bool) + +# Definition of Settings for send emails +DEFAULT_FROM_EMAIL = config('DEFAULT_FROM_EMAIL', default='webmaster@localhost') + +EMAIL_HOST = config('EMAIL_HOST', default='localhost') + +EMAIL_HOST_USER = config('EMAIL_HOST_USER', default='') + +EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD', default='') + +EMAIL_PORT = config('EMAIL_PORT', default=25, cast=int) + +ALLOWED_HOSTS = config('ALLOWED_HOSTS', default=[], cast=Csv()) + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'django_extensions', +] + +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 = 'userpanel.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 = 'userpanel.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.2/ref/settings/#databases + +DATABASES = { + 'default': config( + 'DATABASE_URL', + default='sqlite:///' + os.path.join(BASE_DIR, 'db.sqlite3'), + cast=db_url + ) +} + + +# Password validation +# https://docs.djangoproject.com/en/2.2/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.2/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.2/howto/static-files/ + +STATIC_URL = '/static/' + +STATIC_ROOT = config('STATIC_ROOT') diff --git a/userpanel/urls.py b/userpanel/urls.py new file mode 100644 index 0000000..6081e5b --- /dev/null +++ b/userpanel/urls.py @@ -0,0 +1,29 @@ +"""userpanel URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.2/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 decouple import config +from django.conf import settings +from django.conf.urls.static import static +from django.contrib import admin +from django.urls import include, path + + +urlpatterns = [ + path('admin/', admin.site.urls), +] + +DEVELOPMENT = config('DEVELOPMENT', default=False, cast=bool) +if DEVELOPMENT: + urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) diff --git a/userpanel/wsgi.py b/userpanel/wsgi.py new file mode 100644 index 0000000..35b88b0 --- /dev/null +++ b/userpanel/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for userpanel 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.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'userpanel.settings') + +application = get_wsgi_application()