Exemplo n.º 1
0
def http(req):
    req.post = Post.filter(id__is=req.postpath[0], blog__is=req.settings.ref.id).fetchone()

    if req.post:
        return None
    else:
        return NotFound(req.path)
Exemplo n.º 2
0
def http_POST(req):
    req.post = Post.filter(id__is=req.postpath[0], blog__is=req.settings.ref.id).fetchone()
    
    if req.post:
        req.args.setdefault('featured', [req.post.featured])
        req.args.setdefault('marker', [req.post.marker])
        req.args.setdefault('classes', [req.post.classes])
        req.args.setdefault('title', [req.post.title])
        req.args.setdefault('span', [req.post.span])
        req.args.setdefault('body', [req.post.body])
        req.args.setdefault('style', [req.post.style])
        
        req.post.featured = req.args['featured'][0]
        req.post.marker = req.args['marker'][0]
        req.post.classes = req.args['classes'][0]
        req.post.title = req.args['title'][0]
        req.post.span = req.args['span'][0]
        req.post.body = req.args['body'][0]       
        req.post.style = req.args['style'][0]       
        req.post.save()

        if req.files['attachment'][0][1]:
            req.post.process_attachment(req.files['attachment'][0][2])
        
        return None
    else:
        return NotFound(req.path)
Exemplo n.º 3
0
def http(req):
    req.post = Post.filter(id__is=req.postpath[0], blog__is=req.settings.ref.id).fetchone()
    
    if req.post:
        req.args.setdefault('featured', [req.post.featured])
        req.args.setdefault('marker', [req.post.marker])
        req.args.setdefault('classes', [req.post.classes])
        req.args.setdefault('title', [req.post.title])
        req.args.setdefault('span', [req.post.span])
        req.args.setdefault('body', [req.post.body])
        req.args.setdefault('style', [req.post.style])
        return None
    else:
        return NotFound(req.path)
Exemplo n.º 4
0
def http(req):
    if len(req.postpath) > 3 and req.postpath[3]:
        req.post = Post.filter(
            posted__date="-".join(req.postpath[0:3]), title__is=req.postpath[3].replace("_", " ")
        ).fetchone()

        if req.post:
            view = PostView()
            view.post = req.post
            view.ip = req.remoteAddr.host
            view.save()
            return None
        else:
            return NotFound(req.path)
    else:
        return Redirect("/archive/" + "/".join(req.postpath))
Exemplo n.º 5
0
def http(req):
    q = req.args.get('q', [""])[0]
    
    db().execute("""
            INSERT INTO searchsuggestion 
                (id, suggestion, frequency)
            VALUES
                (0, %s, %s)
            ON DUPLICATE KEY UPDATE
                frequency = frequency + 1
        """, (q, 1))
    
    sphinx = SphinxClient()
    
    search = sphinx.Query(q)
    
    req.posts = []
    if search and len(search['matches']):
        search_ids = [match['id'] for match in search['matches']]
        
        post_filter = Post.filter(search_id__in=search_ids, limit=req.args.get('limit', [10])[0], offset=req.args.get('page', [0])[0])
        posts = post_filter.fetchall(count=True)
        
        docs = reduce(lambda acc, x: acc + x, [[post.title, post.body] for post in posts], [])
        docs = sphinx.BuildExcerpts(docs, "idx1", q, excerpt_opts)
        
        posts_by_search_id = {}
        for i, post in enumerate(posts):
            post.matched_title = docs[i*2]
            post.matched_body = docs[i*2+1]
            posts_by_search_id[post.search_id] = post
            
        req.posts = [posts_by_search_id[id] for id in search_ids]
        req.pagination = post_filter
    
    return None