Compare commits
No commits in common. "5f33ec5824be45be14a26f12c7c217f756703bad" and "b4bd86ed44f17431aca6f05212fd49f263b3fa2b" have entirely different histories.
5f33ec5824
...
b4bd86ed44
@ -94,23 +94,9 @@
|
||||
<ul class="LP-ImageGrid__Container">
|
||||
{% for place_image in place.placeimages.all %}
|
||||
<li class="LP-ImageGrid__Item">
|
||||
<a href="{{ place_image.filename.large.url }}" class="LP-Link">
|
||||
<img class="LP-Image" src="{{ place_image.filename.thumbnail.url }}">
|
||||
</a>
|
||||
{% if user.explorer == place_image.submitted_by or user.explorer == place.submitted_by %}
|
||||
<span class="LP-ImageGrid__DeleteItem" title="Bild löschen">
|
||||
<a href="{% url 'place_image_delete' pk=place_image.id %}" class="LP-Link">
|
||||
<img class="LP-Icon" src="{% static 'icons/cancel.svg' %}" />
|
||||
</a>
|
||||
</span>
|
||||
{% endif %}
|
||||
<a href="{{ place_image.filename.large.url }}" class="LP-Link"><img class="LP-Image" src="{{ place_image.filename.thumbnail.url }}"></a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
<li class="LP-ImageGrid__Item LP-ImageGrid__Item--add" title="Bild hinzufügen">
|
||||
<a class="LP-Link" href="{% url 'place_image_create' place_id=place.id%}">
|
||||
<img class="LP-Icon" src="{% static 'icons/plus.svg' %}" />
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
|
@ -14,7 +14,6 @@ from lostplaces.views import (
|
||||
PhotoAlbumCreateView,
|
||||
PhotoAlbumDeleteView,
|
||||
PlaceImageCreateView,
|
||||
PlaceImageDeleteView,
|
||||
FlatView
|
||||
)
|
||||
|
||||
@ -28,7 +27,6 @@ urlpatterns = [
|
||||
path('place/delete/<int:pk>/', PlaceDeleteView.as_view(), name='place_delete'),
|
||||
path('place/', PlaceListView.as_view(), name='place_list'),
|
||||
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('flat/<slug:slug>/', FlatView, name='flatpage'),
|
||||
|
||||
# POST-only URLs for tag submission
|
||||
|
@ -60,6 +60,7 @@ class IsPlaceSubmitterMixin(UserPassesTestMixin, View):
|
||||
|
||||
class PlaceAssetCreateView(IsAuthenticatedMixin, SuccessMessageMixin, CreateView):
|
||||
model = None
|
||||
fields = []
|
||||
template_name = ''
|
||||
success_message = ''
|
||||
|
||||
|
@ -1,43 +1,18 @@
|
||||
from django.views import View
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
||||
from lostplaces.views.base_views import PlaceAssetCreateView, PlaceAssetDeleteView
|
||||
from lostplaces.views.base_views import PlaceAssetCreateView
|
||||
from lostplaces.models import PlaceImage, Place
|
||||
from lostplaces.forms import PlaceImageForm
|
||||
|
||||
class MultiplePlaceImageUploadMixin:
|
||||
|
||||
def handle_place_images(self, request, place):
|
||||
if request.FILES:
|
||||
submitted_by = request.user.explorer
|
||||
for image in request.FILES.getlist('filename'):
|
||||
place_image = PlaceImage.objects.create(
|
||||
filename=image,
|
||||
place=place,
|
||||
submitted_by=submitted_by
|
||||
)
|
||||
place_image.save()
|
||||
|
||||
class PlaceImageCreateView(MultiplePlaceImageUploadMixin, PlaceAssetCreateView):
|
||||
class PlaceImageCreateView(PlaceAssetCreateView):
|
||||
model = PlaceImage
|
||||
form_class = PlaceImageForm
|
||||
fields = ['filename']
|
||||
template_name = 'place_image/place_image_create.html'
|
||||
success_message = 'Place Images submitted'
|
||||
commit = False
|
||||
|
||||
def post(self, request, place_id, *args, **kwargs):
|
||||
self.place = get_object_or_404(Place, pk=place_id)
|
||||
self.handle_place_images(request, self.place)
|
||||
return redirect(self.get_success_url())
|
||||
|
||||
def form_valid(self, form):
|
||||
form.instance.place = self.place
|
||||
form.instance.submitted_by = self.request.user.explorer
|
||||
return super().form_valid(form)
|
||||
|
||||
class PlaceImageDeleteView(PlaceAssetDeleteView):
|
||||
model = PlaceImage
|
||||
success_message = 'Images deleted successfully'
|
||||
permission_denied_message = 'You\'r not allowed to delete this image'
|
||||
|
||||
|
||||
place = get_object_or_404(Place, pk=place_id)
|
||||
super().post(request, place_id)
|
||||
self.object.place = place
|
||||
self.object = self.request.user
|
||||
self.object.save()
|
@ -13,8 +13,7 @@ from django.shortcuts import render, redirect, get_object_or_404
|
||||
from django.urls import reverse_lazy
|
||||
|
||||
from lostplaces.models import Place, PlaceImage
|
||||
from lostplaces.views.base_views import IsAuthenticatedMixin, IsPlaceSubmitterMixin
|
||||
from lostplaces.views.place_image_views import MultiplePlaceImageUploadMixin
|
||||
from lostplaces.views import IsAuthenticatedMixin, IsPlaceSubmitterMixin
|
||||
from lostplaces.forms import PlaceForm, PlaceImageForm, TagSubmitForm
|
||||
|
||||
from taggit.models import Tag
|
||||
@ -65,7 +64,7 @@ class PlaceUpdateView(IsAuthenticatedMixin, IsPlaceSubmitterMixin, SuccessMessag
|
||||
def get_place(self):
|
||||
return self.get_object()
|
||||
|
||||
class PlaceCreateView(MultiplePlaceImageUploadMixin, IsAuthenticatedMixin, View):
|
||||
class PlaceCreateView(IsAuthenticatedMixin, View):
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
place_image_form = PlaceImageForm()
|
||||
@ -87,7 +86,12 @@ class PlaceCreateView(MultiplePlaceImageUploadMixin, IsAuthenticatedMixin, View)
|
||||
place.submitted_by = submitter
|
||||
place.save()
|
||||
|
||||
self.handle_place_images(request, place)
|
||||
if request.FILES:
|
||||
self._apply_multipart_image_upload(
|
||||
files=request.FILES.getlist('filename'),
|
||||
place=place,
|
||||
submitter=submitter
|
||||
)
|
||||
|
||||
messages.success(
|
||||
self.request,
|
||||
@ -103,6 +107,15 @@ class PlaceCreateView(MultiplePlaceImageUploadMixin, IsAuthenticatedMixin, View)
|
||||
)
|
||||
return render(request, 'place/place_create.html', context={'form': place_form})
|
||||
|
||||
def _apply_multipart_image_upload(self, files, place, submitter):
|
||||
for image in files:
|
||||
place_image = PlaceImage.objects.create(
|
||||
filename=image,
|
||||
place=place,
|
||||
submitted_by=submitter
|
||||
)
|
||||
place_image.save()
|
||||
|
||||
class PlaceDeleteView(IsAuthenticatedMixin, IsPlaceSubmitterMixin, DeleteView):
|
||||
template_name = 'place/place_delete.html'
|
||||
model = Place
|
||||
|
Loading…
Reference in New Issue
Block a user