def post(self, request, *args, **kwargs): pk = self.kwargs.get('pk', None) if pk is not None: user = User.objects.get(pk=pk) prfl = Profile.objects.get(pk=pk) user_form = self.form_class(instance=user, data=request.POST) profile_form = self.second_form_class( instance=prfl, data=request.POST, files=request.FILES) #assert False, profile_form self.form_valid(user_form, profile_form) return confirmation_page(request, pk) else: render_access_denied_message(request)
def creditcarddeleteview(request, user_id, creditcard_id): try: user = User.objects.get(pk=user_id) creditcard = CreditCard.objects.get(pk=creditcard_id) except: return render_access_denied_message(request) form = DeleteCreditCardConfirmation(request) if request.method == 'POST': form = DeleteCreditCardConfirmation(request.POST) if request.POST.get('Confirm'): #Confirmed deletion creditcard.delete() return rendermessage( request, 'Credit Card Delete | Confirmation', 'Credit card removed succefully', '', reverse('users:creditcards', args=[str(user_id)]), 'creditcards page') else: # Cancelled deletion returned to credit cards page return HttpResponseRedirect( reverse('users:creditcards', args=[str(user_id)])) return renderconfirmation( request, form, 'Delete credit card', 'Please confirm', 'Are you sure you want to delete the credit card?')
def addressdeleteview(request, user_id, address_id): try: user = User.objects.get(pk=user_id) address = Address.objects.get(pk=address_id) except: return render_access_denied_message(request) form = DeleteAddressConfirmation(request) if request.method == 'POST': form = DeleteAddressConfirmation(request.POST) if request.POST.get('Confirm'): #Confirmed deletion address.delete() return rendermessage( request, 'Delete confirmation', 'Shipping address removed succefully', '', reverse('users:addresses', args=[str(user_id)]), 'shipping addresses page') else: # Cancelled deletion returned to the shippping addresses page return HttpResponseRedirect( reverse('users:addresses', args=[str(user_id)])) return renderconfirmation( request, form, 'Delete shipping address', 'Please confirm', 'Are you sure you want to delete the shipping address?')
def get(self, request, *args, **kwargs): pk = self.kwargs.get('pk', None) self.request = request if self.request.user.is_authenticated( ) and self.request.user.id == int(kwargs['pk']): super(ProfileUpdateView, self).get(request, *args, **kwargs) user = User.objects.get(pk=pk) prfl = Profile.objects.get(pk=pk) # if the image was removed then show the default image #if not default_storage.exists(prfl.image.url): # prfl.image.url = 'assets/img/user.png' form = self.form_class(instance=user) form2 = self.second_form_class(instance=prfl) return self.render_to_response( self.get_context_data( object=self.object, form=form, form2=form2)) return render_access_denied_message(request)