def post(self, request, *args, **kwargs): customer = get_object_or_404(EmailUser, pk=self.args[0]) emailuser_form = CustomerDetailsForm(request.POST, instance=customer) if emailuser_form.is_valid(): emailuser_form.save() if "identification" in self.request.FILES: if customer.identification is not None: customer.identification.delete() customer.identification = Document.objects.create(file=self.request.FILES["identification"]) customer.save() identification_uploaded.send(sender=self.__class__, user=self.request.user) else: return render(request, self.template_name, {"customer": customer, "form": emailuser_form}) messages.success( request, "The details were updated. Please note that this may require any licences held by the user to be reissued.", ) return redirect("wl_customer_management:customer_lookup", customer.pk)
def post(self, request, *args, **kwargs): customer = get_object_or_404(EmailUser, pk=self.args[0]) ctx = {'customer': customer} if 'save_details' in request.POST: emailuser_form = CustomerDetailsForm(request.POST, instance=customer) if emailuser_form.is_valid(): emailuser_form.save() messages.success( request, 'The details were updated. Please note that this may require any licences held by the user to be reissued.' ) return redirect('wl_customer_management:customer_lookup', customer.pk) else: ctx['form'] = emailuser_form return self.get(request, **ctx) if 'id' in self.request.FILES: previous_id = customer.identification customer.identification = Document.objects.create( file=self.request.FILES['id']) customer.save() if bool(previous_id): previous_id.delete() ctx['id_url'] = customer.identification.file.url identification_uploaded.send(sender=self.__class__, request=self.request) if 'delete_id' in request.POST: if bool(customer.identification): customer.identification.delete() if 'senior_card' in self.request.FILES: previous = customer.senior_card customer.senior_card = Document.objects.create( file=self.request.FILES['senior_card']) customer.save() if bool(previous): previous.delete() ctx['senior_card_url'] = customer.senior_card.file.url if 'delete_senior_card' in request.POST: if bool(customer.senior_card): customer.senior_card.delete() return self.get(request, **ctx)
def post(self, request, *args, **kwargs): customer = get_object_or_404(EmailUser, pk=self.args[0]) ctx = { 'customer': customer } if 'save_details' in request.POST: emailuser_form = CustomerDetailsForm(request.POST, instance=customer) if emailuser_form.is_valid(): emailuser_form.save() messages.success(request, 'The details were updated. Please note that this may require any licences held by the user to be reissued.') return redirect('wl_customer_management:customer_lookup', customer.pk) else: ctx['form'] = emailuser_form return self.get(request, **ctx) if 'id' in self.request.FILES: previous_id = customer.identification customer.identification = Document.objects.create(file=self.request.FILES['id']) customer.save() if bool(previous_id): previous_id.delete() ctx['id_url'] = customer.identification.file.url identification_uploaded.send(sender=self.__class__, request=self.request) if 'delete_id' in request.POST: if bool(customer.identification): customer.identification.delete() if 'senior_card' in self.request.FILES: previous = customer.senior_card customer.senior_card = Document.objects.create(file=self.request.FILES['senior_card']) customer.save() if bool(previous): previous.delete() ctx['senior_card_url'] = customer.senior_card.file.url if 'delete_senior_card' in request.POST: if bool(customer.senior_card): customer.senior_card.delete() return self.get(request, **ctx)
def get_context_data(self, **kwargs): customer = get_object_or_404(EmailUser, pk=self.args[0]) if 'customer' not in kwargs: kwargs['customer'] = customer if 'form' not in kwargs: kwargs['form'] = CustomerDetailsForm(instance=customer) # if 'form_id' not in kwargs: # kwargs['form_id'] = IdentificationForm() if 'id_url' not in kwargs and bool(customer.identification): kwargs['id_url'] = customer.identification.file.url if 'senior_card_url' not in kwargs and bool(customer.senior_card): kwargs['senior_card_url'] = customer.senior_card.file.url return super(EditDetailsView, self).get_context_data(**kwargs)