diff -r 3a2fdc820c41 -r 6442e5c97b48 qrurls/views.py --- a/qrurls/views.py Sat Sep 07 15:38:24 2013 +0300 +++ b/qrurls/views.py Sat Sep 07 15:48:23 2013 +0300 @@ -1,7 +1,6 @@ import calendar # timegm import logging -from django.core.cache import cache from django.http import HttpResponse, HttpResponseRedirect, Http404 from django.shortcuts import render from django.utils import timezone, http @@ -14,12 +13,6 @@ Public frontend UI. """ -class URLNotFound (Http404): - pass - -class URLItemNotFound (Http404): - pass - def http_datetime (dt) : return http.http_date(calendar.timegm(dt.utctimetuple())) @@ -33,21 +26,11 @@ """ Primary frontend for redirecting based on current time. """ - - key = 'qrurls/urlfeed/{shorturl}'.format(shorturl=shorturl) # format as dict - data = cache.get(key) - - if data : - url, modified = data - log.info("get cache: %s: %s", key, url) - else: - url_item = URLItem.search(shorturl=shorturl) - modified = url_item.last_modified() - url = url_item.get_absolute_url() - - log.info("set cache: %s: %s", key, url) - cache.set(key, (url, modified)) # XXX: expiry + try: + url, modified = URLItem.get_url(shorturl) + except URLItem.DoesNotExist: + raise Http404() # redirect, either directly, or to image() response = HttpResponseRedirect(url) @@ -60,10 +43,12 @@ Frontend for a specific item. """ - url_item = _get_url_item( - shorturl=shorturl, item_id=item_id, - related=('shorturl', 'image') - ) + try : + url_item = URLItem.get_item(shorturl, item_id=item_id, + related=('shorturl', 'image'), + ) + except URLItem.DoesNotExist: + raise Http404() if url_item.url : response = HttpResponseRedirect(url_item.url)