Esempio n. 1
0
    def time_count(self):
        real_time_now = translate_time(time.time())
        real_time_old = translate_time(self.update_time)

        startTime = datetime.datetime.strptime(real_time_old, "%Y-%m-%d %H:%M:%S")
        endTime = datetime.datetime.strptime(real_time_now, "%Y-%m-%d %H:%M:%S")

        gap_time = (endTime - startTime).seconds/(24*3600)
        # gap_time = int(gap_time/(3600*24))
        print(type(gap_time))
        return int(gap_time)
Esempio n. 2
0
def create_blog():
    if not ctx.request.user:
        raise HttpError.seeother('/login')
    if not ctx.request.manager:
        raise APIError('not admin')
    i = ctx.request.input(name='', summary='', content='', blogid='', currentcat='')
    name = i.name
    summary = i.summary
    content = i.content
    currentcat = i.currentcat
    if not name:
        raise APIError('name cant be none')
    if not summary:
        raise APIError('summary cant be none')
    if not content:
        raise APIError('content cant be none')
    if i.blogid:
        # blog = select_one('select * from blogs where id=?', i.blogid)
        # blog_to_update = Blog(id=blog.id, name=name, summary=summary, content=content)
        # blog_to_update.update()
        session.query(Blog).filter(Blog.id == i.blogid).\
            update({'name': name, 'summary': summary, 'content': content, 'category':currentcat})
        session.commit()
        # return translate_time(select_one('select * from blogs where id=?', i.blogid))
        return translate_time(session.query(Blog).filter(Blog.id == i.blogid).first())
    # blog = Blog(name=name, summary=summary, content=content,user_id=ctx.request.user.id, user_name=ctx.request.user.name )
    # blog.insert()
    blog = Blog(name=name, summary=summary, content=content, user=ctx.request.user.id, category=currentcat)
    session.add(blog)
    session.commit()
    return blog.as_dict()
Esempio n. 3
0
def api_get_users():
    page = ctx.request.query_string.get('page')
    count = ctx.request.query_string.get('count')
    if page:
        users = session.query(User).all()
        p = Paginator(page=int(page), object_=users, count=int(count or 10))
        return dict(users=translate_time([user.as_dict() for user in  p.object_list]),
                    pagenums=p.pagenums)
    return dict()
Esempio n. 4
0
def postcomments(blogid):
    user = ctx.request.user
    content = ctx.request.input().newcomment
    if user and content.strip():
        comment = Comment(blog=blogid, user=user.id, content=content)
        session.add(comment)
        session.commit()
        return translate_time(comment.as_dict())
    raise APIError('not user or blank content')
Esempio n. 5
0
File: topic.py Progetto: ql1/bbs
def detail(id):
    m = Topic.get(id)
    # some_day = time.time
    m.post_time = translate_time(m.update_time)
    user_id = m.user_id
    u = User.find_by(id = user_id)
    author = u.username
    b = Board.find(m.board_id)
    place = b.title
    return render_template('topic/detail.html',topic = m,author = author,place = place)
Esempio n. 6
0
def getblog():
    page = ctx.request.query_string.get('page')    # 此处修改了框架的query_string:返回{'a'='1','b'='balbal'}
    count = ctx.request.query_string.get('count')
    cat = ctx.request.query_string.get('cat')
    if page:
        if cat == 'all' or cat is None:
            blogs = session.query(Blog).order_by(Blog.created_at.desc()).all()
        else:
            blogs = session.query(Blog).filter(Blog.category == cat).order_by(Blog.created_at.desc()).all()
        p = Paginator(int(page), blogs, count=int(count or 6))
        categories = session.query(Category).all()
        catobject = session.query(Category).filter(Category.id == cat).first()
        return dict(blogs=translate_time([blog.as_dict() for blog in p.object_list]),
                    hasnext=p.hasnext,
                    hasprevious=p.hasprevious,
                    pagenums=p.pagenums,
                    currentcat=catobject.id if catobject else None,
                    categories=[cat.as_dict() for cat in categories])
    return dict()
Esempio n. 7
0
File: topic.py Progetto: ql1/bbs
def index(page_num = 1):
    board_id = int(request.args.get('board_id',-1))
    #如果是-1 就是没有 也就是全部Topic
    if board_id == -1:
        ms = Topic.all()
    else:
        ms = Topic.find_all(board_id=board_id)
    bs = Board.all()
    ms.sort(key=lambda x:x.update_time,reverse=True)

    # ms  即查出的所有需要传入模板的topic
    ms = ms[10 * (page_num -1) : 10 * page_num]
    for m in ms:
        # log('**ms debug',ms)
        m.post_time = translate_time(m.update_time)
    # 在后端计算出需要几页,赋值给 page_all 变量 传给前端
    print(len(ms))
    page_all = (int(len(ms)/10)) + 1
    user = current_user()
    return render_template('topic/index.html',ms = ms,bs = bs,user = user.username,page_all = page_all,currentpage=page_num)
Esempio n. 8
0
def getcomments(blogid):
    comments = session.query(Comment).filter(Comment.blog == blogid).all()
    return translate_time([comment.as_dict() for comment in comments])
Esempio n. 9
0
def api_get_blogs():
    blogs = session.query(Blog).all()
    return dict(blogs=translate_time(blogs))