diff --git a/django_lostplaces/lostplaces/views/explorer_views.py b/django_lostplaces/lostplaces/views/explorer_views.py index 9faf5b1..e3f8318 100644 --- a/django_lostplaces/lostplaces/views/explorer_views.py +++ b/django_lostplaces/lostplaces/views/explorer_views.py @@ -47,8 +47,35 @@ class ExplorerProfileUpdateView(IsAuthenticatedMixin, View): def get(self, request, *args, **kwargs): context = { - 'explorer_image_url': request.user.explorer.profile_image.url, 'explorer_user_change_form': ExplorerUserChangeForm(instance=request.user), 'explorer_change_form': ExplorerChangeForm(instance=request.user.explorer) } + if request.user.explorer.profile_image: + context['explorer_image_url'] = request.user.explorer.profile_image.url return render(request, 'explorer/profile_update.html', context) + + def post(self, request, *args, **kwargs): + explorer_change_form = ExplorerChangeForm(request.POST) + + if place_form.is_valid(): + submitter = request.user.explorer + place = place_form.save(commit=False) + # Save logged in user as "submitted_by" + place.submitted_by = submitter + place.save() + + self.handle_place_images(request, place) + + messages.success( + self.request, + _('Successfully created place') + ) + return redirect(reverse_lazy('place_detail', kwargs={'pk': place.pk})) + + else: + # Usually the browser should have checked the form before sending. + messages.error( + self.request, + _('Please fill in all required fields.') + ) + return render(request, 'place/place_create.html', context={'form': place_form}) \ No newline at end of file