def index(request): featured = models.get_featured() photo_count = cache.get('photo_count') if photo_count is None: photo_count = models.Photo.objects.filter(status='approved').count() cache.set('photo_count', photo_count, 3000) num_pages = photo_count / settings.PAGINATION_BATCH_SIZE try: random_page = random.randrange(1, num_pages) except ValueError: # might happen if there aren't yet enough photos in the # gallery random_page = False template_map = dict(featured=featured, random_page=random_page) context = RequestContext(request, template_map) return render_to_response('gallery/index.html', context_instance=context)
def get_object(self, request): return models.get_featured()