def post(self, request, *args, **kwargs): ctx = {} if 'identification' in request.POST: form = IdentificationForm(request.POST, files=request.FILES) ctx['form_id'] = form if form.is_valid(): previous_id = self.request.user.identification self.request.user.identification = Document.objects.create( file=self.request.FILES['identification_file']) self.request.user.save() if bool(previous_id): previous_id.delete() identification_uploaded.send(sender=self.__class__, request=self.request) if 'senior_card' in request.POST: form = SeniorCardForm(request.POST, files=request.FILES) ctx['form_senior'] = form if form.is_valid(): previous_senior_card = self.request.user.senior_card self.request.user.senior_card = Document.objects.create( file=self.request.FILES['senior_card']) self.request.user.save() if bool(previous_senior_card): previous_senior_card.delete() # back to the same page with an updated ctx with forms return self.get(request, **ctx)
def post(self, request, *args, **kwargs): ctx = {} if 'identification' in request.POST: form = IdentificationForm(request.POST, files=request.FILES) ctx['form_id'] = form if form.is_valid(): previous_id = self.request.user.identification self.request.user.identification = Document.objects.create( file=self.request.FILES['identification_file']) self.request.user.save() if bool(previous_id): previous_id.delete() identification_uploaded.send(sender=self.__class__, request=self.request) messages.success(request, 'ID was successfully uploaded') if 'senior_card' in request.POST: form = SeniorCardForm(request.POST, files=request.FILES) ctx['form_senior'] = form if form.is_valid(): previous_senior_card = self.request.user.senior_card self.request.user.senior_card = Document.objects.create( file=self.request.FILES['senior_card']) self.request.user.save() if bool(previous_senior_card): previous_senior_card.delete() messages.success(request, 'Seniors card was successfully uploaded') return redirect('wl_home')
def post(self, request, *args, **kwargs): ctx = {} if 'identification' in request.POST: form = IdentificationForm(request.POST, files=request.FILES) ctx['form_id'] = form if form.is_valid(): previous_id = self.request.user.identification self.request.user.identification = Document.objects.create(file=self.request.FILES['identification_file']) self.request.user.save() if bool(previous_id): previous_id.delete() identification_uploaded.send(sender=self.__class__, request=self.request) if 'senior_card' in request.POST: form = SeniorCardForm(request.POST, files=request.FILES) ctx['form_senior'] = form if form.is_valid(): previous_senior_card = self.request.user.senior_card self.request.user.senior_card = Document.objects.create(file=self.request.FILES['senior_card']) self.request.user.save() if bool(previous_senior_card): previous_senior_card.delete() # back to the same page with an updated ctx with forms return self.get(request, **ctx)