Compare commits
37 Commits
feature/50
...
develop
Author | SHA1 | Date | |
---|---|---|---|
|
3982db1375 | ||
|
e60a6ea9be | ||
|
bc0ace7bf3 | ||
|
df67bcf639 | ||
|
724c26c926 | ||
|
06d68380c9 | ||
|
f06b6bdae9 | ||
|
7a7c06882a | ||
|
c9d83dfc2c | ||
|
49301afe51 | ||
|
624878624f | ||
|
a2ee323fa4 | ||
|
86c9de3213 | ||
|
8597e53599 | ||
|
d213b51a59 | ||
|
9c50e5891f | ||
|
72094494eb | ||
|
c483c3511d | ||
14effd33e2 | |||
19300614bc | |||
830120a929 | |||
ddd0f8c903 | |||
f078afcdcd | |||
d5f6a00219 | |||
f376951ff9 | |||
163e9beb51 | |||
6ba225bee3 | |||
a4f80820c9 | |||
0f7b799c11 | |||
b23dc8a627 | |||
3e2ab1e12d | |||
78efe9bebb | |||
1de203ad40 | |||
399fa70ab6 | |||
c6a28c7b66 | |||
9980a2d190 | |||
1bc283bd8d |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -79,7 +79,6 @@ Pipfile.lock
|
||||
__pypackages__/
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
@@ -95,3 +94,6 @@ venv.bak/
|
||||
|
||||
# Django Migrations for Development branches
|
||||
django_lostplaces/lostplaces/migrations/*
|
||||
|
||||
# Django Static files
|
||||
django_lostplaces/static/*
|
7
Pipfile
7
Pipfile
@@ -14,6 +14,7 @@ pandoc = "*"
|
||||
pylint-django = "*"
|
||||
setuptools = "*"
|
||||
django-nose = "*"
|
||||
invoke = "*"
|
||||
|
||||
[packages]
|
||||
django = "*"
|
||||
@@ -21,6 +22,7 @@ easy-thumbnails = "*"
|
||||
image = "*"
|
||||
django-widget-tweaks = "*"
|
||||
django-taggit = "*"
|
||||
pykml = "*"
|
||||
|
||||
[scripts]
|
||||
test = "django_lostplaces/manage.py test lostplaces"
|
||||
@@ -29,4 +31,9 @@ dbshell = "django_lostplaces/manage.py dbshell"
|
||||
showmigrations = "django_lostplaces/manage.py showmigrations"
|
||||
makemigrations = "django_lostplaces/manage.py makemigrations --no-input"
|
||||
migrate = "django_lostplaces/manage.py migrate"
|
||||
collectstatic = "django_lostplaces/manage.py collectstatic"
|
||||
build = "django_lostplaces/setup.py bdist_wheel --universal"
|
||||
createsuperuser = "django_lostplaces/manage.py createsuperuser --noinput --username admin --email admin@example.org"
|
||||
createsuperuser_prompt = "django_lostplaces/manage.py createsuperuser"
|
||||
quickstart = "invoke quickstart"
|
||||
security = "pipenv check"
|
19
Readme.md
19
Readme.md
@@ -1,6 +1,6 @@
|
||||
# lostplaces-backend
|
||||
|
||||
lostplaces-backend is a django (3.x) based webproject. It once wants to become a software which allows a group of urban explorers to manage, document and share the locations of lost places while not exposing too much / any information to the public.
|
||||
lostplaces-backend is a django (4.x) based webproject. It once wants to become a software which allows a group of urban explorers to manage, document and share the locations of lost places while not exposing too much / any information to the public.
|
||||
|
||||
The software is currently in early development status, neither scope, datamodel(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.
|
||||
|
||||
@@ -35,7 +35,7 @@ Right now it depends on the following non-core Python 3 libraries. These can be
|
||||
|
||||
# Installing a development instance
|
||||
## Clone the repository
|
||||
`git clone https://git.mowoe.com/reverend/lostplaces-backend.git`
|
||||
`git clone https://git.commander1024.de/Commander1024/lostplaces-backend`
|
||||
## 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.
|
||||
@@ -65,6 +65,21 @@ Visit: [admin](http://localhost:8000/admin) for administrative backend or
|
||||
|
||||
Happy developing ;-)
|
||||
|
||||
# Pipenv Scripts
|
||||
This project comes with a bunch of convinient scripts, like:
|
||||
|Script|Description|
|
||||
|---|---|
|
||||
|test|Runs the tests|
|
||||
|server|Starts a **development** server|
|
||||
|dbshell|Opens a shell session in the database|
|
||||
|showmigrations|Lists all Migrations|
|
||||
|makemigrations|Creates a migration|
|
||||
|migrate|Applies unapplied migrations|
|
||||
|build|Builds this project into a wheel file|
|
||||
|createsuperuser|Creates a superuser with the username **admin** and the password **develop**. This is for development and demo instances only!
|
||||
|quickstart|Runs *migrate*, *createsuperuser* and *server*|
|
||||
|
||||
|
||||
# Installing a productive instance
|
||||
|
||||
Currently there are two ways to deploy the lostplaces project:
|
||||
|
BIN
django_lostplaces/db.sqlite3.develop
Normal file
BIN
django_lostplaces/db.sqlite3.develop
Normal file
Binary file not shown.
@@ -32,9 +32,9 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
SECRET_KEY = 'n$(bx8(^)*wz1ygn@-ekt7rl^1km*!_c+fwwjiua8m@-x_rpl0'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
DEBUG = False
|
||||
|
||||
ALLOWED_HOSTS = ['localhost']
|
||||
ALLOWED_HOSTS = ['localhost', '127.0.0.1', '[::1]']
|
||||
|
||||
|
||||
# Application definition
|
||||
@@ -145,15 +145,16 @@ LANGUAGES = [
|
||||
# https://docs.djangoproject.com/en/3.1/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
STATIC_ROOT = os.path.join(BASE_DIR, 'static_files')
|
||||
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
|
||||
|
||||
# Upload directory
|
||||
MEDIA_URL = '/uploads/'
|
||||
MEDIA_ROOT = os.path.join(BASE_DIR, 'uploads')
|
||||
MEDIA_ROOT = os.path.join(BASE_DIR, 'uploads/')
|
||||
|
||||
# Thumbnails
|
||||
THUMBNAIL_MEDIA_ROOT = os.path.join(MEDIA_ROOT, 'thumbs/')
|
||||
THUMBNAIL_MEDIA_URL = os.path.join(MEDIA_URL, 'thumbs/')
|
||||
RELATIVE_THUMBNAIL_PATH = 'images/'
|
||||
THUMBNAIL_MEDIA_ROOT = os.path.join(MEDIA_ROOT, RELATIVE_THUMBNAIL_PATH)
|
||||
THUMBNAIL_MEDIA_URL = os.path.join(MEDIA_URL, RELATIVE_THUMBNAIL_PATH)
|
||||
THUMBNAIL_QUALITY = 75
|
||||
|
||||
# Templates to use for authentication
|
||||
|
@@ -19,8 +19,9 @@ Including another URLconf
|
||||
|
||||
from django.contrib import admin
|
||||
from django.conf import settings
|
||||
from django.views.static import serve
|
||||
from django.conf.urls.static import static
|
||||
from django.urls import path, include
|
||||
from django.urls import path, include, re_path
|
||||
from django.views.generic.base import TemplateView
|
||||
|
||||
from lostplaces.views import SignUpView
|
||||
@@ -30,4 +31,6 @@ urlpatterns = [
|
||||
path('signup/', SignUpView.as_view(), name='signup'),
|
||||
path('explorer/', include('django.contrib.auth.urls')),
|
||||
path('', include('lostplaces.urls')),
|
||||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
re_path(r'^static/(?P<path>.*)$', serve,{'document_root': settings.STATIC_ROOT}),
|
||||
re_path(r'^uploads/(?P<path>.*)$', serve,{'document_root': settings.MEDIA_ROOT})
|
||||
]
|
||||
|
@@ -35,3 +35,4 @@ admin.site.register(Voucher, VoucherAdmin)
|
||||
admin.site.register(Place, PlacesAdmin)
|
||||
admin.site.register(PlaceImage, PlaceImagesAdmin)
|
||||
admin.site.register(PhotoAlbum, PhotoAlbumsAdmin)
|
||||
admin.site.register(PlaceVoting)
|
||||
|
@@ -7,7 +7,7 @@ from django import forms
|
||||
from django.db import models
|
||||
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
|
||||
from django.contrib.auth.models import User
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from lostplaces import widgets
|
||||
from lostplaces.models import Place, PlaceImage, Voucher, Explorer
|
||||
@@ -22,7 +22,7 @@ class SignupVoucherForm(UserCreationForm):
|
||||
)
|
||||
|
||||
def is_valid(self):
|
||||
super().is_valid()
|
||||
super_result = super().is_valid()
|
||||
submitted_voucher = self.cleaned_data.get('voucher')
|
||||
try:
|
||||
fetched_voucher = Voucher.objects.get(code=submitted_voucher)
|
||||
@@ -35,7 +35,7 @@ class SignupVoucherForm(UserCreationForm):
|
||||
return False
|
||||
|
||||
fetched_voucher.delete()
|
||||
return True
|
||||
return super_result
|
||||
|
||||
class ExplorerUserChangeForm(UserChangeForm):
|
||||
class Meta:
|
||||
@@ -69,7 +69,7 @@ class PlaceForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Place
|
||||
fields = '__all__'
|
||||
exclude = ['submitted_by', 'level']
|
||||
exclude = ['submitted_by', 'level', 'mode']
|
||||
widgets = {
|
||||
'hero': widgets.SelectContent()
|
||||
}
|
||||
@@ -88,6 +88,11 @@ class PlaceForm(forms.ModelForm):
|
||||
widget=forms.NumberInput(attrs={'min':-180,'max': 180,'type': 'number', 'step': 'any'})
|
||||
)
|
||||
|
||||
draft = forms.BooleanField(
|
||||
label=_('Save Place as draft'),
|
||||
required=False
|
||||
)
|
||||
|
||||
class PlaceImageForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = PlaceImage
|
||||
@@ -122,3 +127,9 @@ class TagSubmitForm(forms.Form):
|
||||
required=False,
|
||||
widget=forms.TextInput(attrs={'autocomplete':'off'})
|
||||
)
|
||||
|
||||
class UploadMapFileForm(forms.Form):
|
||||
map_file = forms.FileField()
|
||||
description = forms.CharField(
|
||||
widget=forms.Textarea
|
||||
)
|
||||
|
@@ -1,118 +0,0 @@
|
||||
# Generated by Django 3.1.4 on 2020-12-25 16:02
|
||||
|
||||
import django.core.validators
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import easy_thumbnails.fields
|
||||
from lostplaces.models.models import generate_profile_image_filename
|
||||
from lostplaces.models.place import generate_place_image_filename
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('lostplaces', '0003_voucher'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='explorer',
|
||||
name='bio',
|
||||
field=models.TextField(blank=True, help_text='Describe yourself, your preferences, etc. in a few sentences.', null=True, verbose_name='Biography / Description'),
|
||||
),
|
||||
# migrations.AddField(
|
||||
# model_name='explorer',
|
||||
# name='favorite_places',
|
||||
# field=models.ManyToManyField(blank=True, related_name='explorer_favorites', to='lostplaces.Place', verbose_name='Explorers favorite places'),
|
||||
# ),
|
||||
migrations.AddField(
|
||||
model_name='explorer',
|
||||
name='profile_image',
|
||||
field=easy_thumbnails.fields.ThumbnailerImageField(blank=True, help_text='Optional profile image for display in Explorer profile', null=True, upload_to=generate_profile_image_filename, verbose_name='Profile image'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='photoalbum',
|
||||
name='label',
|
||||
field=models.CharField(max_length=100, verbose_name='link text'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='photoalbum',
|
||||
name='submitted_by',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='photoalbums', to='lostplaces.explorer', verbose_name='Submitter'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='photoalbum',
|
||||
name='submitted_when',
|
||||
field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='Submission date'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='photoalbum',
|
||||
name='url',
|
||||
field=models.URLField(verbose_name='URL'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='place',
|
||||
name='description',
|
||||
field=models.TextField(help_text="Description of the place: e.g. how to get there, where to be careful, the place's history...", verbose_name='Description'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='place',
|
||||
name='latitude',
|
||||
field=models.FloatField(help_text='Latitude in decimal format: e. g. 41.40338', validators=[django.core.validators.MinValueValidator(-90), django.core.validators.MaxValueValidator(90)], verbose_name='Latitude'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='place',
|
||||
name='location',
|
||||
field=models.CharField(max_length=50, verbose_name='Location'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='place',
|
||||
name='longitude',
|
||||
field=models.FloatField(help_text='Longitude in decimal format: e. g. 2.17403', validators=[django.core.validators.MinValueValidator(-180), django.core.validators.MaxValueValidator(180)], verbose_name='Longitude'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='place',
|
||||
name='name',
|
||||
field=models.CharField(max_length=50, verbose_name='Name'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='place',
|
||||
name='submitted_by',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='places', to='lostplaces.explorer', verbose_name='Submitter'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='place',
|
||||
name='submitted_when',
|
||||
field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='Submission date'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='placeimage',
|
||||
name='description',
|
||||
field=models.TextField(blank=True, verbose_name='Description'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='placeimage',
|
||||
name='filename',
|
||||
field=easy_thumbnails.fields.ThumbnailerImageField(help_text='Optional: One or more images to upload', upload_to=generate_place_image_filename, verbose_name='Filename(s)'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='placeimage',
|
||||
name='submitted_by',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='placeimages', to='lostplaces.explorer', verbose_name='Submitter'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='placeimage',
|
||||
name='submitted_when',
|
||||
field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='Submission date'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='voucher',
|
||||
name='created_when',
|
||||
field=models.DateTimeField(auto_now_add=True, verbose_name='Creation date'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='voucher',
|
||||
name='expires_when',
|
||||
field=models.DateTimeField(verbose_name='Expiration date'),
|
||||
),
|
||||
]
|
@@ -1,18 +0,0 @@
|
||||
# Generated by Django 3.1.4 on 2020-12-25 18:14
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('lostplaces', '0004_gory_fix'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='explorer',
|
||||
name='visited_places',
|
||||
field=models.ManyToManyField(blank=True, related_name='explorer_visits', to='lostplaces.Place', verbose_name='Explorers visited places'),
|
||||
),
|
||||
]
|
@@ -0,0 +1,85 @@
|
||||
# Generated by Django 3.2.10 on 2021-12-31 17:20
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import easy_thumbnails.fields
|
||||
import lostplaces.models.models
|
||||
import lostplaces.models.place
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('lostplaces', '0004_release_0_1_3'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='explorer',
|
||||
name='bio',
|
||||
field=models.TextField(blank=True, help_text='Describe yourself, your preferences, etc. in a few sentences.', null=True, verbose_name='Biography / Description'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='explorer',
|
||||
name='favorite_places',
|
||||
field=models.ManyToManyField(blank=True, related_name='explorer_favorites', to='lostplaces.Place', verbose_name='Explorers favorite places'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='explorer',
|
||||
name='level',
|
||||
field=models.IntegerField(choices=[(1, 'Newbie'), (2, 'Scout'), (3, 'Explorer'), (4, 'Journalist'), (5, 'Housekeeper')], default=1),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='explorer',
|
||||
name='profile_image',
|
||||
field=easy_thumbnails.fields.ThumbnailerImageField(blank=True, help_text='Optional profile image for display in Explorer profile', null=True, upload_to=lostplaces.models.generate_profile_image_filename, verbose_name='Profile image'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='explorer',
|
||||
name='visited_places',
|
||||
field=models.ManyToManyField(blank=True, related_name='explorer_visits', to='lostplaces.Place', verbose_name='Explorers visited places'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='place',
|
||||
name='hero',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='place_heros', to='lostplaces.placeimage'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='place',
|
||||
name='level',
|
||||
field=models.IntegerField(choices=[(1, 'Ruin'), (2, 'Vandalized'), (3, 'Natures Treasure'), (4, 'Lost in History'), (5, 'Time Capsule')], default=5),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='placeimage',
|
||||
name='filename',
|
||||
field=easy_thumbnails.fields.ThumbnailerImageField(help_text='Optional: One or more images to upload', upload_to=lostplaces.models.place.generate_place_image_filename, verbose_name='Images'),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='PlaceVoting',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('submitted_when', models.DateTimeField(auto_now_add=True, null=True, verbose_name='Submission date')),
|
||||
('created_when', models.DateTimeField(auto_now_add=True, verbose_name='Creation date')),
|
||||
('expires_when', models.DateTimeField(verbose_name='Expiration date')),
|
||||
('vote', models.IntegerField(choices=[(1, 'Ruin'), (2, 'Vandalized'), (3, 'Natures Treasure'), (4, 'Lost in History'), (5, 'Time Capsule')])),
|
||||
('place', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='placevotings', to='lostplaces.place')),
|
||||
('submitted_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='placevotings', to='lostplaces.explorer', verbose_name='Submitter')),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='DummyAsset',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('submitted_when', models.DateTimeField(auto_now_add=True, null=True, verbose_name='Submission date')),
|
||||
('name', models.CharField(max_length=50)),
|
||||
('place', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='dummyassets', to='lostplaces.place')),
|
||||
('submitted_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='dummyassets', to='lostplaces.explorer', verbose_name='Submitter')),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
]
|
@@ -1,14 +0,0 @@
|
||||
# Generated by Django 3.2.5 on 2021-07-16 11:15
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('lostplaces', '0004_release_0_1_3'),
|
||||
('lostplaces', '0005_add_visited_places'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
]
|
@@ -1,7 +1,7 @@
|
||||
|
||||
from django.utils import timezone
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import gettext as _
|
||||
from django.core.validators import MaxValueValidator, MinValueValidator
|
||||
|
||||
from taggit.managers import TaggableManager
|
||||
|
@@ -1,5 +1,5 @@
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from lostplaces.models.place import PlaceAsset
|
||||
|
||||
|
@@ -13,7 +13,7 @@ from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
from django.db.models.signals import post_save, pre_save
|
||||
from django.dispatch import receiver
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from lostplaces.models.abstract_models import Expireable
|
||||
from lostplaces.models.place import Place
|
||||
@@ -82,9 +82,25 @@ class Explorer(models.Model):
|
||||
choices=EXPLORER_LEVELS
|
||||
)
|
||||
|
||||
def get_place_list_to_display(self):
|
||||
'''
|
||||
Gets the list of places to show on the homepage
|
||||
and the list views
|
||||
'''
|
||||
if self.user.is_superuser:
|
||||
return Place.objects.filter(mode='live').order_by('submitted_when')
|
||||
|
||||
return (Place.objects.filter(
|
||||
level__lte=self.level,
|
||||
mode='live'
|
||||
) | Place.objects.filter(
|
||||
submitted_by=self,
|
||||
mode='live'
|
||||
)).order_by('submitted_when')
|
||||
|
||||
def get_places_eligible_to_see(self):
|
||||
if self.user.is_superuser:
|
||||
return Place.objects.all()
|
||||
return Place.objects.filter(mode='live')
|
||||
return Place.objects.all().filter(level__lte=self.level) | self.places.all()
|
||||
|
||||
def is_eligible_to_see(self, place):
|
||||
@@ -94,6 +110,12 @@ class Explorer(models.Model):
|
||||
place in self.get_places_eligible_to_see()
|
||||
)
|
||||
|
||||
def get_drafts(self):
|
||||
return Place.objects.filter(
|
||||
submitted_by=self,
|
||||
mode='draft'
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return self.user.username
|
||||
|
||||
|
@@ -1,12 +1,16 @@
|
||||
import os
|
||||
import datetime
|
||||
from math import ceil
|
||||
|
||||
from django.db import models
|
||||
from django.urls import reverse
|
||||
from django.dispatch import receiver
|
||||
from django.db.models.signals import post_delete, pre_save
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import gettext as _
|
||||
from django.utils import timezone
|
||||
from django.conf import settings
|
||||
|
||||
from lostplaces.models.abstract_models import Submittable, Taggable, Mapable
|
||||
from lostplaces.models.abstract_models import Submittable, Taggable, Mapable, Expireable
|
||||
|
||||
from easy_thumbnails.fields import ThumbnailerImageField
|
||||
from easy_thumbnails.files import get_thumbnailer
|
||||
@@ -15,10 +19,47 @@ PLACE_LEVELS = (
|
||||
(1, 'Ruin'),
|
||||
(2, 'Vandalized'),
|
||||
(3, 'Natures Treasure'),
|
||||
(4, 'Long Time no See'),
|
||||
(4, 'Lost in History'),
|
||||
(5, 'Time Capsule')
|
||||
)
|
||||
|
||||
PLACE_MODES = (
|
||||
('live', 'live'),
|
||||
('draft', 'draft'),
|
||||
('review', 'review'),
|
||||
('archive', 'archive'),
|
||||
('imported', 'imported')
|
||||
)
|
||||
|
||||
PLACE_IMPORT_TYPES = (
|
||||
('kml', 'KML-File import'),
|
||||
)
|
||||
|
||||
class PlaceImport(models.Model):
|
||||
imported_when = models.DateTimeField(
|
||||
auto_now_add=True,
|
||||
verbose_name=_('When the imported has taken place')
|
||||
)
|
||||
|
||||
description = models.TextField(
|
||||
default=None,
|
||||
null=True,
|
||||
verbose_name=_('Description of the import')
|
||||
)
|
||||
|
||||
explorer = models.ForeignKey(
|
||||
'Explorer',
|
||||
null=True,
|
||||
on_delete=models.SET_NULL,
|
||||
related_name='place_imports'
|
||||
)
|
||||
|
||||
import_type = models.TextField(
|
||||
default='kml',
|
||||
choices=PLACE_IMPORT_TYPES,
|
||||
verbose_name=_('What kind of import this is')
|
||||
)
|
||||
|
||||
class Place(Submittable, Taggable, Mapable):
|
||||
"""
|
||||
Place defines a lost place (location, name, description etc.).
|
||||
@@ -36,7 +77,7 @@ class Place(Submittable, Taggable, Mapable):
|
||||
hero = models.ForeignKey(
|
||||
'PlaceImage',
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
null=True,
|
||||
blank=True,
|
||||
related_name='place_heros'
|
||||
)
|
||||
@@ -46,6 +87,22 @@ class Place(Submittable, Taggable, Mapable):
|
||||
choices=PLACE_LEVELS
|
||||
)
|
||||
|
||||
mode = models.TextField(
|
||||
default='live',
|
||||
choices=PLACE_MODES,
|
||||
verbose_name=_('Mode of Place Editing')
|
||||
)
|
||||
|
||||
place_import = models.ForeignKey(
|
||||
PlaceImport,
|
||||
null=True,
|
||||
on_delete=models.SET_NULL,
|
||||
related_name='place_list'
|
||||
)
|
||||
|
||||
def is_imported(self):
|
||||
return self.place_import != None
|
||||
|
||||
def get_hero_image(self):
|
||||
if self.hero:
|
||||
return self.hero
|
||||
@@ -58,10 +115,15 @@ class Place(Submittable, Taggable, Mapable):
|
||||
return reverse('place_detail', kwargs={'pk': self.pk})
|
||||
|
||||
def get_hero_index_in_queryset(self):
|
||||
'''
|
||||
Calculates the index of the hero image within
|
||||
the list / queryset of images. Necessary for
|
||||
the lightbox.
|
||||
'''
|
||||
for i in range(0, len(self.placeimages.all())):
|
||||
image = self.placeimages.all()[i]
|
||||
if image == self.hero:
|
||||
return i
|
||||
return i
|
||||
return None
|
||||
|
||||
|
||||
@@ -69,20 +131,48 @@ class Place(Submittable, Taggable, Mapable):
|
||||
# Get center position of LP-geocoordinates.
|
||||
def average_latlon(cls, place_list):
|
||||
amount = len(place_list)
|
||||
# Init fill values to prevent None
|
||||
# China Corner in Münster
|
||||
# Where I almost always eat lunch
|
||||
# (Does'nt help losing wheight, tho)
|
||||
longitude = 7.6295628132604385
|
||||
latitude = 51.961922091398904
|
||||
|
||||
if amount > 0:
|
||||
latitude = 0
|
||||
longitude = 0
|
||||
|
||||
for place in place_list:
|
||||
longitude += place.longitude
|
||||
latitude += place.latitude
|
||||
return {'latitude':latitude / amount, 'longitude': longitude / amount}
|
||||
return {'latitude': latitude / amount, 'longitude': longitude / amount}
|
||||
else:
|
||||
# Location of China Corner in Münster
|
||||
# Where I almost always eat lunch
|
||||
# (Does'nt help losing wheight, tho)
|
||||
return {'latitude': 51.961922091398904, 'longitude': 7.6295628132604385}
|
||||
|
||||
return {'latitude': latitude, 'longitude': longitude}
|
||||
def calculate_place_level(self):
|
||||
if self.placevotings.count() == 0:
|
||||
self.level = 5
|
||||
self.save()
|
||||
return
|
||||
|
||||
level = 0
|
||||
|
||||
for vote in self.placevotings.all():
|
||||
level += vote.vote
|
||||
|
||||
self.level = round(level / self.placevotings.count())
|
||||
self.save()
|
||||
|
||||
def calculate_voting_accuracy(self):
|
||||
place_age = timezone.now() - self.submitted_when;
|
||||
accuaries = [];
|
||||
|
||||
for vote in self.placevotings.all():
|
||||
vote_age = timezone.now() - vote.submitted_when;
|
||||
accuracy = 100 - (100 / (place_age / vote_age))
|
||||
accuaries.append(accuracy)
|
||||
|
||||
if len(accuaries) > 0:
|
||||
return ceil(sum(accuaries) / len(accuaries))
|
||||
else:
|
||||
return 0
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
@@ -93,7 +183,7 @@ def generate_place_image_filename(instance, filename):
|
||||
Returns filename as: place_pk-placename{-number}.jpg
|
||||
"""
|
||||
|
||||
return 'places/' + str(instance.place.pk) + '-' + str(instance.place.name) + '.' + filename.split('.')[-1]
|
||||
return settings.RELATIVE_THUMBNAIL_PATH + str(instance.place.pk) + '-' + str(instance.place.name) + '.' + filename.split('.')[-1]
|
||||
|
||||
def generate_image_upload_path(instance, filename):
|
||||
return generate_place_image_filename(instance, filename)
|
||||
@@ -104,7 +194,7 @@ class PlaceAsset(Submittable):
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
abstract = True
|
||||
|
||||
place = models.ForeignKey(
|
||||
Place,
|
||||
@@ -180,3 +270,13 @@ def auto_delete_file_on_change(sender, instance, **kwargs):
|
||||
new_file = instance.filename
|
||||
if not old_file == new_file:
|
||||
old_file.delete(save=False)
|
||||
|
||||
|
||||
class PlaceVoting(PlaceAsset):
|
||||
vote = models.IntegerField(choices=PLACE_LEVELS)
|
||||
|
||||
def get_human_readable_level(self):
|
||||
return PLACE_LEVELS[self.vote - 1][1]
|
||||
|
||||
def get_all_choices(self):
|
||||
return reversed(PLACE_LEVELS)
|
||||
|
@@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
19116
django_lostplaces/lostplaces/static/materialdesignicons.css
Normal file
19116
django_lostplaces/lostplaces/static/materialdesignicons.css
Normal file
File diff suppressed because it is too large
Load Diff
28
django_lostplaces/lostplaces/templates/explorer/drafts.html
Normal file
28
django_lostplaces/lostplaces/templates/explorer/drafts.html
Normal file
@@ -0,0 +1,28 @@
|
||||
{% extends 'global.html'%}
|
||||
{% load static %}
|
||||
{% load i18n %}
|
||||
|
||||
{% load svg_icon %}
|
||||
|
||||
{% block maincontent %}
|
||||
<section class="LP-Section">
|
||||
<div class="LP-PlaceList">
|
||||
<h1 class="LP-Headline">
|
||||
{% if user.username == explorer.user.username %}
|
||||
{% translate 'Your drafts' %}
|
||||
{% else %}
|
||||
{{explorer.user.username}}{% translate '\'s drafts' %}
|
||||
{% endif %}
|
||||
</h1>
|
||||
<ul class="LP-PlaceList__List">
|
||||
{% for place in place_list %}
|
||||
<li class="LP-PlaceList__Item">
|
||||
<a href="{% url 'place_detail' pk=place.pk %}" class="LP-Link">
|
||||
{% include 'partials/place_teaser.html' with place=place extended=True %}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
{% endblock maincontent %}
|
@@ -12,6 +12,7 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="{% static 'main.css' %}">
|
||||
<link rel="stylesheet" href="{% static 'materialdesignicons.css' %}">
|
||||
<link rel="icon" type="image/png" href="{% static 'favicon.ico' %}">
|
||||
<title>
|
||||
{% block title %}Urban Exploration{% endblock %}
|
||||
@@ -31,7 +32,8 @@
|
||||
{% if user.is_authenticated %}
|
||||
Hi {{ user.username }}!
|
||||
<a class="LP-Link" href="{% url 'logout' %}"><span class="LP-Link__Text">{% translate 'Logout' %}</span></a> |
|
||||
<a class="LP-Link" href="{% url 'explorer_profile' explorer_id=user.pk%}"><span class="LP-Link__Text">{% translate 'Profile' %}</span></a>
|
||||
<a class="LP-Link" href="{% url 'explorer_profile' explorer_id=user.pk%}"><span class="LP-Link__Text">{% translate 'Profile' %}</span></a> |
|
||||
<a class="LP-Link" href="{% url 'explorer_drafts' explorer_id=user.pk%}"><span class="LP-Link__Text">{% translate 'Drafts' %}</span></a>
|
||||
{% if user.is_superuser %}
|
||||
| <a class="LP-Link" href="{% url 'admin:index' %}" target="_blank"><span class="LP-Link__Text">{% translate 'Admin' %}</span></a>
|
||||
{% endif %}
|
||||
@@ -57,6 +59,10 @@
|
||||
|
||||
<li class="LP-Menu__Item LP-Menu__Item--additional"><a href="{% url 'place_create'%}" class="LP-Link"><span class="LP-Link__Text">{% translate 'Create place' %}</span></a></li>
|
||||
<li class="LP-Menu__Item LP-Menu__Item--additional"><a href="{% url 'place_list'%}" class="LP-Link"><span class="LP-Link__Text">{% translate 'All places' %}</span></a></li>
|
||||
|
||||
{% if user.is_superuser %}
|
||||
<li class="LP-Menu__Item LP-Menu__Item--additional"><a href="{% url 'import_upload'%}" class="LP-Link"><span class="LP-Link__Text">{% translate 'Import KML File' %}</span></a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</nav>
|
||||
</aside>
|
||||
@@ -88,7 +94,7 @@
|
||||
</div>
|
||||
|
||||
{% block footer %}
|
||||
{% partial 'nav/footer' %}
|
||||
{% include 'partials/nav/footer.html' %}
|
||||
{% endblock footer %}
|
||||
|
||||
</body>
|
||||
|
@@ -12,13 +12,10 @@
|
||||
|
||||
{% block maincontent %}
|
||||
|
||||
{% partial 'welcome' %}
|
||||
{% include 'partials/welcome.html' %}
|
||||
<article class="LP-TextSection">
|
||||
</article>
|
||||
{% partial 'osm_map' %}
|
||||
{% set config mapping_config %}
|
||||
{% set modifier 'wide' %}
|
||||
{% endpartial %}
|
||||
{% include 'partials/osm_map.html' with config=mapping_config modifier='wide' %}
|
||||
<div class="LP-PlaceGrid">
|
||||
<h1 class="LP-Headline LP-Headline">{% translate 'Explore the latest places' %}</h1>
|
||||
<ul class="LP-PlaceGrid__Grid">
|
||||
|
@@ -6,7 +6,7 @@
|
||||
|
||||
{% block maincontent %}
|
||||
|
||||
{% partial 'welcome' %}
|
||||
{% include 'partials/welcome.html' %}
|
||||
<article class="LP-TextSection">
|
||||
<p class="LP-Paragraph">
|
||||
{% blocktranslate %}You can create, view and share your lost places with other members of this site. You can upload photos, place links to your web galleries and contribute your knowledge by tagging other places or commenting on them. You will find detailed information on where these locations are, how to get there and what to expect from them. This might even include detailed information on the surroundings or the history of a lost place.{% endblocktranslate %}
|
||||
@@ -25,9 +25,7 @@
|
||||
<a href="{% url 'place_detail' pk=place.pk %}" class="LP-Link">
|
||||
<article class="LP-PlaceTeaser">
|
||||
<div class="LP-PlaceTeaser__Image">
|
||||
{% partial 'image' %}
|
||||
{% set source_url place.placeimages.first.filename.thumbnail.url %}
|
||||
{% endpartial %}
|
||||
{% include 'partials/image.html' with source_url=place.placeimages.first.filename.thumbnail.url %}
|
||||
</div>
|
||||
<div class="LP-PlaceTeaser__Meta">
|
||||
<div class="LP-PlaceTeaser__Info">
|
||||
|
@@ -0,0 +1,33 @@
|
||||
{% extends 'global.html'%}
|
||||
{% load static %}
|
||||
{% load i18n %}
|
||||
|
||||
{% load svg_icon %}
|
||||
|
||||
{% block maincontent %}
|
||||
<h1 class="LP-Headline">
|
||||
{{ import_type}} from {{import.imported_when|date:"d F Y"}} by {{import.explorer.user.username}}
|
||||
</h1>
|
||||
|
||||
<p class="SP-Paragraph">
|
||||
{{import.place_list.all|length}} places where import in this import
|
||||
</p>
|
||||
<p class="SP-Paragraph">
|
||||
{{import.description}}
|
||||
</p>
|
||||
|
||||
<div class="LP-PlaceList">
|
||||
<h1 class="LP-Headline">{% translate 'Places imported' %}</h1>
|
||||
<ul class="LP-PlaceList__List">
|
||||
{% for place in paginated_places %}
|
||||
<li class="LP-PlaceList__Item">
|
||||
{% include 'partials/place_teaser.html' with place=place extended=True %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
{% include 'partials/nav/pagination.html' with page_obj=paginated_places is_paginated=True %}
|
||||
|
||||
</div>
|
||||
|
||||
{% endblock maincontent %}
|
@@ -0,0 +1,33 @@
|
||||
{% extends 'global.html'%}
|
||||
{% load static %}
|
||||
{% load i18n %}
|
||||
|
||||
{% load svg_icon %}
|
||||
|
||||
{% block maincontent %}
|
||||
<form class="LP-Form" method="POST" enctype="multipart/form-data">
|
||||
<fieldset class="LP-Form__Fieldset">
|
||||
<legend class="LP-Form__Legend">{% translate 'Import Places from KML File' %}</legend>
|
||||
{% csrf_token %}
|
||||
|
||||
<div class="LP-Form__Composition LP-Form__Composition--breakable">
|
||||
<div class="LP-Form__Field">
|
||||
{% include 'partials/form/inputField.html' with field=upload_form.description %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="LP-Form__Composition LP-Form__Composition--breakable">
|
||||
<div class="LP-Form__Field">
|
||||
{% include 'partials/form/inputField.html' with field=upload_form.map_file %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{% translate 'Create' as action %}
|
||||
<div class="LP-Form__Composition LP-Form__Composition--buttons">
|
||||
{% include 'partials/form/submit.html' with referrer=request.META.HTTP_REFERER action=action %}
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
</form>
|
||||
{% endblock maincontent %}
|
@@ -14,7 +14,7 @@
|
||||
<div class="LP-PlaceTeaser__Meta">
|
||||
<div class="LP-PlaceTeaser__Info">
|
||||
<span class="LP-PlaceTeaser__Title">
|
||||
<h1 class="LP-Headline LP-Headline--teaser">{{place.name|truncatechars:19}}</h1>
|
||||
<h1 class="LP-Headline LP-Headline--teaser">{{place.name}}</h1>
|
||||
</span>
|
||||
<span class="LP-PlaceTeaser__Detail">
|
||||
<p class="LP-Paragraph">{{place.location|truncatechars:25}}</p>
|
||||
|
36
django_lostplaces/lostplaces/templates/partials/voting.html
Normal file
36
django_lostplaces/lostplaces/templates/partials/voting.html
Normal file
@@ -0,0 +1,36 @@
|
||||
{% load i18n %}
|
||||
|
||||
<div class="LP-Voting">
|
||||
<div class="LP-Voting__Left">
|
||||
<h2 class="LP-Headline">
|
||||
Place level
|
||||
</h2>
|
||||
<div class="LP-Voting__Choices">
|
||||
{% for choice in voting.all_choices %}
|
||||
<a href="{% url 'place_vote' place_id=place.id vote=choice.0 %}" class="LP-Voting__Vote {% if choice.0 <= place.level %} LP-Voting__Vote--overall{% endif %}" title="Vote place as "{{choice.1}}"">
|
||||
<i class="mdi mdi-shield-home"></i>
|
||||
<span class="LP-Voting__Label">
|
||||
{{choice.1}}
|
||||
</span>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="LP-Voting__CurrentVote">
|
||||
{{place.get_level_display}}
|
||||
</div>
|
||||
</div>
|
||||
{% if voting.users_vote %}
|
||||
<div class="LP-Voting__Right">
|
||||
<div class="LP-Voting__Info">
|
||||
<div class="LP-Voting__UserVote">
|
||||
<span class="LP-Voting__InfoLabel">You voted this place as</span>
|
||||
<span class="LP-Voting__Vote">{{voting.users_vote.get_human_readable_level}} <i>Level {{voting.users_vote.vote}}</i></span>
|
||||
</div>
|
||||
|
||||
<div class="LP-Voting__Expiration">
|
||||
The accuracy of the voting is {{voting.accuracy}}%
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
@@ -39,8 +39,10 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{% translate 'Create' as action %}
|
||||
<div class="LP-Form__Composition LP-Form__Composition--buttons">
|
||||
{% include 'partials/form/inputField.html' with field=place_form.draft %}
|
||||
{% include 'partials/form/submit.html' with referrer=request.META.HTTP_REFERER action=action %}
|
||||
</div>
|
||||
</fieldset>
|
||||
|
@@ -23,15 +23,18 @@
|
||||
{% block maincontent %}
|
||||
<article class="LP-PlaceDetail">
|
||||
<header class="LP-PlaceDetail__Header">
|
||||
<h1 class="LP-Headline">{{ place.name }} {% include 'partials/icons/place_favorite.html' %} {% include 'partials/icons/place_visited.html' %}</h1>
|
||||
<h1 class="LP-Headline">
|
||||
{{ place.name }}
|
||||
{% include 'partials/icons/place_favorite.html' %}
|
||||
{% include 'partials/icons/place_visited.html' %}
|
||||
|
||||
{% if user.is_superuser %}
|
||||
<a class="LP-Link" href="{{'/admin/lostplaces/place/'|addstr:place.id }}" target="_blank"><span class="LP-Link__Text">{% translate 'view place in admin panel' %}</span></a>
|
||||
{% endif %}
|
||||
</h1>
|
||||
{% if place.get_hero_image %}
|
||||
<div class="LP-PlaceDetail__Image">
|
||||
{% partial image %}
|
||||
{% set source_url place.get_hero_image.filename.hero.url %}
|
||||
{% set link_url %}
|
||||
{{"#image"|addstr:place.get_hero_index_in_queryset}}
|
||||
{% endset %}
|
||||
{% endpartial %}
|
||||
{% include '../partials/image.html' with source_url=place.get_hero_image.filename.hero.url link_url="#image"|addstr:place.get_hero_index_in_queryset %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</header>
|
||||
@@ -40,25 +43,58 @@
|
||||
<p class="LP-Paragraph">{{ place.description }}</p>
|
||||
</div>
|
||||
|
||||
<section class="LP-Section">
|
||||
|
||||
{% url 'place_tag_submit' place_id=place.id as tag_submit_url%}
|
||||
{% partial tagging %}
|
||||
{% set config=tagging_config %}
|
||||
{% endpartial %}
|
||||
|
||||
</section>
|
||||
<div class="LP-Quickinfo">
|
||||
<section class="LP-Section">
|
||||
{% url 'place_tag_submit' place_id=place.id as tag_submit_url %}
|
||||
{% include '../partials/tagging.html' with config=tagging_config %}
|
||||
</section>
|
||||
|
||||
<section class="LP-Section">
|
||||
{% include '../partials/voting.html' with voting=placevoting %}
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section class="LP-Section">
|
||||
<h1 class="LP-Headline">{% translate 'Map links' %}</h1>
|
||||
{% partial osm_map config=mapping_config %}
|
||||
<div class="LP-LinkList">
|
||||
<ul class="LP-LinkList__Container">
|
||||
<li class="LP-LinkList__Item"><a target="_blank" href="https://www.google.com/maps?q={{place.latitude|safe}},{{place.longitude|safe}}" class="LP-Link"><span class="LP-Text">Google Maps</span></a></li>
|
||||
<li class="LP-LinkList__Item"><a target="_blank" href="https://www.tim-online.nrw.de/tim-online2/?center={{place.latitude|safe}},{{place.longitude|safe}}&icon=true&bg=dop" class="LP-Link"><span class="LP-Text">TIM Online</span></a></li>
|
||||
<li class="LP-LinkList__Item"><a target="_blank" href="http://www.openstreetmap.org/?mlat={{place.latitude|safe}}&mlon={{place.longitude|safe}}&zoom=16" class="LP-Link"><span class="LP-Text">OSM</span></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
{% include '../partials/osm_map.html' with config=mapping_config %}
|
||||
<ul class="LP-LinkList">
|
||||
<li class="LP-LinkList__Item">
|
||||
<a target="_blank" href="https://www.google.com/maps?q={{place.latitude|safe}},{{place.longitude|safe}}" class="LP-Link">
|
||||
<span class="LP-Text RV-Iconized">
|
||||
<span class="RV-Iconized__Text">
|
||||
Google Maps
|
||||
</span>
|
||||
<span class="RV-Iconized__Icon RV-Iconized__Icon--left">
|
||||
<i class="mdi mdi-map-outline"></i>
|
||||
</span>
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="LP-LinkList__Item">
|
||||
<a target="_blank" href="https://www.tim-online.nrw.de/tim-online2/?center={{place.latitude|safe}},{{place.longitude|safe}}&icon=true&bg=dop" class="LP-Link">
|
||||
<span class="LP-Text RV-Iconized">
|
||||
<span class="RV-Iconized__Text">
|
||||
TIM Online
|
||||
</span>
|
||||
<span class="RV-Iconized__Icon RV-Iconized__Icon--left">
|
||||
<i class="mdi mdi-map-outline"></i>
|
||||
</span>
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="LP-LinkList__Item">
|
||||
<a target="_blank" href="http://www.openstreetmap.org/?mlat={{place.latitude|safe}}&mlon={{place.longitude|safe}}&zoom=16" class="LP-Link">
|
||||
<span class="LP-Text RV-Iconized">
|
||||
<span class="RV-Iconized__Text">
|
||||
OSM
|
||||
</span>
|
||||
<span class="RV-Iconized__Icon RV-Iconized__Icon--left">
|
||||
<i class="mdi mdi-map-outline"></i>
|
||||
</span>
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<section class=" LP-Section">
|
||||
@@ -98,7 +134,7 @@
|
||||
|
||||
<section class="LP-Section">
|
||||
{% translate 'Images' as headline %}
|
||||
{% partial "placeImageGrid" image_list=place.placeimages.all %}
|
||||
{% include '../partials/placeImageGrid.html' with image_list=place.placeimages.all %}
|
||||
</section>
|
||||
|
||||
</article>
|
||||
|
@@ -14,7 +14,7 @@
|
||||
</div>
|
||||
|
||||
<div class="LP-Form__Composition LP-Form__Composition--buttons">
|
||||
{% include 'partials/form/submit.html' with referrer=request.META.HTTP_REFERER %}
|
||||
{% include 'partials/form/submit.html' with referer=request.META.HTTP_REFERER %}
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
|
@@ -42,21 +42,25 @@ class PlaceImageTestCase(ModelTestCase):
|
||||
if not os.path.isdir(settings.MEDIA_ROOT):
|
||||
os.mkdir(settings.MEDIA_ROOT)
|
||||
|
||||
images_dir = os.path.join(
|
||||
settings.MEDIA_ROOT,
|
||||
settings.RELATIVE_THUMBNAIL_PATH,
|
||||
)
|
||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
if not os.path.isfile(os.path.join(settings.MEDIA_ROOT, 'im_a_image_copy.jpeg')):
|
||||
shutil.copyfile(
|
||||
os.path.join(current_dir, 'im_a_image.jpeg'),
|
||||
os.path.join(settings.MEDIA_ROOT, 'im_a_image_copy.jpeg')
|
||||
os.path.join(images_dir, 'im_a_image_copy.jpeg')
|
||||
)
|
||||
|
||||
shutil.copyfile(
|
||||
os.path.join(current_dir, 'im_a_image.jpeg'),
|
||||
os.path.join(settings.MEDIA_ROOT, 'im_a_image_changed.jpeg')
|
||||
os.path.join(images_dir, 'im_a_image_changed.jpeg')
|
||||
)
|
||||
|
||||
PlaceImage.objects.create(
|
||||
description='Im a description',
|
||||
filename=os.path.join(settings.MEDIA_ROOT, 'im_a_image_copy.jpeg'),
|
||||
filename=os.path.join(images_dir, 'im_a_image_copy.jpeg'),
|
||||
place=place,
|
||||
submitted_when=timezone.now(),
|
||||
submitted_by=user.explorer
|
||||
|
@@ -1,13 +1,14 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import datetime
|
||||
from django.test import TestCase
|
||||
from django.db import models
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.utils import timezone
|
||||
|
||||
from lostplaces.models import Place
|
||||
from lostplaces.models import Place, PlaceVoting
|
||||
from lostplaces.tests.models import ModelTestCase
|
||||
|
||||
class PlaceTestCase(ModelTestCase):
|
||||
@@ -106,12 +107,12 @@ class PlaceTestCase(ModelTestCase):
|
||||
an empty list
|
||||
'''
|
||||
avg_latlon = Place.average_latlon([])
|
||||
self.assertEqual(avg_latlon['latitude'], 0,
|
||||
self.assertEqual(avg_latlon['latitude'], 51.961922091398904,
|
||||
msg='%s: (no places) average latitude missmatch' % (
|
||||
self.model.__name__
|
||||
)
|
||||
)
|
||||
self.assertEqual(avg_latlon['longitude'], 0,
|
||||
self.assertEqual(avg_latlon['longitude'], 7.6295628132604385,
|
||||
msg='%s: (no places) average longitude missmatch' % (
|
||||
self.model.__name__
|
||||
)
|
||||
@@ -124,3 +125,169 @@ class PlaceTestCase(ModelTestCase):
|
||||
self.model.__name__
|
||||
)
|
||||
)
|
||||
|
||||
def test_level_calculation(self):
|
||||
explorer = self.place.submitted_by
|
||||
|
||||
PlaceVoting.objects.create(
|
||||
submitted_by=explorer,
|
||||
place=self.place,
|
||||
vote=5
|
||||
)
|
||||
PlaceVoting.objects.create(
|
||||
submitted_by=explorer,
|
||||
place=self.place,
|
||||
vote=2
|
||||
)
|
||||
PlaceVoting.objects.create(
|
||||
submitted_by=explorer,
|
||||
place=self.place,
|
||||
vote=4
|
||||
)
|
||||
|
||||
self.place.calculate_place_level()
|
||||
|
||||
self.assertEqual(
|
||||
4,
|
||||
self.place.level,
|
||||
msg='Expecting the place level to be 4'
|
||||
)
|
||||
|
||||
def test_level_calculation_no_votes(self):
|
||||
self.place.calculate_place_level()
|
||||
self.assertEqual(
|
||||
5,
|
||||
self.place.level,
|
||||
msg='Expecting the default place level to be 5'
|
||||
)
|
||||
|
||||
def test_level_mid_accuracy(self):
|
||||
explorer = self.place.submitted_by
|
||||
six_month_ago = datetime.timedelta(days=180)
|
||||
self.place.submitted_when = timezone.now() - six_month_ago
|
||||
|
||||
votings = [
|
||||
{
|
||||
'date': timezone.now() - datetime.timedelta(days=170),
|
||||
'vote': 5
|
||||
},
|
||||
{
|
||||
'date': timezone.now() - datetime.timedelta(days=23),
|
||||
'vote': 2
|
||||
},
|
||||
{
|
||||
'date': timezone.now() - datetime.timedelta(days=1),
|
||||
'vote': 4
|
||||
}
|
||||
]
|
||||
|
||||
for vote in votings:
|
||||
voting = PlaceVoting.objects.create(
|
||||
submitted_by=explorer,
|
||||
place=self.place,
|
||||
vote= vote['vote']
|
||||
)
|
||||
voting.submitted_when = vote['date']
|
||||
voting.save()
|
||||
|
||||
self.assertEqual(
|
||||
65,
|
||||
self.place.calculate_voting_accuracy()
|
||||
)
|
||||
|
||||
def test_level_high_accuracy(self):
|
||||
explorer = self.place.submitted_by
|
||||
six_month_ago = datetime.timedelta(days=180)
|
||||
self.place.submitted_when = timezone.now() - six_month_ago
|
||||
|
||||
votings = [
|
||||
{
|
||||
'date': timezone.now() - datetime.timedelta(days=9),
|
||||
'vote': 5
|
||||
},
|
||||
{
|
||||
'date': timezone.now() - datetime.timedelta(days=14),
|
||||
'vote': 2
|
||||
},
|
||||
{
|
||||
'date': timezone.now() - datetime.timedelta(days=0),
|
||||
'vote': 4
|
||||
}
|
||||
]
|
||||
|
||||
for vote in votings:
|
||||
voting = PlaceVoting.objects.create(
|
||||
submitted_by=explorer,
|
||||
place=self.place,
|
||||
vote= vote['vote']
|
||||
)
|
||||
voting.submitted_when = vote['date']
|
||||
voting.save()
|
||||
|
||||
self.assertEqual(
|
||||
96,
|
||||
self.place.calculate_voting_accuracy()
|
||||
)
|
||||
|
||||
def test_level_low_accuracy(self):
|
||||
explorer = self.place.submitted_by
|
||||
six_month_ago = datetime.timedelta(days=180)
|
||||
self.place.submitted_when = timezone.now() - six_month_ago
|
||||
|
||||
votings = [
|
||||
{
|
||||
'date': timezone.now() - datetime.timedelta(days=177),
|
||||
'vote': 5
|
||||
},
|
||||
{
|
||||
'date': timezone.now() - datetime.timedelta(days=150),
|
||||
'vote': 2
|
||||
},
|
||||
{
|
||||
'date': timezone.now() - datetime.timedelta(days=100),
|
||||
'vote': 4
|
||||
}
|
||||
]
|
||||
|
||||
for vote in votings:
|
||||
voting = PlaceVoting.objects.create(
|
||||
submitted_by=explorer,
|
||||
place=self.place,
|
||||
vote= vote['vote']
|
||||
)
|
||||
voting.submitted_when = vote['date']
|
||||
voting.save()
|
||||
|
||||
self.assertEqual(
|
||||
21,
|
||||
self.place.calculate_voting_accuracy()
|
||||
)
|
||||
|
||||
def test_level_accuracy_zero_timedelta(self):
|
||||
explorer = self.place.submitted_by
|
||||
six_month_ago = datetime.timedelta(days=180)
|
||||
self.place.submitted_when = timezone.now() - six_month_ago
|
||||
|
||||
votings = [
|
||||
{
|
||||
'date': timezone.now() - datetime.timedelta(days=0),
|
||||
'vote': 4
|
||||
}
|
||||
]
|
||||
|
||||
for vote in votings:
|
||||
voting = PlaceVoting.objects.create(
|
||||
submitted_by=explorer,
|
||||
place=self.place,
|
||||
vote= vote['vote']
|
||||
)
|
||||
voting.submitted_when = vote['date']
|
||||
voting.save()
|
||||
|
||||
self.assertEqual(
|
||||
100,
|
||||
self.place.calculate_voting_accuracy(),
|
||||
msg='Expecting the accurcy to be 100% when the vote is 0 time units old'
|
||||
)
|
||||
|
||||
|
||||
|
BIN
django_lostplaces/lostplaces/tests/views/im_a_image.jpeg
Normal file
BIN
django_lostplaces/lostplaces/tests/views/im_a_image.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 81 KiB |
@@ -1,4 +1,4 @@
|
||||
23238#!/usr/bin/env python
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from django.test import TestCase, RequestFactory, Client
|
||||
@@ -7,6 +7,7 @@ from django.db import models
|
||||
from django.contrib.auth.models import User, AnonymousUser
|
||||
from django.contrib.messages.storage.fallback import FallbackStorage
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext as _
|
||||
from django.shortcuts import render
|
||||
|
||||
from lostplaces.models import Place
|
||||
|
300
django_lostplaces/lostplaces/tests/views/test_explorer_views.py
Normal file
300
django_lostplaces/lostplaces/tests/views/test_explorer_views.py
Normal file
@@ -0,0 +1,300 @@
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from django.utils.translation import gettext as _
|
||||
from django.utils import timezone
|
||||
from django.contrib.auth.models import User
|
||||
from django.conf import settings
|
||||
from django.urls import reverse
|
||||
|
||||
from lostplaces.tests.views import (
|
||||
ViewTestCase,
|
||||
GlobalTemplateTestCaseMixin
|
||||
)
|
||||
from lostplaces.views import ExplorerProfileView
|
||||
from lostplaces.models import(
|
||||
Place,
|
||||
PlaceImage,
|
||||
PhotoAlbum
|
||||
)
|
||||
|
||||
class TestExplorerProfileView(GlobalTemplateTestCaseMixin, ViewTestCase):
|
||||
view = ExplorerProfileView
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
user = User.objects.create_user(
|
||||
username='testpeter',
|
||||
password='Develop123'
|
||||
)
|
||||
|
||||
def test_unauth_profile_access(self):
|
||||
user = User.objects.get(username='testpeter')
|
||||
response = self.client.get(
|
||||
reverse('explorer_profile', kwargs={
|
||||
'explorer_id': user.explorer.id
|
||||
})
|
||||
)
|
||||
|
||||
self.assertHttpCode(response, 302)
|
||||
self.assertFalse(
|
||||
user.username in response.content.decode(),
|
||||
msg='Expecting the username to not be visible to unauthorized users'
|
||||
)
|
||||
|
||||
def test_unauth_profile_access_follow_redirect(self):
|
||||
user = User.objects.get(username='testpeter')
|
||||
response = self.client.get(
|
||||
reverse('explorer_profile', kwargs={
|
||||
'explorer_id': user.explorer.id
|
||||
}),
|
||||
follow=True
|
||||
)
|
||||
|
||||
self.assertHttpOK(response)
|
||||
self.assertTrue(
|
||||
_('Please login to proceed') in response.content.decode(),
|
||||
msg='Expecting a message to tell the user to login'
|
||||
)
|
||||
|
||||
def test_explorer_places(self):
|
||||
user = User.objects.get(username='testpeter')
|
||||
Place.objects.create(
|
||||
name='Im the latest place 4369',
|
||||
submitted_when=timezone.now(),
|
||||
submitted_by=user.explorer,
|
||||
location='Test %d town' % 5,
|
||||
latitude=50.5 + 5/10,
|
||||
longitude=7.0 - 5/10,
|
||||
description='This is just a test, do not worry %d' % 5,
|
||||
level=3
|
||||
)
|
||||
|
||||
self.client.login(username='testpeter', password='Develop123')
|
||||
|
||||
response = self.client.get(
|
||||
reverse('explorer_profile', kwargs={
|
||||
'explorer_id': user.explorer.id
|
||||
})
|
||||
)
|
||||
|
||||
self.assertHttpOK(response)
|
||||
self.assertTrue(
|
||||
'Im the latest place 4369' in response.content.decode(),
|
||||
msg='Expecting the latest place to be visible on the submitters profile page'
|
||||
)
|
||||
|
||||
def test_draft_in_explorer_places(self):
|
||||
user = User.objects.get(username='testpeter')
|
||||
Place.objects.create(
|
||||
name='Im the latest place in draft 3671',
|
||||
submitted_when=timezone.now(),
|
||||
submitted_by=user.explorer,
|
||||
location='Test %d town' % 5,
|
||||
latitude=50.5 + 5/10,
|
||||
longitude=7.0 - 5/10,
|
||||
description='This is just a test, do not worry %d' % 5,
|
||||
level=3,
|
||||
mode='draft'
|
||||
)
|
||||
|
||||
self.client.login(username='testpeter', password='Develop123')
|
||||
|
||||
response = self.client.get(
|
||||
reverse('explorer_profile', kwargs={
|
||||
'explorer_id': user.explorer.id
|
||||
})
|
||||
)
|
||||
|
||||
self.assertHttpOK(response)
|
||||
self.assertFalse(
|
||||
'Im the latest place in draft 3671' in response.content.decode(),
|
||||
msg='Expecting a place in draft mode to not show up on the submitters profile page'
|
||||
)
|
||||
|
||||
def test_explorer_image(self):
|
||||
user = User.objects.get(username='testpeter')
|
||||
place = Place.objects.create(
|
||||
name='Im a the latest place 4369',
|
||||
submitted_when=timezone.now(),
|
||||
submitted_by=user.explorer,
|
||||
location='Test %d town' % 5,
|
||||
latitude=50.5 + 5/10,
|
||||
longitude=7.0 - 5/10,
|
||||
description='This is just a test, do not worry %d' % 5,
|
||||
level=3
|
||||
)
|
||||
|
||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
file_path = os.path.join(
|
||||
settings.MEDIA_ROOT,
|
||||
settings.RELATIVE_THUMBNAIL_PATH,
|
||||
'im_a_image_3649.jpeg'
|
||||
)
|
||||
shutil.copyfile(
|
||||
os.path.join(current_dir, 'im_a_image.jpeg'),
|
||||
file_path
|
||||
)
|
||||
PlaceImage.objects.create(
|
||||
description='Im a description',
|
||||
filename=file_path,
|
||||
place=place,
|
||||
submitted_when=timezone.now(),
|
||||
submitted_by=user.explorer
|
||||
)
|
||||
|
||||
self.client.login(username='testpeter', password='Develop123')
|
||||
|
||||
response = self.client.get(
|
||||
reverse('explorer_profile', kwargs={
|
||||
'explorer_id': user.explorer.id
|
||||
})
|
||||
)
|
||||
|
||||
self.assertHttpOK(response)
|
||||
self.assertTrue(
|
||||
os.path.join(settings.RELATIVE_THUMBNAIL_PATH,'im_a_image_3649.jpeg') in response.content.decode(),
|
||||
msg='Expecting the latest place image to be visible on the submitters profile page'
|
||||
)
|
||||
|
||||
def test_explorer_photoalbum(self):
|
||||
user = User.objects.get(username='testpeter')
|
||||
place = Place.objects.create(
|
||||
name='Im a the latest place 4369',
|
||||
submitted_when=timezone.now(),
|
||||
submitted_by=user.explorer,
|
||||
location='Test %d town' % 5,
|
||||
latitude=50.5 + 5/10,
|
||||
longitude=7.0 - 5/10,
|
||||
description='This is just a test, do not worry %d' % 5,
|
||||
level=3
|
||||
)
|
||||
|
||||
PhotoAlbum.objects.create(
|
||||
place=place,
|
||||
submitted_by=user.explorer,
|
||||
url='http://example.org/6897134',
|
||||
label='Im a exmpale link label 6423'
|
||||
)
|
||||
|
||||
self.client.login(username='testpeter', password='Develop123')
|
||||
|
||||
response = self.client.get(
|
||||
reverse('explorer_profile', kwargs={
|
||||
'explorer_id': user.explorer.id
|
||||
})
|
||||
)
|
||||
|
||||
self.assertHttpOK(response)
|
||||
self.assertTrue(
|
||||
'href="http://example.org/6897134"' in response.content.decode(),
|
||||
msg='Expecting the latest photoalbum url to be linked on the submitters profile page'
|
||||
)
|
||||
|
||||
self.assertTrue(
|
||||
'Im a exmpale link label 6423' in response.content.decode(),
|
||||
msg='Expecting the latest photoalbum label to be on the submitters profile page'
|
||||
)
|
||||
|
||||
|
||||
class TestExplorerDraftsView(GlobalTemplateTestCaseMixin, ViewTestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
user = User.objects.create_user(
|
||||
username='testpeter',
|
||||
password='Develop123'
|
||||
)
|
||||
|
||||
User.objects.create_user(
|
||||
username='otheruser',
|
||||
password='Develop123'
|
||||
)
|
||||
|
||||
superuser = User.objects.create_user(
|
||||
username='toor',
|
||||
password='Develop123'
|
||||
)
|
||||
superuser.is_superuser = True
|
||||
superuser.save()
|
||||
|
||||
def test_draft_view(self):
|
||||
user = User.objects.get(username='testpeter')
|
||||
self.client.login(username='testpeter', password='Develop123')
|
||||
response = self.client.get(
|
||||
reverse('explorer_drafts', kwargs={
|
||||
'explorer_id': user.explorer.id
|
||||
})
|
||||
)
|
||||
self.assertHttpOK(response)
|
||||
|
||||
def test_draft_view_unauthorized_user(self):
|
||||
user = User.objects.get(username='testpeter')
|
||||
self.client.login(username='otheruser', password='Develop123')
|
||||
response = self.client.get(
|
||||
reverse('explorer_drafts', kwargs={
|
||||
'explorer_id': user.explorer.id
|
||||
})
|
||||
)
|
||||
self.assertHttpForbidden(response)
|
||||
|
||||
def test_draft_view_superuser(self):
|
||||
user = User.objects.get(username='testpeter')
|
||||
self.client.login(username='toor', password='Develop123')
|
||||
response = self.client.get(
|
||||
reverse('explorer_drafts', kwargs={
|
||||
'explorer_id': user.explorer.id
|
||||
})
|
||||
)
|
||||
self.assertHttpOK(response)
|
||||
|
||||
def test_place_in_draft_view(self):
|
||||
user = User.objects.get(username='testpeter')
|
||||
Place.objects.create(
|
||||
name='Im a draft place 3792',
|
||||
submitted_when=timezone.now(),
|
||||
submitted_by=user.explorer,
|
||||
location='Test %d town' % 5,
|
||||
latitude=50.5 + 5/10,
|
||||
longitude=7.0 - 5/10,
|
||||
description='This is just a test, do not worry %d' % 5,
|
||||
mode='draft',
|
||||
level=3
|
||||
)
|
||||
|
||||
self.client.login(username='testpeter', password='Develop123')
|
||||
response = self.client.get(
|
||||
reverse('explorer_drafts', kwargs={
|
||||
'explorer_id': user.explorer.id
|
||||
})
|
||||
)
|
||||
|
||||
self.assertTrue(
|
||||
'Im a draft place 3792' in response.content.decode(),
|
||||
msg='Expecting a place draft to be visible in the submitters drafs view'
|
||||
)
|
||||
|
||||
def test_place_not_in_draft_view(self):
|
||||
user = User.objects.get(username='testpeter')
|
||||
Place.objects.create(
|
||||
name='Im a draft place 3819',
|
||||
submitted_when=timezone.now(),
|
||||
submitted_by=user.explorer,
|
||||
location='Test %d town' % 5,
|
||||
latitude=50.5 + 5/10,
|
||||
longitude=7.0 - 5/10,
|
||||
description='This is just a test, do not worry %d' % 5,
|
||||
level=3
|
||||
)
|
||||
|
||||
self.client.login(username='testpeter', password='Develop123')
|
||||
response = self.client.get(
|
||||
reverse('explorer_drafts', kwargs={
|
||||
'explorer_id': user.explorer.id
|
||||
})
|
||||
)
|
||||
|
||||
self.assertFalse(
|
||||
'Im a draft place 3819' in response.content.decode(),
|
||||
msg='Expecting a live place to not be visible in the submitters drafs view'
|
||||
)
|
@@ -9,10 +9,11 @@ from django.urls import reverse
|
||||
from django.contrib.auth.models import User
|
||||
from django.utils import timezone
|
||||
from django.conf import settings
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
|
||||
from lostplaces.models import Place
|
||||
from lostplaces.models import PLACE_MODES
|
||||
from lostplaces.views import (
|
||||
PlaceCreateView,
|
||||
PlaceListView,
|
||||
@@ -154,6 +155,38 @@ class TestPlaceListView(GlobalTemplateTestCaseMixin, ViewTestCase):
|
||||
'Im a own place' in response.content.decode(),
|
||||
msg='Expecting the user to see places where their level is high enough'
|
||||
)
|
||||
|
||||
def test_place_mode_filter(self):
|
||||
explorer = User.objects.get(username='testpeter').explorer
|
||||
Place.objects.all().delete()
|
||||
|
||||
for mode in PLACE_MODES:
|
||||
place = Place.objects.create(
|
||||
name='Im a place in mode %s' % mode[0],
|
||||
submitted_when=timezone.now(),
|
||||
submitted_by=explorer,
|
||||
location='Test town',
|
||||
latitude=50.5,
|
||||
longitude=7.0,
|
||||
description='This is just a test, do not worry %s' % mode[0],
|
||||
level=3,
|
||||
mode=mode[0]
|
||||
)
|
||||
|
||||
self.client.login(username='testpeter', password='Develop123')
|
||||
response = self.client.get(reverse('place_list'))
|
||||
|
||||
for mode in PLACE_MODES:
|
||||
if ('Im a place in mode %s' % mode[0]) in response.content.decode():
|
||||
self.assertTrue(
|
||||
mode[0] == 'live',
|
||||
msg='Expecting only places in mode \'live\' to be listed, saw a place in mode %s' % mode[0]
|
||||
)
|
||||
elif mode[0] == 'live':
|
||||
self.fail(
|
||||
msg='Expecting at least one place in mode \'live\' to be listed'
|
||||
)
|
||||
|
||||
|
||||
class TestPlaceCreateView(ViewTestCase):
|
||||
view = PlaceCreateView
|
||||
@@ -209,6 +242,11 @@ class TestPlaceCreateView(ViewTestCase):
|
||||
'success',
|
||||
msg='Expecting a visible success message'
|
||||
)
|
||||
self.assertEqual(
|
||||
Place.objects.get(name='test place 486').mode,
|
||||
'live',
|
||||
msg='Expeting the place to be in \'live\' mode'
|
||||
)
|
||||
|
||||
def test_positive_image(self):
|
||||
self.client.login(username='testpeter', password='Develop123')
|
||||
@@ -258,6 +296,11 @@ class TestPlaceCreateView(ViewTestCase):
|
||||
'success',
|
||||
msg='Expecting a visible success message'
|
||||
)
|
||||
self.assertEqual(
|
||||
Place.objects.get(name='test place 894').mode,
|
||||
'live',
|
||||
msg='Expeting the place to be in \'live\' mode'
|
||||
)
|
||||
|
||||
def test_negative_no_name(self):
|
||||
self.client.login(username='testpeter', password='Develop123')
|
||||
@@ -363,6 +406,31 @@ class TestPlaceCreateView(ViewTestCase):
|
||||
msg='Expecing a visible error message'
|
||||
)
|
||||
|
||||
def test_positve_save_as_draft(self):
|
||||
self.client.login(username='testpeter', password='Develop123')
|
||||
response = self.client.post(
|
||||
reverse('place_create'),
|
||||
{
|
||||
'name': 'test name 6483',
|
||||
'location': 'wurstwasser',
|
||||
'latitude': 45.4654,
|
||||
'longitude': 68.135489,
|
||||
'description': """
|
||||
Cupiditate harum reprehenderit ipsam iure consequuntur eaque eos reiciendis. Blanditiis vel minima minus repudiandae voluptate aut quia sed. Provident ex omnis illo molestiae. Ullam eos et est provident enim deserunt.
|
||||
""",
|
||||
'draft': True
|
||||
},
|
||||
follow=True
|
||||
)
|
||||
|
||||
self.assertHttpOK(response)
|
||||
self.assertEqual(
|
||||
Place.objects.get(name='test name 6483').mode,
|
||||
'draft',
|
||||
msg='Expeting the place to be in \'draft\' mode'
|
||||
)
|
||||
|
||||
|
||||
class PlaceDetailViewTestCase(TaggableViewTestCaseMixin, MapableViewTestCaseMixin, ViewTestCase):
|
||||
view = PlaceDetailView
|
||||
|
||||
@@ -416,6 +484,7 @@ class PlaceDetailViewTestCase(TaggableViewTestCaseMixin, MapableViewTestCaseMixi
|
||||
self.client.login(username='blubberbernd', password='Develop123')
|
||||
response = self.client.get(reverse('place_detail', kwargs={'pk': 1}))
|
||||
|
||||
self.assertHttpForbidden(response)
|
||||
self.assertFalse(
|
||||
'Im a place' in response.content.decode(),
|
||||
msg='Expecting the user to not see the places'
|
||||
@@ -425,6 +494,7 @@ class PlaceDetailViewTestCase(TaggableViewTestCaseMixin, MapableViewTestCaseMixi
|
||||
self.client.login(username='toor', password='Develop123')
|
||||
response = self.client.get(reverse('place_detail', kwargs={'pk': 1}))
|
||||
|
||||
self.assertHttpOK(response)
|
||||
self.assertTrue(
|
||||
'Im a place' in response.content.decode(),
|
||||
msg='Expecting the superuser to see all places'
|
||||
@@ -434,6 +504,7 @@ class PlaceDetailViewTestCase(TaggableViewTestCaseMixin, MapableViewTestCaseMixi
|
||||
self.client.login(username='blubberbernd', password='Develop123')
|
||||
response = self.client.get(reverse('place_detail', kwargs={'pk': 2}))
|
||||
|
||||
self.assertHttpOK(response)
|
||||
self.assertTrue(
|
||||
'Im a own place' in response.content.decode(),
|
||||
msg='Expecting the user to see it\'s own places'
|
||||
@@ -443,6 +514,7 @@ class PlaceDetailViewTestCase(TaggableViewTestCaseMixin, MapableViewTestCaseMixi
|
||||
self.client.login(username='testpeter', password='Develop123')
|
||||
response = self.client.get(reverse('place_detail', kwargs={'pk': 2}))
|
||||
|
||||
self.assertHttpOK(response)
|
||||
self.assertTrue(
|
||||
'Im a own place' in response.content.decode(),
|
||||
msg='Expecting the user to see places where their level is high enough'
|
||||
@@ -605,6 +677,63 @@ class PlaceDetailViewTestCase(TaggableViewTestCaseMixin, MapableViewTestCaseMixi
|
||||
user.explorer not in place.explorer_visits.all(),
|
||||
msg='Expecting the explorer to not be in the reverse list of visits after deleting visit'
|
||||
)
|
||||
|
||||
def test_accessing_place_in_draft(self):
|
||||
user = User.objects.get(username='testpeter')
|
||||
place = Place.objects.create(
|
||||
name='Im a own place in draft 387948',
|
||||
submitted_when=timezone.now(),
|
||||
submitted_by=user.explorer,
|
||||
location='Test %d town' % 5,
|
||||
latitude=50.5 + 5/10,
|
||||
longitude=7.0 - 5/10,
|
||||
description='This is just a test, do not worry %d' % 5,
|
||||
level=3,
|
||||
mode='draft'
|
||||
)
|
||||
|
||||
self.client.login(username='testpeter', password='Develop123')
|
||||
|
||||
response = self.client.get(
|
||||
reverse('place_detail', kwargs={
|
||||
'pk': place.pk
|
||||
})
|
||||
)
|
||||
self.assertHttpOK(response)
|
||||
self.assertTrue(
|
||||
'Im a own place in draft 387948' in response.content.decode(),
|
||||
msg='Expecting the user to see his own place in draft mode'
|
||||
)
|
||||
|
||||
|
||||
self.client.login(username='blubberbernd', password='Develop123')
|
||||
response = self.client.get(
|
||||
reverse('place_detail', kwargs={
|
||||
'pk': place.pk
|
||||
})
|
||||
)
|
||||
self.assertHttpForbidden(response)
|
||||
|
||||
self.client.login(username='toor', password='Develop123')
|
||||
response = self.client.get(
|
||||
reverse('place_detail', kwargs={
|
||||
'pk': place.pk
|
||||
})
|
||||
)
|
||||
self.assertHttpOK(response)
|
||||
self.assertTrue(
|
||||
'Im a own place in draft 387948' in response.content.decode(),
|
||||
msg='Expecting a superuser to see all places in draft mode'
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -14,7 +14,6 @@ from lostplaces.tests.views import (
|
||||
)
|
||||
|
||||
class TestHomeView(GlobalTemplateTestCaseMixin, ViewTestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
user = User.objects.create_user(
|
||||
@@ -33,6 +32,32 @@ class TestHomeView(GlobalTemplateTestCaseMixin, ViewTestCase):
|
||||
)
|
||||
place.tags.add('I a tag', 'testlocation')
|
||||
place.save()
|
||||
|
||||
# Creating a place with level one to test against
|
||||
# unauth's users and users with level 1
|
||||
Place.objects.create(
|
||||
name='Im a place level 1',
|
||||
submitted_when=timezone.now(),
|
||||
submitted_by=user.explorer,
|
||||
location='Testtown',
|
||||
latitude=50.5,
|
||||
longitude=7.0,
|
||||
description='This is just a test, do not worry',
|
||||
level=1
|
||||
)
|
||||
|
||||
# Creating a place with level two to test against
|
||||
# unauth's users and users above level 1
|
||||
Place.objects.create(
|
||||
name='Im a place level 2',
|
||||
submitted_when=timezone.now(),
|
||||
submitted_by=user.explorer,
|
||||
location='Testtown',
|
||||
latitude=50.5,
|
||||
longitude=7.0,
|
||||
description='This is just a test, do not worry',
|
||||
level=2
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
self.client = Client()
|
||||
@@ -80,7 +105,26 @@ class TestHomeView(GlobalTemplateTestCaseMixin, ViewTestCase):
|
||||
),
|
||||
msg='Expecting the test place to show up on the homepage'
|
||||
)
|
||||
|
||||
|
||||
print(response.content.decode().replace('\n', ''))
|
||||
self.assertNotEqual(
|
||||
None,
|
||||
re.search(
|
||||
"""Im a place level 1""",
|
||||
response.content.decode().replace('\n', '')
|
||||
),
|
||||
msg="Expecting the level 1 places to show up on the homepage publicly"
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
None,
|
||||
re.search(
|
||||
"""Im a place level 2""",
|
||||
response.content.decode().replace('\n', '')
|
||||
),
|
||||
msg="Expecting the level 2 places to *not* show up on the homepage publicly"
|
||||
)
|
||||
|
||||
def test_map_authenticated(self):
|
||||
"""
|
||||
Testing there is a map showing all the lates places
|
||||
|
@@ -22,7 +22,11 @@ from lostplaces.views import (
|
||||
PhotoAlbumCreateView,
|
||||
PhotoAlbumDeleteView,
|
||||
ExplorerProfileView,
|
||||
ExplorerProfileUpdateView
|
||||
ExplorerProfileUpdateView,
|
||||
ExplorerDraftsView,
|
||||
PlaceVoteView,
|
||||
UploadMapFileView,
|
||||
ImportDetailView
|
||||
)
|
||||
|
||||
urlpatterns = [
|
||||
@@ -32,6 +36,7 @@ urlpatterns = [
|
||||
|
||||
path('explorer/<int:explorer_id>/', ExplorerProfileView.as_view(), name='explorer_profile'),
|
||||
path('explorer/update/', ExplorerProfileUpdateView.as_view(), name='explorer_profile_update'),
|
||||
path('explorer/<int:explorer_id>/drafts', ExplorerDraftsView.as_view(), name='explorer_drafts'),
|
||||
|
||||
path('place/', PlaceListView.as_view(), name='place_list'),
|
||||
path('place/<int:pk>/', PlaceDetailView.as_view(), name='place_detail'),
|
||||
@@ -47,7 +52,12 @@ urlpatterns = [
|
||||
|
||||
path('place_image/create/<int:place_id>/', PlaceImageCreateView.as_view(), name='place_image_create'),
|
||||
path('place_image/delete/<int:pk>/', PlaceImageDeleteView.as_view(), name='place_image_delete'),
|
||||
|
||||
path('place/vote/<int:place_id>/<int:vote>', PlaceVoteView.as_view(), name='place_vote'),
|
||||
|
||||
path('photo_album/create/<int:place_id>/', PhotoAlbumCreateView.as_view(), name='photo_album_create'),
|
||||
path('photo_album/delete/<int:pk>/', PhotoAlbumDeleteView.as_view(), name='photo_album_delete')
|
||||
path('photo_album/delete/<int:pk>/', PhotoAlbumDeleteView.as_view(), name='photo_album_delete'),
|
||||
|
||||
path('import/upload', UploadMapFileView.as_view(), name='import_upload'),
|
||||
path('import/<int:pk>', ImportDetailView.as_view(), name='import_detail')
|
||||
]
|
||||
|
@@ -5,4 +5,5 @@ from lostplaces.views.base_views import *
|
||||
from lostplaces.views.views import *
|
||||
from lostplaces.views.place_views import *
|
||||
from lostplaces.views.place_image_views import *
|
||||
from lostplaces.views.explorer_views import *
|
||||
from lostplaces.views.explorer_views import *
|
||||
from lostplaces.views.imports import *
|
@@ -12,7 +12,7 @@ from django.contrib.messages.views import SuccessMessageMixin
|
||||
|
||||
from django.shortcuts import redirect, get_object_or_404
|
||||
from django.urls import reverse_lazy, reverse
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from lostplaces.models import Place
|
||||
from lostplaces.common import redirect_referer_or
|
||||
@@ -31,6 +31,21 @@ class IsAuthenticatedMixin(LoginRequiredMixin, View):
|
||||
messages.error(self.request, self.permission_denied_message)
|
||||
return super().handle_no_permission()
|
||||
|
||||
class IsSuperUserMixin(UserPassesTestMixin, View):
|
||||
'''
|
||||
A view mixin that checks if the user is a superuser.
|
||||
Users who are not logged in or users who are no superuser get
|
||||
a permission deined message.
|
||||
'''
|
||||
permission_denied_message = _('You are not allowed to see this page')
|
||||
|
||||
def test_func(self):
|
||||
return self.request.user.is_superuser
|
||||
|
||||
def handle_no_permission(self):
|
||||
messages.error(self.request, self.permission_denied_message)
|
||||
return super().handle_no_permission()
|
||||
|
||||
class IsPlaceSubmitterMixin(UserPassesTestMixin, View):
|
||||
'''
|
||||
A view mixin that checks wether a user is the submitter
|
||||
@@ -138,4 +153,10 @@ class LevelCapPlaceListView(ListView):
|
||||
model = Place
|
||||
|
||||
def get_queryset(self):
|
||||
return self.request.user.explorer.get_places_eligible_to_see()
|
||||
return self.request.user.explorer.get_place_list_to_display()
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['place_list'] = context.pop('object_list')
|
||||
return context
|
||||
|
@@ -3,11 +3,12 @@
|
||||
|
||||
from django.views import View
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from django.shortcuts import render, redirect, get_object_or_404
|
||||
from django.urls import reverse_lazy
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.mixins import UserPassesTestMixin
|
||||
|
||||
from lostplaces.common import get_all_subclasses
|
||||
from lostplaces.views.base_views import IsAuthenticatedMixin
|
||||
@@ -18,7 +19,7 @@ from lostplaces.forms import ExplorerChangeForm, ExplorerUserChangeForm
|
||||
class ExplorerProfileView(IsAuthenticatedMixin, View):
|
||||
def get(self, request, explorer_id):
|
||||
explorer = get_object_or_404(Explorer, pk=explorer_id)
|
||||
place_list = explorer.places.all()
|
||||
place_list = explorer.get_place_list_to_display()
|
||||
place_count = place_list.count()
|
||||
|
||||
context={
|
||||
@@ -81,4 +82,21 @@ class ExplorerProfileUpdateView(IsAuthenticatedMixin, View):
|
||||
_('Please fill in all required fields.')
|
||||
)
|
||||
return redirect(reverse_lazy('explorer_profile_update'))
|
||||
|
||||
|
||||
class ExplorerDraftsView(IsAuthenticatedMixin, UserPassesTestMixin, View):
|
||||
|
||||
def get_explorer(self):
|
||||
return get_object_or_404(Explorer, pk=self.kwargs['explorer_id'])
|
||||
|
||||
def test_func(self):
|
||||
if not hasattr(self.request, 'user'):
|
||||
return False
|
||||
return self.request.user == self.get_explorer().user or self.request.user.is_superuser
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
context = {
|
||||
'explorer': self.get_explorer(),
|
||||
'place_list': self.get_explorer().get_drafts()
|
||||
}
|
||||
return render(request, 'explorer/drafts.html', context)
|
||||
|
91
django_lostplaces/lostplaces/views/imports.py
Normal file
91
django_lostplaces/lostplaces/views/imports.py
Normal file
@@ -0,0 +1,91 @@
|
||||
from django.views import View
|
||||
from django.shortcuts import render, redirect, get_object_or_404
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext as _
|
||||
from django.core.paginator import Paginator
|
||||
|
||||
from pykml import parser as kml_parser
|
||||
|
||||
from lostplaces.forms import UploadMapFileForm
|
||||
from lostplaces.models import Place, PlaceImport
|
||||
from lostplaces.views.base_views import (
|
||||
IsSuperUserMixin
|
||||
)
|
||||
|
||||
class UploadMapFileView(IsSuperUserMixin, View):
|
||||
permission_denied_message = _('You are not allowed to import any places')
|
||||
|
||||
def get(self, request):
|
||||
upload_form = UploadMapFileForm()
|
||||
return render(request, 'import/upload_map_file.html', {'upload_form': upload_form})
|
||||
|
||||
def post(self, request):
|
||||
upload_form = UploadMapFileForm(request.POST, request.FILES)
|
||||
explorer = request.user.explorer
|
||||
|
||||
if upload_form.is_valid():
|
||||
map_file = upload_form.cleaned_data['map_file']
|
||||
parsed_kml = kml_parser.fromstring(map_file.read())
|
||||
|
||||
place_import = PlaceImport.objects.create(
|
||||
explorer=request.user.explorer,
|
||||
description=upload_form.cleaned_data['description']
|
||||
)
|
||||
|
||||
for folder in parsed_kml.Document.Folder:
|
||||
for place_kml in folder.Placemark:
|
||||
lat_long = self.get_lat_long(place_kml)
|
||||
|
||||
name = str(place_kml.name) if hasattr(place_kml, 'name') else ''
|
||||
description = str(place_kml.description) if hasattr(place_kml, 'description') else ''
|
||||
|
||||
place_model = Place.objects.create(
|
||||
name=name.strip(),
|
||||
latitude=lat_long[0],
|
||||
longitude=lat_long[1],
|
||||
description=description.strip(),
|
||||
place_import=place_import,
|
||||
mode='imported'
|
||||
)
|
||||
|
||||
place_import.save()
|
||||
|
||||
return redirect(reverse('lostplaces_home'))
|
||||
|
||||
def get_lat_long(self, place_kml):
|
||||
if hasattr(place_kml, 'Point') and len(place_kml.Point.coordinates) >= 1:
|
||||
coordinates = str(place_kml.Point.coordinates[0]).strip()
|
||||
splited = coordinates.split(',')
|
||||
latitude = 0
|
||||
longitude = 0
|
||||
|
||||
if len(splited) >= 1:
|
||||
longitude = splited[0]
|
||||
if len(splited) >= 2:
|
||||
latitude = splited[1]
|
||||
|
||||
return (latitude, longitude)
|
||||
else:
|
||||
return (0, 0)
|
||||
|
||||
class ImportDetailView(IsSuperUserMixin, View):
|
||||
permission_denied_message = _('You are not allowed to see this import\'s details')
|
||||
|
||||
def get_import(self):
|
||||
return get_object_or_404(PlaceImport, pk=self.kwargs['pk'])
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
place_import = self.get_import()
|
||||
|
||||
place_paginator = Paginator(place_import.place_list.all(), 18)
|
||||
paginated_places = place_paginator.get_page(
|
||||
request.GET.get('page')
|
||||
)
|
||||
context = {
|
||||
'import': place_import,
|
||||
'paginated_places': paginated_places,
|
||||
'import_type': place_import.get_import_type_display()
|
||||
}
|
||||
|
||||
return render(request, 'import/import_detail_view.html', context)
|
||||
|
@@ -1,6 +1,6 @@
|
||||
from django.views import View
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from lostplaces.views.base_views import PlaceAssetCreateView, PlaceAssetDeleteView
|
||||
from lostplaces.models import PlaceImage, Place
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
from datetime import timedelta
|
||||
|
||||
from django.db.models.functions import Lower
|
||||
|
||||
@@ -9,12 +10,19 @@ from django.views.generic.detail import SingleObjectMixin
|
||||
|
||||
from django.contrib import messages
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import gettext as _
|
||||
from django.utils import timezone
|
||||
|
||||
from django.shortcuts import render, redirect, get_object_or_404
|
||||
from django.urls import reverse_lazy, reverse
|
||||
|
||||
from lostplaces.models import Place, PlaceImage
|
||||
from lostplaces.models import (
|
||||
Place,
|
||||
PlaceImage,
|
||||
PlaceVoting,
|
||||
PLACE_LEVELS
|
||||
)
|
||||
|
||||
from lostplaces.views.base_views import (
|
||||
IsAuthenticatedMixin,
|
||||
IsPlaceSubmitterMixin,
|
||||
@@ -28,7 +36,7 @@ from lostplaces.common import redirect_referer_or
|
||||
from taggit.models import Tag
|
||||
|
||||
class PlaceListView(IsAuthenticatedMixin, LevelCapPlaceListView):
|
||||
paginate_by = 5
|
||||
paginate_by = 18
|
||||
template_name = 'place/place_list.html'
|
||||
ordering = [Lower('name')]
|
||||
|
||||
@@ -46,8 +54,21 @@ class PlaceDetailView(IsAuthenticatedMixin, IsEligibleToSeePlaceMixin, View):
|
||||
def get_place(self):
|
||||
return get_object_or_404(Place, pk=self.kwargs['pk'])
|
||||
|
||||
def get(self, request, pk):
|
||||
def get(self, request, pk):
|
||||
place = self.get_place()
|
||||
place.calculate_place_level()
|
||||
explorer = request.user.explorer
|
||||
|
||||
if place.mode == 'draft':
|
||||
messages.info(
|
||||
self.request,
|
||||
_('This place is still in draft mode and only visible to the submitter and superusers')
|
||||
)
|
||||
elif place.mode == 'imported':
|
||||
messages.info(
|
||||
self.request,
|
||||
_('This place was imported and not reviewed & correted yet. This place is visbible for superusers only and does not appear in the list views.')
|
||||
)
|
||||
|
||||
context = {
|
||||
'place': place,
|
||||
@@ -61,6 +82,11 @@ class PlaceDetailView(IsAuthenticatedMixin, IsEligibleToSeePlaceMixin, View):
|
||||
'tagged_item': place,
|
||||
'submit_url': reverse('place_tag_submit', kwargs={'tagged_id': place.id}),
|
||||
'delete_url_name': 'place_tag_delete'
|
||||
},
|
||||
'placevoting': {
|
||||
'users_vote': PlaceVoting.objects.filter(place=place, submitted_by=explorer).first(),
|
||||
'all_choices': reversed(PLACE_LEVELS),
|
||||
'accuracy': place.calculate_voting_accuracy()
|
||||
}
|
||||
}
|
||||
return render(request, 'place/place_detail.html', context)
|
||||
@@ -98,6 +124,9 @@ class PlaceCreateView(MultiplePlaceImageUploadMixin, IsAuthenticatedMixin, View)
|
||||
place = place_form.save(commit=False)
|
||||
# Save logged in user as "submitted_by"
|
||||
place.submitted_by = submitter
|
||||
if place_form.cleaned_data['draft']:
|
||||
place.mode = 'draft';
|
||||
|
||||
place.save()
|
||||
|
||||
self.handle_place_images(request, place)
|
||||
@@ -185,3 +214,34 @@ class PlaceVisitDeleteView(IsAuthenticatedMixin, View):
|
||||
request.user.explorer.save()
|
||||
|
||||
return redirect_referer_or(request, reverse('place_detail', kwargs={'pk': place.pk}))
|
||||
|
||||
|
||||
class PlaceVoteView(IsEligibleToSeePlaceMixin, View):
|
||||
delta = timedelta(weeks=24)
|
||||
|
||||
def get_place(self):
|
||||
return get_object_or_404(Place, pk=self.kwargs['place_id'])
|
||||
|
||||
def get(self, request, place_id, vote):
|
||||
place = self.get_place()
|
||||
explorer = request.user.explorer
|
||||
|
||||
voting = PlaceVoting.objects.filter(
|
||||
submitted_by=explorer,
|
||||
place=place
|
||||
).first()
|
||||
|
||||
if voting is None:
|
||||
voting = PlaceVoting.objects.create(
|
||||
submitted_by=explorer,
|
||||
place=place,
|
||||
vote=vote
|
||||
)
|
||||
messages.success(self.request, _('Vote submitted'))
|
||||
else:
|
||||
voting.submitted_when = timezone.now()
|
||||
voting.vote = vote
|
||||
messages.success(self.request, _('Your vote has been update'))
|
||||
|
||||
voting.save()
|
||||
return redirect_referer_or(request, reverse('place_detail', kwargs={'pk': place.pk}))
|
@@ -9,11 +9,11 @@ from django.contrib import messages
|
||||
from django.urls import reverse_lazy, reverse
|
||||
from django.shortcuts import render, redirect, get_object_or_404
|
||||
from django.http import HttpResponseForbidden
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from lostplaces.forms import SignupVoucherForm, TagSubmitForm
|
||||
from lostplaces.models import Place, PhotoAlbum
|
||||
from lostplaces.views.base_views import IsAuthenticatedMixin
|
||||
from lostplaces.views.base_views import IsAuthenticatedMixin, LevelCapPlaceListView
|
||||
from lostplaces.common import redirect_referer_or
|
||||
|
||||
from lostplaces.views.base_views import (
|
||||
@@ -29,20 +29,22 @@ class SignUpView(SuccessMessageMixin, CreateView):
|
||||
template_name = 'signup.html'
|
||||
success_message = _('User created')
|
||||
|
||||
class HomeView(IsAuthenticatedMixin, View):
|
||||
def get(self, request, *args, **kwargs):
|
||||
place_list = request.user.explorer.get_places_eligible_to_see()
|
||||
context = {
|
||||
'place_list': place_list,
|
||||
'mapping_config': {
|
||||
'all_points': place_list,
|
||||
'map_center': Place.average_latlon(place_list)
|
||||
}
|
||||
class HomeView(IsAuthenticatedMixin, LevelCapPlaceListView, View):
|
||||
template_name = 'home.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
place_list = context['place_list']
|
||||
|
||||
context['mapping_config'] = {
|
||||
'all_points': place_list,
|
||||
'map_center': Place.average_latlon(place_list)
|
||||
}
|
||||
return render(request, 'home.html', context)
|
||||
return context
|
||||
|
||||
|
||||
def handle_no_permission(self):
|
||||
place_list = Place.objects.all().order_by('-submitted_when')[:5]
|
||||
place_list = Place.objects.filter(level=1)[:5]
|
||||
context = {
|
||||
'place_list': place_list
|
||||
}
|
||||
|
@@ -6,13 +6,15 @@ from setuptools import setup, find_packages
|
||||
with open('Readme.md') as f:
|
||||
readme = f.read()
|
||||
|
||||
# Keep PEP 440 for version identification in mind
|
||||
# https://www.python.org/dev/peps/pep-0440/#post-releases
|
||||
setup(
|
||||
name='django-lostplaces',
|
||||
version='0.1.3',
|
||||
version='0.1.4.post2',
|
||||
description='A django app to manage lost places',
|
||||
author='Reverend',
|
||||
author_email='reverend@reverend2048.de',
|
||||
url='https://git.mowoe.com/reverend/lostplaces-backend',
|
||||
author='Reverend, Commander1024',
|
||||
author_email='reverend@reverend2048.de, commander@commander1024.de',
|
||||
url='https://git.commander1024.de/Commander1024/lostplaces-backend',
|
||||
packages=find_packages(exclude=['django_lostplaces']),
|
||||
long_description=readme,
|
||||
long_description_content_type='text/markdown',
|
||||
@@ -33,4 +35,4 @@ setup(
|
||||
],
|
||||
include_package_data=True,
|
||||
license='MIT'
|
||||
)
|
||||
)
|
23
tasks.py
Normal file
23
tasks.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from invoke import task
|
||||
|
||||
@task
|
||||
def quickstart(c):
|
||||
commands = [
|
||||
'pipenv run collectstatic',
|
||||
'pipenv run migrate',
|
||||
'pipenv run createsuperuser',
|
||||
'pipenv run server'
|
||||
]
|
||||
c.run(' && '.join(commands))
|
||||
|
||||
@task
|
||||
def live(c):
|
||||
commands = [
|
||||
'pipenv check',
|
||||
'pipenv run test',
|
||||
'pipenv run collectstatic',
|
||||
'pipenv run migrate',
|
||||
'pipenv run createsuperuser_prompt'
|
||||
'pipenv run server'
|
||||
]
|
||||
c.run(' && '.join(commands))
|
Reference in New Issue
Block a user