Exemplo n.º 1
0
def default_page_template_data(request, map):
    plain_old_comments = map.page.comments.all()
    if request.args.get('linear') is not None:
        comment_mode = 'linear'
        comments = linear(plain_old_comments)
    else:
        comment_mode = 'threaded'
        comments = thread(plain_old_comments)

    return {
        'display_options': MakoDict(default_display_options()),
        'page_data':       MakoDict({
            'page':                 map.page,
            'page_path':            map.request_path
        }),
        'comment_data':    MakoDict({
            'comment_count':        len(plain_old_comments),
            'comments':             comments,
            'comment_submit_path':  map.request_path,
            'comment_mode':         comment_mode,
            'form':                 request.form,
        }, ['comments', 'form']),
        'tags_data':       MakoDict({
            'tags': map.page.tags
        }),
        'related_posts': related_posts(map.page),
        'lynx': lynx_browser(request),
        'captcha_nr' : random.randint(1,20),
        'admin' : admin_cred_match(request)
    }
Exemplo n.º 2
0
def default_comment_template_data(request, comment_id):
    mixergy = session. \
                query(Comment, Page, UrlMap). \
                join(Page, UrlMap). \
                filter(Comment.comment_id==comment_id). \
                first()

    if not mixergy:
        # TODO: "The requested comment was not found, here are a few latest coments"
        #       "Here are latest posts, here are most commented posts..."
        raise NotFound()

    comment, page, urlmap = mixergy

    template_data = {
        'page':                 page,
        'page_path':            urlmap.request_path,
        'comment_submit_path':  '/c/%d?reply' % comment_id,
        'comment_parent_id':    comment_id,
        'comment':              comment,
        'form':                 request.form,
        'lynx':                 lynx_browser(request),
        'captcha_nr' :          random.randint(1,20),
        'admin' : admin_cred_match(request)
    }
    return template_data
Exemplo n.º 3
0
def handle_page_get(request, map):
    engine.execute("UPDATE pages SET views=views+1 WHERE page_id=%d" % map['page_id'])

    stackvm_post = False
    if map['page_id'] in stackvm_ids: # stackvm post ids
        stackvm_post = True

    if stackvm_post:
        su = request.args.get('signup')
        if su in ['ok', 'failed']:
            return compute_stackvm_get_page(request, map)

    referer = request.headers.get('Referer', 'None')
    mobile = False
    if mobile_rx.search(referer):
        mobile = True

    cache_id = 'individual_page_%s' % map['request_path']
    if mobile:
        cache_id = 'individual_mobile_page_%s' % map['request_path']

    if admin_cred_match(request):
        return template_response(compute_handle_page_get(request, map))

    return cached_template_response(
             compute_handle_page_get,
             cache_id,
             3600,
             request,
             map)