Added failsafe, if there is no profile_image.
This commit is contained in:
parent
871acd1dce
commit
b1aa4473e9
@ -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})
|
Loading…
Reference in New Issue
Block a user