コード例 #1
0
def get_content(request, path=''):
    """Get content from datastore as requested on the url path
    
    Args:
        path - comes without leading slash. / added in code
    
    """
    content = StaticContent.get_by_key_name("/%s" % path)
    if not content:
        if path == '':
            # Nothing generated yet. Inform user to create some content
            return render_to_response("blog/themes/%s/listing.html" % config.theme, 
                                {'config': config, 'no_post': True,})
        else:
            raise NotFound
    
    serve = True
    # check modifications and etag
    if 'If-Modified-Since' in request.headers:
        last_seen = datetime.datetime.strptime(
            request.headers['If-Modified-Since'], HTTP_DATE_FMT)
        if last_seen >= content.last_modified.replace(microsecond=0):
            serve = False
    if 'If-None-Match' in request.headers:
        etags = [x.strip('" ')
                 for x in request.headers['If-None-Match'].split(',')]
        if content.etag in etags:
            serve = False
    response = _output(content, serve)
    return response