Example #1
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)
Example #2
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)
Example #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)
Example #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))
Example #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
Example #6
0
def http_POST(req):
    message = json.loads(req.args['message'][0])
    for data in data.posts:    
        post = Post.get(data.ident)
        user = User.get(data.user)

        if not user:
            user = User()
            user.id = data.user
            user.username = data.name
            user.email = data.email
            user.save()            

        if post:
            comment = Comment()
            comment.post = post
            comment.user = user
            comment.id = data.id
            comment.posted = data.time
            comment.title = data.title
            comment.body = data.body
            comment.save()       
    
    return None
Example #7
0
File: new.py Project: lzimm/pervurs
def http_POST(req):
    req.args.setdefault('featured', [False])
    req.args.setdefault('marker', ['Connectedism'])
    req.args.setdefault('classes', [''])
    req.args.setdefault('title', [''])
    req.args.setdefault('span', [''])
    req.args.setdefault('body', [''])
    req.args.setdefault('style', [''])
    
    post = Post()
    post.blog = req.settings.ref
    post.user = req.user
    post.featured = req.args['featured'][0]
    post.marker = req.args['marker'][0]
    post.classes = req.args['classes'][0]
    post.title = req.args['title'][0]
    post.span = req.args['span'][0]
    post.body = req.args['body'][0]
    post.style = req.args['style'][0]
    post.posted = str(datetime.today())
    post.save()

    if req.files['attachment'][0][1]:
        post.process_attachment(req.files['attachment'][0][2])
    else:
        post.set_default_attachment()

    return None