From 0f5474c2d3c83479447c933a8644ce73de2aa52b Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Fri, 25 Dec 2020 11:14:21 +0100 Subject: [PATCH] half-working :P --- .../lostplaces/views/explorer_views.py | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/django_lostplaces/lostplaces/views/explorer_views.py b/django_lostplaces/lostplaces/views/explorer_views.py index e3f8318..6773f07 100644 --- a/django_lostplaces/lostplaces/views/explorer_views.py +++ b/django_lostplaces/lostplaces/views/explorer_views.py @@ -7,6 +7,7 @@ from django.utils.translation import ugettext_lazy as _ from django.shortcuts import render, redirect, get_object_or_404 from django.urls import reverse_lazy +from django.contrib import messages from lostplaces.common import get_all_subclasses from lostplaces.views.base_views import IsAuthenticatedMixin @@ -55,22 +56,21 @@ class ExplorerProfileUpdateView(IsAuthenticatedMixin, View): return render(request, 'explorer/profile_update.html', context) def post(self, request, *args, **kwargs): - explorer_change_form = ExplorerChangeForm(request.POST) + explorer_user_change_form = ExplorerUserChangeForm(request.POST, instance=request.user) + explorer_change_form = ExplorerChangeForm(request.POST, instance=request.user.explorer) - 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() + if explorer_change_form.is_valid() and explorer_user_change_form.is_valid(): + print(explorer_user_change_form) + explorer_user_change_form.save() + explorer_change_form.save() - self.handle_place_images(request, place) + #self.handle_place_images(request, explorer) messages.success( self.request, - _('Successfully created place') + _('Successfully updated Explorer profile') ) - return redirect(reverse_lazy('place_detail', kwargs={'pk': place.pk})) + return redirect(reverse_lazy('explorer_profile_update')) else: # Usually the browser should have checked the form before sending. @@ -78,4 +78,5 @@ class ExplorerProfileUpdateView(IsAuthenticatedMixin, View): 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 + return redirect(reverse_lazy('explorer_profile_update')) + \ No newline at end of file