12 Commits

Author SHA1 Message Date
Leonhard Strohmidel
8597e53599 #63 Replacing vote expiration with vote accuarcy 2022-09-20 09:56:23 +02:00
Leonhard Strohmidel
d213b51a59 Fixing Typo 2022-09-20 09:53:00 +02:00
Leonhard Strohmidel
9c50e5891f Removing Partial TemplateTag 2022-09-17 21:22:51 +02:00
Leonhard Strohmidel
72094494eb Replacing url with re_path 2022-09-17 18:16:35 +02:00
Leonhard Strohmidel
c483c3511d Replacing ugettext_lazy with gettext 2022-09-17 18:07:29 +02:00
14effd33e2 Adding collectstatic to the quickstart script 2022-01-14 12:39:57 +01:00
19300614bc Added local ip's to allowed_hosts 2022-01-14 12:37:21 +01:00
830120a929 #59 Pictures are in the wrong directory 2022-01-13 17:23:57 +01:00
ddd0f8c903 Merge branch 'master' into develop 2022-01-01 13:44:04 +01:00
f078afcdcd Env file 2022-01-01 13:43:24 +01:00
d5f6a00219 Fixin Metadata 2022-01-01 00:07:43 +01:00
f376951ff9 No migrations in develop branch 2021-12-31 23:42:49 +01:00
26 changed files with 107 additions and 67 deletions

1
.env Normal file
View File

@@ -0,0 +1 @@
DJANGO_SUPERUSER_PASSWORD=develop

7
.gitignore vendored
View File

@@ -79,7 +79,6 @@ Pipfile.lock
__pypackages__/
# Environments
.env
.venv
env/
venv/
@@ -92,3 +91,9 @@ venv.bak/
# twine / pypi
.pypirc
# Django Migrations for Development branches
django_lostplaces/lostplaces/migrations/*
# Django Static files
django_lostplaces/static/*

View File

@@ -30,6 +30,7 @@ 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"

Binary file not shown.

View File

@@ -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

View File

@@ -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})
]

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -1,11 +1,14 @@
import os
from math import floor
import datetime
from math import round, 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, Expireable
@@ -91,8 +94,6 @@ class Place(Submittable, Taggable, Mapable):
return {'latitude': latitude, 'longitude': longitude}
def calculate_place_level(self):
self.remove_expired_votes()
if self.placevotings.count() == 0:
self.level = 5
self.save()
@@ -103,13 +104,19 @@ class Place(Submittable, Taggable, Mapable):
for vote in self.placevotings.all():
level += vote.vote
self.level = floor(level / self.placevotings.count())
self.level = round(level / self.placevotings.count())
self.save()
def remove_expired_votes(self):
def calculate_voting_accuracy(self):
place_age = timezone.now() - self.submitted_when;
accuaries = [];
for vote in self.placevotings.all():
if vote.is_expired:
vote.delete()
vote_age = timezone.now() - vote.created_when;
accuracy = 100 - (100 / (place_age / vote_age))
accuaries.append(accuracy)
return ceil(sum(accuaries) / len(accuaries))
def __str__(self):
return self.name
@@ -120,7 +127,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)

View File

@@ -89,7 +89,7 @@
</div>
{% block footer %}
{% partial 'nav/footer' %}
{% include 'partials/nav/footer.html' %}
{% endblock footer %}
</body>

View File

@@ -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">

View File

@@ -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">

View File

@@ -28,12 +28,7 @@
</div>
<div class="LP-Voting__Expiration">
<span class="LP-Voting__InfoLabel">Your vote expires on</span>
<span class="LP-Voting__Date">
<time datetime="{{voting.expires_when|date:'Y-m-d'}}">
{{voting.users_vote.expires_when|date:'d.m.Y'}}
</time>
</span>
The accuracy of the voting is {{voting.accuracy}}%
</div>
</div>
</div>

View File

@@ -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>
@@ -43,23 +46,18 @@
<div class="LP-Quickinfo">
<section class="LP-Section">
{% url 'place_tag_submit' place_id=place.id as tag_submit_url %}
{% partial tagging %}
{% set config=tagging_config %}
{% endpartial %}
{% include '../partials/tagging.html' with config=tagging_config %}
</section>
{{votingplace.vote}}
<section class="LP-Section">
{% partial voting %}
{% set place=place %}
{% set voting=placevoting %}
{% endpartial %}
{% 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 %}
{% 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">
@@ -137,7 +135,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>

View File

@@ -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>

View File

@@ -124,3 +124,31 @@ class PlaceTestCase(ModelTestCase):
self.model.__name__
)
)
def test_level_calculation(self):
place = self.place
explorer = place.submitted_by
PlaceVoting.objects.create(
submitted_by=explorer,
place=place,
vote=5,
expires_when=timezone.now()+self.delta
)
PlaceVoting.objects.create(
submitted_by=explorer,
place=place,
vote=2,
expires_when=timezone.now()+self.delta
)
PlaceVoting.objects.create(
submitted_by=explorer,
place=place,
vote=4,
expires_when=timezone.now()+self.delta
)
self.assertEqual(
4,
place.calculate_place_level()
)

View File

@@ -9,7 +9,7 @@ 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

View File

@@ -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

View File

@@ -3,7 +3,7 @@
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

View File

@@ -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

View File

@@ -10,7 +10,7 @@ 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
@@ -74,7 +74,8 @@ class PlaceDetailView(IsAuthenticatedMixin, IsEligibleToSeePlaceMixin, View):
},
'placevoting': {
'users_vote': PlaceVoting.objects.filter(place=place, submitted_by=explorer).first(),
'all_choices': reversed(PLACE_LEVELS)
'all_choices': reversed(PLACE_LEVELS),
'accuracy': place.calculate_voting_accuracy()
}
}
return render(request, 'place/place_detail.html', context)
@@ -204,8 +205,11 @@ class PlaceVisitDeleteView(IsAuthenticatedMixin, View):
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 = get_object_or_404(Place, id=place_id)
place = self.get_place()
explorer = request.user.explorer
voting = PlaceVoting.objects.filter(

View File

@@ -9,7 +9,7 @@ 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

View File

@@ -10,11 +10,11 @@ with open('Readme.md') as f:
# https://www.python.org/dev/peps/pep-0440/#post-releases
setup(
name='django-lostplaces',
version='0.1.4.post1',
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',

View File

@@ -3,6 +3,7 @@ from invoke import task
@task
def quickstart(c):
commands = [
'pipenv run collectstatic',
'pipenv run migrate',
'pipenv run createsuperuser',
'pipenv run server'
@@ -14,6 +15,7 @@ def live(c):
commands = [
'pipenv check',
'pipenv run test',
'pipenv run collectstatic',
'pipenv run migrate',
'pipenv run createsuperuser_prompt'
'pipenv run server'