Skip to content

Commit

Permalink
Properly handling missing packages and proxy requests with a redirect…
Browse files Browse the repository at this point in the history
… within the class-based views.
  • Loading branch information
coordt committed Apr 20, 2012
1 parent 9eb557a commit e104db3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions userpypi/views/packages.py
Expand Up @@ -59,11 +59,15 @@ class PackageDetailView(OwnerObjectMixin, DetailView):
simple = False
doap = False
owner = None
redirect = ''

def render_to_response(self, context, **response_kwargs):
"""
Returns a response with a template rendered with the given context.
"""
if self.redirect:
return HttpResponseRedirect(self.redirect)

self.doap = 'doap' in self.kwargs and self.kwargs['doap']

if self.doap:
Expand All @@ -79,9 +83,8 @@ def get_object(self):
obj = queryset.get()
except ObjectDoesNotExist:
if PROXY_MISSING:
return HttpResponseRedirect('%s/%s/' %
(PROXY_BASE_URL.rstrip('/'),
package))
self.redirect = '%s/%s/' % (PROXY_BASE_URL.rstrip('/'), package)
return None
raise Http404(u"No %(verbose_name)s found matching the query" %
{'verbose_name': queryset.model._meta.verbose_name})
return obj
Expand Down

0 comments on commit e104db3

Please sign in to comment.