def api_blogs(*, page='1'):
    page_index = get_page_index(page)
    num = yield from Blog.findNumber('count(id)')
    p = Page(num, page_index)
    if num == 0:
        return dict(page=p, blogs=())
    blogs = yield from Blog.findAll(orderBy='created_at desc', limit=(p.offset, p.limit))
    return dict(page=p, blogs=blogs)
def api_create_blog(request, *, name, summary, content):
    check_admin(request)
    if not name or not name.strip():
        raise APIValueError('name', 'name cannot be empty.')
    if not summary or not summary.strip():
        raise APIValueError('summary', 'summary cannot be empty.')
    if not content or not content.strip():
        raise APIValueError('content', 'content cannot be empty.')
    blog = Blog(user_id=request.__user__.id, user_name=request.__user__.name, user_image=request.__user__.image, name=name.strip(), summary=summary.strip(), content=content.strip())
    yield from blog.save()
    return blog
def index(*, page='1'):
    page_index = get_page_index(page)
    num = yield from Blog.findNumber('count(id)')
    page = Page(num)
    if num == 0:
        blogs = []
    else:
        blogs = yield from Blog.findAll(orderBy='created_at desc', limit=(page.offset, page.limit))
    return {
        '__template__': 'blogs.html',
        'page': page,
        'blogs': blogs
    }
Beispiel #4
0
def send(request):
    """网页发送信息。 """
    
    if request.method == 'POST':
        try:
            msg = request.POST.get('content')
            
            # 发送到机器人
            user = db.users.get_current_user()
            if user:
                blog = Blog.all().filter('user ='******'%s|%s: %s' % (user, blog.name, msg)
                else:
                    msg = '%s|%s: %s' % (user, 'blog', msg)
                grouptalk.send(msg, user.email())
            else:
                msg = 'web: ' + msg
                grouptalk.send(msg)
            
            # 发送到web客户端
            grouptalk.channel_send(msg)
        except:
            logging.error('error web send msg!')
                
        return http.HttpResponse()
Beispiel #5
0
def invite_all_users(request):
    """邀请所有用户。"""
    
    blogs = Blog.all().fetch(limit=1000)
    for blog in blogs:
        grouptalk.invite(blog.user.email())
        
    return http.HttpResponse()
Beispiel #6
0
def init_talkstatus(request):
    """管理员专用!慎用!初始化TalkStatus数据模型。"""
    
    db.delete(talk_models.TalkStatus.all().fetch(limit=1000))
    
    blogs = Blog.all().fetch(limit=1000)
    for blog in blogs:
        talk_models.TalkStatus.add(user=blog.user, blog=blog)

    return http.HttpResponse()
def get_blog(id):
    blog = yield from Blog.find(id)
    comments = yield from Comment.findAll('blog_id=?', [id], orderBy='created_at desc')
    for c in comments:
        c.html_content = text2html(c.content)
    blog.html_content = markdown2.markdown(blog.content)
    return {
        '__template__': 'blog.html',
        'blog': blog,
        'comments': comments
    }
Beispiel #8
0
def hosts(request):
    
    links = (blog.link[7:].encode('utf8').split('/')[0] for blog in Blog.all().fetch(limit=1000) if 'appspot.com' in blog.link)
    
    template = loader.get_template('tools/templates/hosts.html')
    context = RequestContext(request, {
        'links': links,
        'ip': IP,
    })
    
    return http.HttpResponse(template.render(context))
def api_create_comment(id, request, *, content):
    user = request.__user__
    if user is None:
        raise APIPermissionError('Please signin first.')
    if not content or not content.strip():
        raise APIValueError('content')
    blog = yield from Blog.find(id)
    if blog is None:
        raise APIResourceNotFoundError('Blog')
    comment = Comment(blog_id=blog.id, user_id=user.id, user_name=user.name, user_image=user.image, content=content.strip())
    yield from comment.save()
    return comment
def api_update_blog(id, request, *, name, summary, content):
    check_admin(request)
    blog = yield from Blog.find(id)
    if not name or not name.strip():
        raise APIValueError('name', 'name cannot be empty.')
    if not summary or not summary.strip():
        raise APIValueError('summary', 'summary cannot be empty.')
    if not content or not content.strip():
        raise APIValueError('content', 'content cannot be empty.')
    blog.name = name.strip()
    blog.summary = summary.strip()
    blog.content = content.strip()
    yield from blog.update()
    return blog
Beispiel #11
0
def recieve(request):
    """机器人接收消息,信息转发。"""
    
    try:
        message = xmpp.Message(request.POST)

        if grouptalk.is_command(message.body):
            grouptalk.exec_command(message, message.body)
            return http.HttpResponse()
        
        sender_mail = message.sender.split('/')[0]
        blog = Blog.all().filter('user ='******'@')[0]
        if blog:
            msg = '%s|%s: %s' % (sender_user, blog.name, message.body)
        else:
            msg = '%s|%s: %s' % (sender_user, 'blog', message.body)
        grouptalk.send(msg, sender_mail)
        grouptalk.channel_send(msg)
    except:
        logging.error('error send msg!')
        
    return http.HttpResponse()
def api_delete_blog(request, *, id):
    check_admin(request)
    blog = yield from Blog.find(id)
    yield from blog.remove()
    return dict(id=id)
def api_get_blog(*, id):
    blog = yield from Blog.find(id)
    return blog
Beispiel #14
0
 def blogname(self):
     blog = Blog.all().filter('user ='******''