Example #1
0
    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')
Example #2
0
 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)
Example #3
0
 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)
Example #4
0
    def get_context_data(self, **kwargs):
        if 'form_id' not in kwargs:
            kwargs['form_id'] = IdentificationForm()
        if self.request.user.identification:
            kwargs['existing_id_image_url'] = self.request.user.identification.file.url

        if self.request.user.is_senior:
            if 'form_senior' not in kwargs:
                kwargs['form_senior'] = SeniorCardForm()
            if self.request.user.senior_card:
                kwargs['existing_senior_card_image_url'] = self.request.user.senior_card.file.url

        if 'file_types' not in kwargs:
            kwargs['file_types'] = ', '.join(['.' + file_ext for file_ext in IdentificationForm.VALID_FILE_TYPES])
        return super(IdentificationView, self).get_context_data(**kwargs)