diff --git a/.gitignore b/.gitignore index e61bca2..fbefd29 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +config.py +data/ + # ---> Python # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..452055c --- /dev/null +++ b/.gitmodules @@ -0,0 +1,18 @@ +[submodule "fstools"] + path = fstools + url = https://git.mount-mockery.de/pylib/fstools.git +[submodule "geo"] + path = geo + url = https://git.mount-mockery.de/pylib/geo.git +[submodule "mycreole"] + path = mycreole + url = https://git.mount-mockery.de/django_lib/mycreole.git +[submodule "pygal"] + path = pygal + url = https://git.mount-mockery.de/django_lib/pygal.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/.project b/.project new file mode 100644 index 0000000..00bed9c --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + django_pygal + + + + + + org.python.pydev.PyDevBuilder + + + + + + org.python.pydev.pythonNature + + diff --git a/.pydevproject b/.pydevproject new file mode 100644 index 0000000..ad74947 --- /dev/null +++ b/.pydevproject @@ -0,0 +1,8 @@ + + + +/${PROJECT_DIR_NAME} + +python interpreter +Default + 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/example_data/building_scenery/IMG_20160824_113401.jpg b/data/example_data/building_scenery/IMG_20160824_113401.jpg new file mode 100644 index 0000000..3cf256e Binary files /dev/null and b/data/example_data/building_scenery/IMG_20160824_113401.jpg differ diff --git a/data/example_data/building_scenery/IMG_20160901_162221.jpg b/data/example_data/building_scenery/IMG_20160901_162221.jpg new file mode 100644 index 0000000..3c79457 Binary files /dev/null and b/data/example_data/building_scenery/IMG_20160901_162221.jpg differ diff --git a/data/example_data/building_scenery/IMG_20180104_213600.jpg b/data/example_data/building_scenery/IMG_20180104_213600.jpg new file mode 100644 index 0000000..1eec0a9 Binary files /dev/null and b/data/example_data/building_scenery/IMG_20180104_213600.jpg differ diff --git a/data/example_data/natural_scenery/20141226_135921.jpg b/data/example_data/natural_scenery/20141226_135921.jpg new file mode 100644 index 0000000..f5812d3 Binary files /dev/null and b/data/example_data/natural_scenery/20141226_135921.jpg differ diff --git a/data/example_data/natural_scenery/DSC01058.JPG b/data/example_data/natural_scenery/DSC01058.JPG new file mode 100644 index 0000000..cedb44c Binary files /dev/null and b/data/example_data/natural_scenery/DSC01058.JPG differ diff --git a/data/example_data/natural_scenery/DSC_1150.JPG b/data/example_data/natural_scenery/DSC_1150.JPG new file mode 100644 index 0000000..2f26e0a Binary files /dev/null and b/data/example_data/natural_scenery/DSC_1150.JPG differ diff --git a/data/example_data/natural_scenery/DSC_1163.JPG b/data/example_data/natural_scenery/DSC_1163.JPG new file mode 100644 index 0000000..4b50335 Binary files /dev/null and b/data/example_data/natural_scenery/DSC_1163.JPG differ diff --git a/data/example_data/natural_scenery/DSC_1167.JPG b/data/example_data/natural_scenery/DSC_1167.JPG new file mode 100644 index 0000000..e34cc29 Binary files /dev/null and b/data/example_data/natural_scenery/DSC_1167.JPG differ diff --git a/data/example_data/natural_scenery/DSC_1864.JPG b/data/example_data/natural_scenery/DSC_1864.JPG new file mode 100644 index 0000000..461d087 Binary files /dev/null and b/data/example_data/natural_scenery/DSC_1864.JPG differ diff --git a/data/example_data/natural_scenery/DSC_2573.JPG b/data/example_data/natural_scenery/DSC_2573.JPG new file mode 100644 index 0000000..7833e4f Binary files /dev/null and b/data/example_data/natural_scenery/DSC_2573.JPG differ diff --git a/data/media/theme/logo.png b/data/media/theme/logo.png new file mode 100644 index 0000000..ca6e164 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/geo b/geo new file mode 160000 index 0000000..f59b19e --- /dev/null +++ b/geo @@ -0,0 +1 @@ +Subproject commit f59b19ed1fd2a64735ca477fdb1fba24681e8879 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..3f0d13a --- /dev/null +++ b/main/settings.py @@ -0,0 +1,253 @@ +""" +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, ITEM_ROOT, THUMBNAIL_SIZES, WEBNAIL_SIZES +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 = False + +ALLOWED_HOSTS = config.get('ALLOWED_HOSTS', []) + + +# Application definition +# +INSTALLED_APPS = [ + 'pygal.apps.PygalConfig', + 'themes.apps.ThemesConfig', + 'users.apps.UsersConfig', + # + '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.locale.LocaleMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', + '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, 'pygal', '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/' + + +# Session parameters +# + +SESSION_KEY_THUMBNAIL_SIZE = 'thumbnail_size' +SESSION_KEY_WEBNAIL_SIZE = 'webnail_size' +PERSISTENT_SESSION_VARIABLES = [SESSION_KEY_THUMBNAIL_SIZE, SESSION_KEY_WEBNAIL_SIZE] + + +# Logging Configuration +# +default_handler = ['console_long'] 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, + }, + 'APP': { + 'handlers': default_handler, + 'level': 'INFO', + 'propagate': False, + }, + 'CACHING': { + 'handlers': default_handler, + 'level': 'INFO', + 'propagate': False, + }, + 'WHOOSH': { + 'handlers': default_handler, + 'level': 'INFO', + 'propagate': False, + }, + 'FSTOOLS': { + 'handlers': default_handler, + 'level': 'INFO', + 'propagate': False, + }, + 'GEO': { + 'handlers': default_handler, + 'level': 'INFO', + 'propagate': False, + }, + }, +} + + +# Other Configuration issues +# + +DATA_UPLOAD_MAX_NUMBER_FIELDS = 30000 + +LOGIN_URL = 'users-login' + +XNAIL_ROOT = os.path.join(BASE_DIR, 'data', 'xnails') +TEMP_ROOT = os.path.join(BASE_DIR, 'data', 'temp') + + +# App Configuration +# +DEFAULT_THEME = config.get('DEFAULT_THEME', 'clear-red') +ITEM_ROOT = config.get('ITEM_ROOT', os.path.join(BASE_DIR, 'data', 'example_data')) +THUMBNAIL_SIZES = config.get('THUMBNAIL_SIZES', [137, 175, 250]) +WEBNAIL_SIZES = config.get('WEBNAIL_SIZES', [450, 1100, 1750]) diff --git a/main/urls.py b/main/urls.py new file mode 100644 index 0000000..520b18c --- /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 +from django.urls.base import reverse +import pygal + +urlpatterns = [ + path('admin/', admin.site.urls), + path('pygal/', include('pygal.urls')), + path('users/', include('users.urls')), + path('', lambda request: redirect(reverse('pygal-responses', kwargs={'responsetype': pygal.RESP_TYPE_USERVIEW, 'datatype': pygal.DATA_TYPE_ITEM}), 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/pygal b/pygal new file mode 160000 index 0000000..d73c736 --- /dev/null +++ b/pygal @@ -0,0 +1 @@ +Subproject commit d73c7363b7340163c02277750258a46ea2a00d20 diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..44742c2 --- /dev/null +++ b/readme.txt @@ -0,0 +1,18 @@ +1. Setupt venev + * virtualenv -p /usr/bin/python3 pygal-venv + * ln -s pygal-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. python manage.py migrate +3. python manage.py createsuperuser +4. Set SECRET:KEY in config.py +5. Set ITEM_ROOT in config.py to your item target path, otherwise the example_data is used +6. python manage.py collectstatic +7. chgrp www-data . && chmod 770 . +8. chgrp www-data db.sqlite3 && chmod 664 db.sqlite3 +9. chgrp www-data -R data +9.1. find data -type d -exec chmod 775 "{}" \; +9.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..1969324 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +Django>=2.0.5,<3.0 +Pillow>=5.4.1 +python-creole>=1.0.0 +Whoosh>=2.4.0 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