Ejemplo n.º 1
0
 def post(self, request, *args, **kwargs):
     form = forms.SponsorForm(request.POST, request.FILES)
     try:
         uid = force_text(
             urlsafe_base64_decode(self.kwargs.get('uid', None)))
         user = userModels.User.objects.get(pk=uid)
     except (TypeError, ValueError, OverflowError,
             userModels.User.DoesNotExist):
         return Http404('How did you get here?')
     if not user.has_applications_left():
         form.add_error(None, 'You have no applications left')
     elif form.is_valid():
         name = form.cleaned_data['name']
         app = models.SponsorApplication.objects.filter(user=user,
                                                        name=name).first()
         if app:
             form.add_error(
                 'name', 'This name is already taken. Have you applied?')
         else:
             application = form.save(commit=False)
             application.user = user
             application.save()
             messages.success(request,
                              'We have now received your application. ')
             return render(request, 'sponsor_submitted.html')
     c = self.get_context_data()
     c.update({'form': form})
     return render(request, self.template_name, c)
Ejemplo n.º 2
0
    def get_context_data(self, **kwargs):
        context = super(SponsorApplicationView, self).get_context_data(**kwargs)
        form = forms.SponsorForm()
        context.update({'form': form, 'is_sponsor': True})
        try:
            uid = force_text(urlsafe_base64_decode(self.kwargs.get('uid', None)))
            user = userModels.User.objects.get(pk=uid)
            context.update({'user': user})
        except (TypeError, ValueError, OverflowError, userModels.User.DoesNotExist):
            pass

        return context