From b4bd86ed44f17431aca6f05212fd49f263b3fa2b Mon Sep 17 00:00:00 2001 From: reverend Date: Sat, 26 Sep 2020 09:48:06 +0200 Subject: [PATCH] View for submitting additionale place images --- .../place_image/place_image_create.html | 28 +++++++++++++++++++ django_lostplaces/lostplaces/urls.py | 2 ++ .../lostplaces/views/__init__.py | 3 +- .../lostplaces/views/place_image_views.py | 18 ++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 django_lostplaces/lostplaces/templates/place_image/place_image_create.html create mode 100644 django_lostplaces/lostplaces/views/place_image_views.py diff --git a/django_lostplaces/lostplaces/templates/place_image/place_image_create.html b/django_lostplaces/lostplaces/templates/place_image/place_image_create.html new file mode 100644 index 0000000..1b5c3e9 --- /dev/null +++ b/django_lostplaces/lostplaces/templates/place_image/place_image_create.html @@ -0,0 +1,28 @@ +{% extends 'global.html'%} + +{% block maincontent %} +
+
+ Submit images to an place + {% csrf_token %} + +
+
+ {% include 'partials/form/inputField.html' with field=form.filename %} +
+
+ +
+
+ +
+ +
+
+ +
+{% endblock maincontent %} \ No newline at end of file diff --git a/django_lostplaces/lostplaces/urls.py b/django_lostplaces/lostplaces/urls.py index da2c61a..0a00914 100644 --- a/django_lostplaces/lostplaces/urls.py +++ b/django_lostplaces/lostplaces/urls.py @@ -13,6 +13,7 @@ from lostplaces.views import ( PlaceTagSubmitView, PhotoAlbumCreateView, PhotoAlbumDeleteView, + PlaceImageCreateView, FlatView ) @@ -25,6 +26,7 @@ urlpatterns = [ path('place/update//', PlaceUpdateView.as_view(), name='place_edit'), path('place/delete//', PlaceDeleteView.as_view(), name='place_delete'), path('place/', PlaceListView.as_view(), name='place_list'), + path('place_image/create/', PlaceImageCreateView.as_view(), name='place_image_create'), path('flat//', FlatView, name='flatpage'), # POST-only URLs for tag submission diff --git a/django_lostplaces/lostplaces/views/__init__.py b/django_lostplaces/lostplaces/views/__init__.py index f4743f1..97115d5 100644 --- a/django_lostplaces/lostplaces/views/__init__.py +++ b/django_lostplaces/lostplaces/views/__init__.py @@ -3,4 +3,5 @@ from lostplaces.views.base_views import * from lostplaces.views.views import * -from lostplaces.views.place_views import * \ No newline at end of file +from lostplaces.views.place_views import * +from lostplaces.views.place_image_views import * \ No newline at end of file diff --git a/django_lostplaces/lostplaces/views/place_image_views.py b/django_lostplaces/lostplaces/views/place_image_views.py new file mode 100644 index 0000000..d9f7d3c --- /dev/null +++ b/django_lostplaces/lostplaces/views/place_image_views.py @@ -0,0 +1,18 @@ +from django.views import View +from django.shortcuts import get_object_or_404 + +from lostplaces.views.base_views import PlaceAssetCreateView +from lostplaces.models import PlaceImage, Place + +class PlaceImageCreateView(PlaceAssetCreateView): + model = PlaceImage + fields = ['filename'] + template_name = 'place_image/place_image_create.html' + success_message = 'Place Images submitted' + + def post(self, request, place_id, *args, **kwargs): + 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() \ No newline at end of file