示例#1
0
def css(page_key):
    preview = ('preview' in request.args) and (request.args.get('preview') != '0')
    pretty = ('pretty' in request.args) and (request.args.get('pretty') != '0')

    if not preview and not pretty:
        count_view('css:all')
        if request.referrer:
            count_view('css:page:%s:%s' % (urlparse(request.referrer).netloc, page_key))
        etag = memcache.get(page_key + '-css-etag')
        if etag and request.headers.get('If-None-Match', '') == etag:
            return 'Not Modified', 304
        css = memcache.get(page_key + '-css')
        if not css or not etag:
            page = Page.get_or_404(page_key)
            css = page.compressed_css(False)
            etag = _etag(css)
            expires = 24 * 60 * 60
            memcache.set(page_key + '-css-etag', etag, time=expires)
            memcache.set(page_key + '-css', css, time=expires)
        return _send_file(css, 'text/css', etag)
    else:
        page = Page.get_or_404(page_key)
        if pretty:
            css = page.uncompressed_css(preview)
        else:
            css = page.compressed_css(preview)
        return _send_file(css, 'text/css')
示例#2
0
def css(page_key):
    preview = ('preview'
               in request.args) and (request.args.get('preview') != '0')
    pretty = ('pretty' in request.args) and (request.args.get('pretty') != '0')

    if not preview and not pretty:
        count_view('css:all')
        if request.referrer:
            count_view('css:page:%s:%s' %
                       (urlparse(request.referrer).netloc, page_key))
        etag = memcache.get(page_key + '-css-etag')
        if etag and request.headers.get('If-None-Match', '') == etag:
            return 'Not Modified', 304
        css = memcache.get(page_key + '-css')
        if not css or not etag:
            page = Page.get_or_404(page_key)
            css = page.compressed_css(False)
            etag = _etag(css)
            expires = 24 * 60 * 60
            memcache.set(page_key + '-css-etag', etag, time=expires)
            memcache.set(page_key + '-css', css, time=expires)
        return _send_file(css, 'text/css', etag)
    else:
        page = Page.get_or_404(page_key)
        if pretty:
            css = page.uncompressed_css(preview)
        else:
            css = page.compressed_css(preview)
        return _send_file(css, 'text/css')
示例#3
0
def templatejs(file_name, page_key=None):
    page = None
    if page_key:
        page = Page.get_or_404(page_key)
    js = render_template('js/%s.js' % (file_name), page=page)
    if not settings.debug or '__no_debug__' in request.args:
        js = jsmin(js)
    return Response(js, content_type='text/javascript')
示例#4
0
def templatejs(file_name, page_key=None):
    page = None
    if page_key:
        page = Page.get_or_404(page_key)
    js = render_template('js/%s.js' % (file_name), page=page)
    if not settings.debug or '__no_debug__' in request.args:
        js = jsmin(js)
    return Response(js, content_type='text/javascript')
示例#5
0
def _whois():
    key = request.args.get('key', None)
    email = request.args.get('email', None)
    page = None
    user_sites = None
    if key:
        page = Page.get_or_404(key)
    if email:
        user_sites = Site.gql('WHERE users = :1', User(email))
    if key or email:
        return render_template('_whois_result.html', key=key, page=page, email=email, user_sites=user_sites)
    return render_template('_whois.html')
示例#6
0
def fetch_preview():
    page = Page.get_or_404(request.form.get('page_key', ''))
    if 'localhost' in page.url or '127.0.0.1' in page.url or use_url2png is False:
        return 'OK'
    url = 'http:' + url2png(page.url)
    result = urlfetch.fetch(url, deadline=10)
    if result.status_code == 200:
        page.preview_img = result.content
        page.put()
        return 'OK'
    else:
        msg = 'Error while fetching preview image from %s\nStatus %s\nHeaders\n%s\nFinal Url: "%s"' % (url, result.status_code, result.headers, getattr(result, 'final_url', ''))
        logging.warn(msg)
        return msg, 500
示例#7
0
def _whois():
    key = request.args.get('key', None)
    email = request.args.get('email', None)
    page = None
    user_sites = None
    if key:
        page = Page.get_or_404(key)
    if email:
        user_sites = Site.gql('WHERE users = :1', User(email))
    if key or email:
        return render_template('_whois_result.html',
                               key=key,
                               page=page,
                               email=email,
                               user_sites=user_sites)
    return render_template('_whois.html')
示例#8
0
def example5(page_key):
    page = Page.get_or_404(page_key)
    return render_template('examples/blog-html5.html', page=page)
示例#9
0
def example5(page_key):
    page = Page.get_or_404(page_key)
    return render_template('examples/blog-html5.html', page=page)