diff --git a/.gitignore b/.gitignore index e61bca2..f0ef830 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +config.py + # ---> Python # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..b69c4a1 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,15 @@ +[submodule "fstools"] + path = fstools + url = https://git.mount-mockery.de/pylib/fstools.git +[submodule "mycreole"] + path = mycreole + url = https://git.mount-mockery.de/django_lib/mycreole.git +[submodule "patt"] + path = patt + url = https://git.mount-mockery.de/django_lib/patt.git +[submodule "themes"] + path = themes + url = https://git.mount-mockery.de/django_lib/themes.git +[submodule "users"] + path = users + url = https://git.mount-mockery.de/django_lib/users.git diff --git a/activate b/activate new file mode 120000 index 0000000..9308d33 --- /dev/null +++ b/activate @@ -0,0 +1 @@ +venv/bin/activate \ No newline at end of file diff --git a/data/media/theme/logo.png b/data/media/theme/logo.png new file mode 100644 index 0000000..39ff101 Binary files /dev/null and b/data/media/theme/logo.png differ diff --git a/fstools b/fstools new file mode 160000 index 0000000..ada1f74 --- /dev/null +++ b/fstools @@ -0,0 +1 @@ +Subproject commit ada1f74d4c05a35bad9d2b258f3d0b4ccdfd1653 diff --git a/main/__init__.py b/main/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/main/settings.py b/main/settings.py new file mode 100644 index 0000000..5908540 --- /dev/null +++ b/main/settings.py @@ -0,0 +1,247 @@ +""" +Django settings for this project. + +Generated by 'django-admin startproject' using Django 2.2.3. + +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/ +""" + +try: + from config import config + # required keys: SECRET_KEY + # optional keys: ALLOWED_HOSTS, DEFAULT_THEME +except ImportError: + config = {} +import os +import random + + +# 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! +# +try: + SECRET_KEY = config['SECRET_KEY'] +except KeyError: + chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)' + s_key = ''.join([random.choice(chars) for n in range(50)]) + secret_key_warning = "You need to create a config.py file including a variable config which is a dict with at least a SECRET_KEY definition (e.g.: %s)." % repr(s_key) + raise KeyError(secret_key_warning) +# SECURITY WARNING: don't run with debug turned on in production! +# +DEBUG = True + +ALLOWED_HOSTS = config.get('ALLOWED_HOSTS', []) + + +# Application definition +# +INSTALLED_APPS = [ + 'patt.apps.PattConfig', + 'themes.apps.ThemesConfig', + 'users.apps.UsersConfig', + 'mycreole.apps.MycreoleConfig', + # + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'simple_history', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.locale.LocaleMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'simple_history.middleware.HistoryRequestMiddleware', + 'users.middleware.SettingsMiddleware', +] + +ROOT_URLCONF = 'main.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 = 'main.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.2/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.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', + }, +] + +# Search Engine +# +WHOOSH_PATH = os.path.join(BASE_DIR, 'data', 'whoosh_index') + + +# Internationalization +# https://docs.djangoproject.com/en/2.2/topics/i18n/ +# +LANGUAGE_CODE = 'en-us' +LANGUAGES = [ + ('en', 'English'), + ('de', 'Deutsch'), +] + +TIME_ZONE = 'UTC' + +USE_I18N = True +LOCALE_PATHS = [ + os.path.join(BASE_DIR, 'themes', 'locale'), + os.path.join(BASE_DIR, 'users', 'locale'), + os.path.join(BASE_DIR, 'patt', 'locale'), +] + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.2/howto/static-files/ +# +STATIC_ROOT = os.path.join(BASE_DIR, 'data', 'static') +STATIC_URL = '/static/' + +MEDIA_ROOT = os.path.join(BASE_DIR, 'data', 'media') +MEDIA_URL = '/media/' + +MYCREOLE_ROOT = os.path.join(BASE_DIR, 'data', 'mycreole') +MYCREOLE_ATTACHMENT_ACCESS = { + 'read': 'patt.access.read_attachment', + 'modify': 'patt.access.modify_attachment', +} +MYCREOLE_EXT_FILTERS = [ + 'patt.creole.task_link_filter', + 'patt.creole.tasklist_link_filter', +] + +# Session parameters +# +PERSISTENT_SESSION_VARIABLES = [] + + +# Logging Configuration +# +debug_handler = 'console' +default_handler = [debug_handler] if DEBUG else ['console'] +# +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'formatters': { + 'short': { + 'format': "%(asctime)s \"%(name)s - %(levelname)s - %(message)s\"", + 'datefmt': '[%d/%b/%Y %H:%M:%S]', + }, + 'long': { + 'format': """~~~~(%(levelname)-10s)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +File "%(pathname)s", line %(lineno)d, in %(funcName)s +%(asctime)s: %(name)s - %(message)s +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~""", + }, + }, + 'handlers': { + 'console': { + 'level': 'DEBUG', + 'class': 'logging.StreamHandler', + 'formatter': 'short', + }, + 'console_long': { + 'level': 'DEBUG', + 'class': 'logging.StreamHandler', + 'formatter': 'long', + }, + }, + 'loggers': { + 'AUTH': { + 'handlers': default_handler, + 'level': 'INFO', + 'propagate': False, + }, + 'ACC': { + 'handlers': default_handler, + 'level': 'INFO', + 'propagate': False, + }, + 'APP': { + 'handlers': default_handler, + 'level': 'INFO', + 'propagate': False, + }, + 'WHOOSH': { + 'handlers': default_handler, + 'level': 'INFO', + 'propagate': False, + }, + 'FSTOOLS': { + 'handlers': default_handler, + 'level': 'INFO', + 'propagate': False, + }, + }, +} + + +# Other Configuration issues +# +LOGIN_URL = 'users-login' + +# App Configuration +# +DEFAULT_THEME = config.get('DEFAULT_THEME', 'clear-green') diff --git a/main/urls.py b/main/urls.py new file mode 100644 index 0000000..2fdeb3d --- /dev/null +++ b/main/urls.py @@ -0,0 +1,32 @@ +"""Project 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 django.conf import settings +from django.conf.urls.static import static +from django.contrib import admin +from django.shortcuts import redirect +from django.urls import path, include + + +urlpatterns = [ + path('admin/', admin.site.urls), + path('patt/', include('patt.urls')), + path('users/', include('users.urls')), + path('mycreole/', include('mycreole.urls')), + path('', lambda request: redirect('patt/', permanent=False)), +] + +if settings.DEBUG: + urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/main/wsgi.py b/main/wsgi.py new file mode 100644 index 0000000..fa40526 --- /dev/null +++ b/main/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for this 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', 'main.settings') + +application = get_wsgi_application() diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..063eacc --- /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', 'main.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/mycreole b/mycreole new file mode 160000 index 0000000..dd0edc2 --- /dev/null +++ b/mycreole @@ -0,0 +1 @@ +Subproject commit dd0edc2d56c2c234be32fa76e3bd5b6b4f38a69f diff --git a/patt b/patt new file mode 160000 index 0000000..c834976 --- /dev/null +++ b/patt @@ -0,0 +1 @@ +Subproject commit c834976e79f98f6c59cf6fb33b0f5850b008281b diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..ad78f4c --- /dev/null +++ b/readme.txt @@ -0,0 +1,17 @@ +1. Setupt venev + * virtualenv -p /usr/bin/python3 patt-venv + * ln -s patt-venv/bin/activate + * source activate + * Sometimes upgrades are needed: pip list --outdated | cut -d ' ' -f 1 | xargs pip install $1 --upgrade + * pip install -r requirements.txt +2. Set SECRET:KEY in config.py +3. python manage.py migrate +4. python manage.py createsuperuser +5. python manage.py collectstatic +6. chgrp www-data . && chmod 770 . +7. chgrp www-data db.sqlite3 && chmod 664 db.sqlite3 +8. chgrp www-data -R data +8.1. find data -type d -exec chmod 775 "{}" \; +8.2. find data -type f -exec chmod 664 "{}" \; + +x. Run server by command "python manage.py runserver 0.0.0.0:8000" or add App to apache diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..2637745 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +Django>=2.0.5,<3.0 +Pillow>=5.4.1 +python-creole>=1.0.0 +Whoosh>=2.4.0 +django-simple-history>=2.7.3 diff --git a/themes b/themes new file mode 160000 index 0000000..a24e772 --- /dev/null +++ b/themes @@ -0,0 +1 @@ +Subproject commit a24e772083b27e9ab413d137005dbc9e8325dbc4 diff --git a/users b/users new file mode 160000 index 0000000..277352f --- /dev/null +++ b/users @@ -0,0 +1 @@ +Subproject commit 277352fe9bbf0e67b52bdb19a5ba7fa6281dad6e