Source

copelco / lib / copelco / apps / default / views.py

Full commit
Colin Copeland 5f87b58 



Colin Copeland 068de63 


Colin Copeland 5f87b58 

Colin Copeland 068de63 



Colin Copeland 5f87b58 




































from django import http
from django.template import Context, RequestContext, loader
from django.shortcuts import render_to_response, get_object_or_404

from copelco.apps.aggregator.models import FeedItem
from copelco.apps.flickr.models import PhotoSize


def home(request):
    feed_items = FeedItem.objects.order_by('-date_modified')[:10]
    photos = PhotoSize.objects.filter(type='medium',
                                      width__gt=500).order_by('?')[:10]
    context = {'feed_items': feed_items, 'photos': photos}
    return render_to_response('home.html', context,
                              context_instance=RequestContext(request))


# in lieu of http://code.djangoproject.com/ticket/5617
def render_safe(request, template_name):
    """
    Try to render the given template using RequestContext.  If that fails,
    use an empty Context instead.
    """
    t = loader.get_template(template_name)
    try:
        context = RequestContext(request, {'request_path': request.path})
        return t.render(context)
    except:
        return t.render(Context({}))


def page_not_found(request, template_name='404.html'):
    """
    Default 404 handler.

    Templates: `404.html`
    Context:
        request_path
            The path of the requested URL (e.g., '/app/pages/bad_page/')
    """
    return http.HttpResponseNotFound(render_safe(request, template_name))


def server_error(request, template_name='500.html'):
    """
    500 error handler.

    Templates: `500.html`
    Context: None
    """
    return http.HttpResponseServerError(render_safe(request, template_name))