make pledge complete page more forgiving
parent
3c40106a5b
commit
3d2980f9a1
|
@ -1520,6 +1520,11 @@ class FundCompleteView(TemplateView):
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
context = self.get_context_data(**kwargs)
|
context = self.get_context_data(**kwargs)
|
||||||
|
|
||||||
|
# if there is a redirect URL calculated in get_context_data -- redirect to that URL
|
||||||
|
if context.get('redirect'):
|
||||||
|
return HttpResponseRedirect(context.get('redirect'))
|
||||||
|
|
||||||
if context['campaign'].type == THANKS:
|
if context['campaign'].type == THANKS:
|
||||||
return DownloadView.as_view()(request, work=context['work'])
|
return DownloadView.as_view()(request, work=context['work'])
|
||||||
else:
|
else:
|
||||||
|
@ -1535,8 +1540,22 @@ class FundCompleteView(TemplateView):
|
||||||
context = super(FundCompleteView, self).get_context_data()
|
context = super(FundCompleteView, self).get_context_data()
|
||||||
|
|
||||||
# pull out the transaction id and try to get the corresponding Transaction
|
# pull out the transaction id and try to get the corresponding Transaction
|
||||||
transaction_id = self.request.REQUEST.get("tid")
|
transaction_id = self.request.REQUEST.get("tid", "")
|
||||||
|
|
||||||
|
# be more forgiving of tid --> e.g., if there is a trailing "/"
|
||||||
|
|
||||||
|
g = re.search("^(\d+)(\/?)$", transaction_id)
|
||||||
|
if g:
|
||||||
|
transaction_id=g.group(1)
|
||||||
|
else: # error -- redirect to home page
|
||||||
|
context['redirect'] = reverse('home')
|
||||||
|
return context
|
||||||
|
|
||||||
transaction = Transaction.objects.get(id=transaction_id)
|
transaction = Transaction.objects.get(id=transaction_id)
|
||||||
|
# if there is no valid transaction, redirect home
|
||||||
|
if not transaction:
|
||||||
|
context['redirect'] = reverse('home')
|
||||||
|
return context
|
||||||
|
|
||||||
# work and campaign in question
|
# work and campaign in question
|
||||||
try:
|
try:
|
||||||
|
@ -1546,13 +1565,18 @@ class FundCompleteView(TemplateView):
|
||||||
campaign = None
|
campaign = None
|
||||||
work = None
|
work = None
|
||||||
|
|
||||||
# we need to check whether the user tied to the transaction is indeed the authenticated user.
|
# # we need to check whether the user tied to the transaction is indeed the authenticated user.
|
||||||
|
|
||||||
if transaction.campaign.type == THANKS and transaction.user == None:
|
if transaction.campaign.type == THANKS and transaction.user == None:
|
||||||
pass
|
pass
|
||||||
elif self.request.user.id != transaction.user.id:
|
elif self.request.user.id != transaction.user.id:
|
||||||
# should be 403 -- but let's try 404 for now -- 403 exception coming in Django 1.4
|
# let's redirect user to the work corresponding to the transaction if we can
|
||||||
raise Http404
|
if work:
|
||||||
|
context['redirect'] = reverse('work', kwargs={'work_id': work.id})
|
||||||
|
else:
|
||||||
|
context['redirect'] = reverse('home')
|
||||||
|
|
||||||
|
return context
|
||||||
|
|
||||||
# add the work corresponding to the Transaction on the user's wishlist if it's not already on the wishlist
|
# add the work corresponding to the Transaction on the user's wishlist if it's not already on the wishlist
|
||||||
if transaction.user is not None and (campaign is not None) and (work is not None):
|
if transaction.user is not None and (campaign is not None) and (work is not None):
|
||||||
|
|
Loading…
Reference in New Issue