-
- {% for message in messages %}
-
- - + {% endif %} - {% block maincontent %} - {% endblock maincontent %} + {% block maincontent %} + {% endblock maincontent %} - -
diff --git a/Readme.md b/Readme.md index 628f094..275787d 100644 --- a/Readme.md +++ b/Readme.md @@ -4,6 +4,12 @@ lostplaces-backend is a django (3.x) based webproject. It once wants to become a The software is currently in early development status, neither scope, datalmodel(s) nor features are finalized yet. Therefore we would not recommend to download or install this piece of software anywhere - except your local django dev server. +## Features +- manage lost places with lots of usefull information +- sensitive information is not accesiable for anonymous (not logged in) users +- user self registration using a voucher system, only people you invite can join your instance +- collaboration, every user can add informations like tags, photos and external links to your place + ## Dependencies Right now it depends on the following non-core Python 3 libraries. These can be installed using the package manager of your distribution or into the venv locally. @@ -14,12 +20,14 @@ Right now it depends on the following non-core Python 3 libraries. These can be * [django-taggit](https://github.com/jazzband/django-taggit) A simpler approach to tagging with Django. -## Development -### Setting up a (pipenv) virtual environment for development +# Installing a development instance +## Clone the repository +`git clone https://git.mowoe.com/reverend/lostplaces-backend.git` +## Setting up a (pipenv) virtual environment for development After having obtained the repository contents (either via .zip download or git clone), you can easily setup a [pipenv](https://docs.pipenv.org/) virtual environment. The repo provides a Pipfile for easy dependency management that does not mess with your system. -``` +```shell $ cd lostplaces-backend $ pipenv install $ pipenv shell @@ -29,8 +37,8 @@ $ pipenv shell (lostplaces-backend) $ lostplaces/manage.py runserver --ipv6 ``` -### Returning to the venv -``` +## Returning to the venv +```shell $ cd lostplaces-backend $ pipenv shell (lostplaces-backend) $ pipenv update # If dependencies changed, or updates available @@ -42,21 +50,42 @@ $ pipenv shell Visit: [admin](http://localhost:8000/admin) for administrative backend or [frontend](http://localhost:8000/) -## Installing lostplaces +# Installing a productive instance -### Install dependencies -Python3, Django3, easy-thumbnails, image, django-widget-tweaks, django-taggit -``` -pip install --user django easy-thumbnails image django-widget-tweaks django-taggit -``` -Or, if you use pipenv -``` -pipenv install / update -``` +Currently there are two ways to deploy the lostplaces project: +1. Cloning this repository, including the configured django instance +2. Install the package and setup the django instance your self -### Add 'lostplaces_app' to your INSTALLED_APPS setting like this +## Cloning the repository -``` +Essently, this is the same as installing an development instance, but without the development server (manage.py runserver) and something powerfull (Apache, NGINX) instead. You have to configure the webserve to work with the *SGI Api respectivly, reference [django's guide for deployment](https://docs.djangoproject.com/en/3.1/howto/deployment/) for further information. + +You also should setup an dedicated database server, the build in SQLite file is not recommened for production use. Reference [django's guide for databases](https://docs.djangoproject.com/en/3.1/ref/databases/) for further information. + +Before making the django instance public, you should tweak the config `settings.py`: +1. Change the secret key, the one found in the config is already public. Choose something secure (i.e. [this](https://duckduckgo.com/?q=password+generator+64)) +2. Turn off debug mode by setting `DEBUG = False` +3. Tune the localization settings, see [django's documentation](https://docs.djangoproject.com/en/3.1/topics/i18n/) + +Run `lostplaces/managy.py collectstatic` you should be ready to go. + + +## Installing the lostplaces_app to an existing django instance + +### Installing django and the lostplaces app + +If you haven't already setup an django instance, see [django's documentation](https://docs.djangoproject.com/en/3.1/topics/install/). + +After that, download the desired release (probably the latest one) [from the realeases page](https://git.mowoe.com/reverend/lostplaces-backend/releases) and install it using `pip install --user name-of-the-file.tar.gz`. + +*Note: You can run pip install without the --user flag, which will require root privileges and introduces potential security issues* + +### Configuring the django instance + +Now configure your `settings.py` as follows: +1. Add the following apps to the django project + +```python INSTALLED_APPS = [ ... 'lostplaces_app', @@ -66,41 +95,46 @@ INSTALLED_APPS = [ ] ``` -### Add this configuration to your settings.py +2. Set the URL's and Root-directories for file handling, for example +```python +STATIC_URL = '/static/' +STATIC_ROOT = os.path.join(BASE_DIR, 'static_files') + +MEDIA_URL = '/uploads/' +MEDIA_ROOT = os.path.join(BASE_DIR, 'uploads') ``` -from django.urls import reverse_lazy -... + +3. Set the user model (this will be changed in the next release) + +```python AUTH_USER_MODEL = 'lostplaces_app.Explorer' +``` +4. Set the URL's for login, for example + +```python LOGIN_URL = reverse_lazy('login') - -THUMBNAIL_ALIASES = { - '': { - 'thumbnail': {'size': (300, 300), 'crop': False}, - 'hero': {'size': (700, 700), 'crop': False}, - 'large': {'size': (1920, 1920), 'crop': False}, - }, -} +LOGIN_REDIRECT_URL = reverse_lazy('lostplaces_home') +LOGOUT_REDIRECT_URL = reverse_lazy('lostplaces_home') ``` - -### Include the lostplaces URLconf in your project urls.py like this - -``` -from django.urls import path, include -... +### Configuring the URL's +In the `urls.py` configure the `urlpatter` like this +```python urlpatterns = [ - ... - path('lostplaces/', include('lostplaces_app.urls')), -] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + path('admin/', admin.site.urls), + path('signup/', SignUpView.as_view(), name='signup'), # If you want to use lostplaces sign up view + path('explorers/', include('django.contrib.auth.urls')), # You can change the 'explorers/' to whatever you desire + path('', include('lostplaces_app.urls')), # In this configuration lostplaces will be at the top level of you website, change '' to 'lostplaces/', if you don't want this +] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # So django can deliver user uploaded files ``` -Run ``./manage.py migrate`` to create the lost places models. - -Start the development server and visit http://localhost:8000/admin/ - -Visit http://localhost:8000/ to CRUD lost places. +Before making the django instance public, you should tweak the config `settings.py`: +1. Change the secret key, the one found in the config is already public. Choose something secure (i.e. [this](https://duckduckgo.com/?q=password+generator+64)) +2. Turn off debug mode by setting `DEBUG = False` +3. Tune the localization settings, see [django's documentation](https://docs.djangoproject.com/en/3.1/topics/i18n/) +Run `lostplaces/managy.py collectstatic` you should be ready to go. Happy developing ;-) diff --git a/lostplaces/lostplaces/settings.py b/lostplaces/lostplaces/settings.py index e08bb8d..f69bacb 100644 --- a/lostplaces/lostplaces/settings.py +++ b/lostplaces/lostplaces/settings.py @@ -29,22 +29,22 @@ SECRET_KEY = 'n$(bx8(^)*wz1ygn@-ekt7rl^1km*!_c+fwwjiua8m@-x_rpl0' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [ 'localhost' ] +ALLOWED_HOSTS = ['localhost'] # Application definition INSTALLED_APPS = [ 'lostplaces_app', + 'easy_thumbnails', + 'widget_tweaks', + 'taggit', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', - 'django.contrib.staticfiles', - 'easy_thumbnails', - 'widget_tweaks', - 'taggit' + 'django.contrib.staticfiles' ] MIDDLEWARE = [ @@ -62,7 +62,7 @@ ROOT_URLCONF = 'lostplaces.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [os.path.join(BASE_DIR, 'templates')], + 'DIRS': [], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ @@ -126,9 +126,7 @@ USE_TZ = True # https://docs.djangoproject.com/en/3.0/howto/static-files/ STATIC_URL = '/static/' -STATICFILES_DIRS = [ - os.path.join(BASE_DIR, "static") -] +STATIC_ROOT = os.path.join(BASE_DIR, 'static_files') MEDIA_URL = '/uploads/' MEDIA_ROOT = os.path.join(BASE_DIR, 'uploads') @@ -137,17 +135,6 @@ MEDIA_ROOT = os.path.join(BASE_DIR, 'uploads') AUTH_USER_MODEL = 'lostplaces_app.Explorer' # Templates to use for authentication -LOGIN_REDIRECT_URL = 'home' -LOGOUT_REDIRECT_URL = 'home' - LOGIN_URL = reverse_lazy('login') - -THUMBNAIL_ALIASES = { - '': { - 'thumbnail': {'size': (300, 200), 'crop': True}, - 'hero': {'size': (700, 466), 'crop': True}, - 'large': {'size': (1920, 1920), 'crop': False}, - }, -} - -SVG_ICONS_SOURCE_FILE = os.path.join(BASE_DIR, 'lostplaces_app', 'static', 'icons', 'icons.icomoon.json') +LOGIN_REDIRECT_URL = reverse_lazy('lostplaces_home') +LOGOUT_REDIRECT_URL = reverse_lazy('lostplaces_home') diff --git a/lostplaces/lostplaces/urls.py b/lostplaces/lostplaces/urls.py index 57bdc01..c01f7b8 100644 --- a/lostplaces/lostplaces/urls.py +++ b/lostplaces/lostplaces/urls.py @@ -23,8 +23,11 @@ from django.conf.urls.static import static from django.urls import path, include from django.views.generic.base import TemplateView +from lostplaces_app.views import SignUpView + urlpatterns = [ path('admin/', admin.site.urls), + path('signup/', SignUpView.as_view(), name='signup'), path('explorers/', include('django.contrib.auth.urls')), path('', include('lostplaces_app.urls')), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/lostplaces/lostplaces_app/__init__.py b/lostplaces/lostplaces_app/__init__.py index faa18be..720990e 100644 --- a/lostplaces/lostplaces_app/__init__.py +++ b/lostplaces/lostplaces_app/__init__.py @@ -1,2 +1,11 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +from django.conf import settings + +settings.THUMBNAIL_ALIASES = { + '': { + 'thumbnail': {'size': (300, 200), 'crop': True}, + 'hero': {'size': (700, 466), 'crop': True}, + 'large': {'size': (1920, 1920), 'crop': False}, + }, +} \ No newline at end of file diff --git a/lostplaces/lostplaces_app/static/tagify.css b/lostplaces/lostplaces_app/static/tagify.css deleted file mode 100644 index 750119a..0000000 --- a/lostplaces/lostplaces_app/static/tagify.css +++ /dev/null @@ -1,548 +0,0 @@ -:root { - --tagify-dd-color-primary: rgb(53, 149, 246); - --tagify-dd-bg-color: white -} - -.tagify { - --tags-border-color: #DDD; - --tags-hover-border-color: #CCC; - --tags-focus-border-color: #3595f6; - --tag-bg: #E5E5E5; - --tag-hover: #D3E2E2; - --tag-text-color: black; - --tag-text-color--edit: black; - --tag-pad: 0.3em 0.5em; - --tag-inset-shadow-size: 1.1em; - --tag-invalid-color: #D39494; - --tag-invalid-bg: rgba(211, 148, 148, 0.5); - --tag-remove-bg: rgba(211, 148, 148, 0.3); - --tag-remove-btn-color: black; - --tag-remove-btn-bg: none; - --tag-remove-btn-bg--hover: #c77777; - --input-color: inherit; - --tag--min-width: 1ch; - --tag--max-width: auto; - --tag-hide-transition: .3s; - --placeholder-color: rgba(0, 0, 0, 0.4); - --placeholder-color-focus: rgba(0, 0, 0, 0.25); - --loader-size: .8em; - display: flex; - align-items: flex-start; - flex-wrap: wrap; - border: 1px solid #ddd; - border: 1px solid var(--tags-border-color); - padding: 0; - line-height: 1.1; - cursor: text; - outline: 0; - position: relative; - transition: .1s -} - -@keyframes tags--bump { - 30% { - transform: scale(1.2) - } -} - -@keyframes rotateLoader { - to { - transform: rotate(1turn) - } -} - -.tagify:hover { - border-color: #ccc; - border-color: var(--tags-hover-border-color) -} - -.tagify.tagify--focus { - transition: 0s; - border-color: #3595f6; - border-color: var(--tags-focus-border-color) -} - -.tagify[readonly]:not(.tagify--mix) { - cursor: default -} - -.tagify[readonly]:not(.tagify--mix)>.tagify__input { - visibility: hidden; - width: 0; - margin: 5px 0 -} - -.tagify[readonly]:not(.tagify--mix) .tagify__tag__removeBtn { - display: none -} - -.tagify[readonly]:not(.tagify--mix) .tagify__tag>div { - padding: .3em .5em; - padding: var(--tag-pad) -} - -.tagify[readonly]:not(.tagify--mix) .tagify__tag>div::before { - background: linear-gradient(45deg, var(--tag-bg) 25%, transparent 25%, transparent 50%, var(--tag-bg) 50%, var(--tag-bg) 75%, transparent 75%, transparent) 0/5px 5px; - box-shadow: none; - filter: brightness(.95) -} - -.tagify--loading .tagify__input::before { - content: none -} - -.tagify--loading .tagify__input::after { - content: ''; - vertical-align: middle; - opacity: 1; - width: .7em; - height: .7em; - width: var(--loader-size); - height: var(--loader-size); - border: 3px solid; - border-color: #eee #bbb #888 transparent; - border-radius: 50%; - animation: rotateLoader .4s infinite linear; - margin: -2px 0 -2px .5em -} - -.tagify--loading .tagify__input:empty::after { - margin-left: 0 -} - -.tagify+input, -.tagify+textarea { - display: none !important -} - -.tagify__tag { - display: inline-flex; - align-items: center; - margin: 5px 0 5px 5px; - position: relative; - z-index: 1; - outline: 0; - cursor: default; - transition: .13s ease-out -} - -.tagify__tag>div { - vertical-align: top; - box-sizing: border-box; - max-width: 100%; - padding: .3em .5em; - padding: var(--tag-pad); - color: #000; - color: var(--tag-text-color); - line-height: inherit; - border-radius: 3px; - -webkit-user-select: none; - user-select: none; - white-space: nowrap; - transition: .13s ease-out -} - -.tagify__tag>div>* { - white-space: pre-wrap; - overflow: hidden; - text-overflow: ellipsis; - display: inline-block; - vertical-align: top; - min-width: var(--tag--min-width); - max-width: var(--tag--max-width); - transition: .8s ease, .1s color -} - -.tagify__tag>div>[contenteditable] { - outline: 0; - -webkit-user-select: text; - user-select: text; - cursor: text; - margin: -2px; - padding: 2px; - max-width: 350px -} - -.tagify__tag>div::before { - content: ''; - position: absolute; - border-radius: inherit; - left: 0; - top: 0; - right: 0; - bottom: 0; - z-index: -1; - pointer-events: none; - transition: 120ms ease; - animation: tags--bump .3s ease-out 1; - box-shadow: 0 0 0 1.1em #e5e5e5 inset; - box-shadow: 0 0 0 var(--tag-inset-shadow-size) var(--tag-bg) inset -} - -.tagify__tag:hover:not([readonly]) div::before { - top: -2px; - right: -2px; - bottom: -2px; - left: -2px; - box-shadow: 0 0 0 1.1em #d3e2e2 inset; - box-shadow: 0 0 0 var(--tag-inset-shadow-size) var(--tag-hover) inset -} - -.tagify__tag--loading { - pointer-events: none -} - -.tagify__tag--loading .tagify__tag__removeBtn { - display: none -} - -.tagify__tag--loading::after { - --loader-size: .4em; - content: ''; - vertical-align: middle; - opacity: 1; - width: .7em; - height: .7em; - width: var(--loader-size); - height: var(--loader-size); - border: 3px solid; - border-color: #eee #bbb #888 transparent; - border-radius: 50%; - animation: rotateLoader .4s infinite linear; - margin: 0 .5em 0 -.1em -} - -.tagify__tag--flash div::before { - animation: none -} - -.tagify__tag--hide { - width: 0 !important; - padding-left: 0; - padding-right: 0; - margin-left: 0; - margin-right: 0; - opacity: 0; - transform: scale(0); - transition: .3s; - transition: var(--tag-hide-transition); - pointer-events: none -} - -.tagify__tag.tagify--noAnim>div::before { - animation: none -} - -.tagify__tag.tagify--notAllowed:not(.tagify__tag--editable) div>span { - opacity: .5 -} - -.tagify__tag.tagify--notAllowed:not(.tagify__tag--editable) div::before { - box-shadow: 0 0 0 1.1em rgba(211, 148, 148, .5) inset !important; - box-shadow: 0 0 0 var(--tag-inset-shadow-size) var(--tag-invalid-bg) inset !important; - transition: .2s -} - -.tagify__tag[readonly] .tagify__tag__removeBtn { - display: none -} - -.tagify__tag[readonly]>div::before { - background: linear-gradient(45deg, var(--tag-bg) 25%, transparent 25%, transparent 50%, var(--tag-bg) 50%, var(--tag-bg) 75%, transparent 75%, transparent) 0/5px 5px; - box-shadow: none; - filter: brightness(.95) -} - -.tagify__tag--editable>div { - color: #000; - color: var(--tag-text-color--edit) -} - -.tagify__tag--editable>div::before { - box-shadow: 0 0 0 2px #d3e2e2 inset !important; - box-shadow: 0 0 0 2px var(--tag-hover) inset !important -} - -.tagify__tag--editable.tagify--invalid>div::before { - box-shadow: 0 0 0 2px #d39494 inset !important; - box-shadow: 0 0 0 2px var(--tag-invalid-color) inset !important -} - -.tagify__tag__removeBtn { - order: 5; - display: inline-flex; - align-items: center; - justify-content: center; - border-radius: 50px; - cursor: pointer; - font: 14px/1 Arial; - background: 0 0; - background: var(--tag-remove-btn-bg); - color: #000; - color: var(--tag-remove-btn-color); - width: 14px; - height: 14px; - margin-right: 4.66667px; - margin-left: -4.66667px; - transition: .2s ease-out -} - -.tagify__tag__removeBtn::after { - content: "\00D7" -} - -.tagify__tag__removeBtn:hover { - color: #fff; - background: #c77777; - background: var(--tag-remove-btn-bg--hover) -} - -.tagify__tag__removeBtn:hover+div>span { - opacity: .5 -} - -.tagify__tag__removeBtn:hover+div::before { - box-shadow: 0 0 0 1.1em rgba(211, 148, 148, .3) inset !important; - box-shadow: 0 0 0 var(--tag-inset-shadow-size) var(--tag-remove-bg) inset !important; - transition: .2s -} - -.tagify:not(.tagify--mix) .tagify__input br { - display: none -} - -.tagify:not(.tagify--mix) .tagify__input * { - display: inline; - white-space: nowrap -} - -.tagify__input { - flex-grow: 1; - display: inline-block; - min-width: 110px; - margin: 5px; - padding: .3em .5em; - padding: var(--tag-pad, .3em .5em); - line-height: inherit; - position: relative; - white-space: pre-wrap; - color: inherit; - color: var(--input-color) -} - -.tagify__input:empty::before { - transition: .2s ease-out; - opacity: 1; - transform: none; - display: inline-block; - width: auto -} - -.tagify--mix .tagify__input:empty::before { - display: inline-block -} - -.tagify__input:focus { - outline: 0 -} - -.tagify__input:focus::before { - transition: .2s ease-out; - opacity: 0; - transform: translatex(6px) -} - -@media all and (-ms-high-contrast:none), -(-ms-high-contrast:active) { - .tagify__input:focus::before { - display: none - } -} - -@supports (-ms-ime-align:auto) { - .tagify__input:focus::before { - display: none - } -} - -.tagify__input:focus:empty::before { - transition: .2s ease-out; - opacity: 1; - transform: none; - color: rgba(0, 0, 0, .25); - color: var(--placeholder-color-focus) -} - -@-moz-document url-prefix() { - .tagify__input:focus:empty::after { - display: none - } -} - -.tagify__input::before { - content: attr(data-placeholder); - height: 1em; - line-height: 1em; - margin: auto 0; - z-index: 1; - color: rgba(0, 0, 0, .4); - color: var(--placeholder-color); - white-space: nowrap; - pointer-events: none; - opacity: 0; - position: absolute -} - -.tagify--mix .tagify__input::before { - display: none; - position: static; - line-height: inherit -} - -.tagify__input::after { - content: attr(data-suggest); - display: inline-block; - white-space: pre; - color: #000; - opacity: .3; - pointer-events: none; - max-width: 100px -} - -.tagify__input .tagify__tag { - margin: 0 -} - -.tagify__input .tagify__tag>div { - padding-top: 0; - padding-bottom: 0 -} - -.tagify--mix { - display: block -} - -.tagify--mix .tagify__input { - padding: 5px; - margin: 0; - width: 100%; - height: 100%; - line-height: 1.5 -} - -.tagify--mix .tagify__input::before { - height: auto -} - -.tagify--mix .tagify__input::after { - content: none -} - -.tagify--select::after { - content: '>'; - opacity: .5; - position: absolute; - top: 50%; - right: 0; - bottom: 0; - font: 16px monospace; - line-height: 8px; - height: 8px; - pointer-events: none; - transform: translate(-150%, -50%) scaleX(1.2) rotate(90deg); - transition: .2s ease-in-out -} - -.tagify--select[aria-expanded=true]::after { - transform: translate(-150%, -50%) rotate(270deg) scaleY(1.2) -} - -.tagify--select .tagify__tag { - position: absolute; - top: 0; - right: 1.8em; - bottom: 0 -} - -.tagify--select .tagify__tag div { - display: none -} - -.tagify--select .tagify__input { - width: 100% -} - -.tagify--invalid { - --tags-border-color: #D39494 -} - -.tagify__dropdown { - position: absolute; - z-index: 9999; - transform: translateY(1px); - overflow: hidden -} - -.tagify__dropdown[placement=top] { - margin-top: 0; - transform: translateY(-100%) -} - -.tagify__dropdown[placement=top] .tagify__dropdown__wrapper { - border-top-width: 1px; - border-bottom-width: 0 -} - -.tagify__dropdown[position=text] { - box-shadow: 0 0 0 3px rgba(var(--tagify-dd-color-primary), .1); - font-size: .9em -} - -.tagify__dropdown[position=text] .tagify__dropdown__wrapper { - border-width: 1px -} - -.tagify__dropdown__wrapper { - max-height: 300px; - overflow: hidden; - background: #fff; - background: var(--tagify-dd-bg-color); - border: 1px solid #3595f6; - border-color: var(--tagify-dd-color-primary); - border-top-width: 0; - box-shadow: 0 2px 4px -2px rgba(0, 0, 0, .2); - transition: .25s cubic-bezier(0, 1, .5, 1) -} - -.tagify__dropdown__wrapper:hover { - overflow: auto -} - -.tagify__dropdown--initial .tagify__dropdown__wrapper { - max-height: 20px; - transform: translateY(-1em) -} - -.tagify__dropdown--initial[placement=top] .tagify__dropdown__wrapper { - transform: translateY(2em) -} - -.tagify__dropdown__item { - box-sizing: inherit; - padding: .3em .5em; - margin: 1px; - cursor: pointer; - border-radius: 2px; - position: relative; - outline: 0 -} - -.tagify__dropdown__item--active { - background: #3595f6; - background: var(--tagify-dd-color-primary); - color: #fff -} - -.tagify__dropdown__item:active { - filter: brightness(105%) -} \ No newline at end of file diff --git a/lostplaces/lostplaces_app/templates/global.html b/lostplaces/lostplaces_app/templates/global.html index 6863ad3..bca584f 100644 --- a/lostplaces/lostplaces_app/templates/global.html +++ b/lostplaces/lostplaces_app/templates/global.html @@ -16,77 +16,78 @@ -
-