示例#1
0
def comment_article():
    req_data   = request.get_data()
    info = ''
    ret_data = {}

    if request.cookies.has_key('session_id'):
        session_id = request.cookies['session_id']
    else:
        info = 'user not login'
        return check_result(False, USER_NOT_LOGIN, info, ret_data)

    sessionInfo = getSessionInfo(red, session_id, ['uid'])

    if not session_id:
        info = 'user not login'
        return check_result(False, USER_NOT_LOGIN, info, ret_data)

    try:
        req = json.loads(req_data)
    except ValueError as e:
        info = 'register failed:json analyse failure'
        logger.error(info)
        return check_result(False, JSON_ERR_ANALY, info, ret_data)

    req['uid'] = sessionInfo['uid']

    import writeComment
    result, mtype, info, ret_data = writeComment.writeComment(req)

    return check_result(result, mtype, info, ret_data)
示例#2
0
def scan_question(qid):
    cookie = request.cookies
    sessionInfo = {}

    if cookie.has_key('session_id'):
        session_id  = cookie['session_id']
        sessionInfo = getSessionInfo(red, session_id, ['nickname', 'head_url', 'authority'])

    import loadQuestion
    result, mtype, info, ret_data = loadQuestion.loadQuestion(qid)

    if result == True:
        ques       = ret_data['question']
        answers    = ret_data['answers']
        title      = ques[0]
        content    = markdown.markdown(ques[1], extensions=['markdown.extensions.extra'])
        scan_time  = ques[2]
        agree_time = ques[4]
        time       = ques[5]

        return render_template('question.html', user=sessionInfo, url='/', title=title,
                                content=content, answers=answers, answer_num=len(answers), scan_time=scan_time,
                                agree_time=agree_time, time=time, qid=qid)
    else:
        return abort()
示例#3
0
def new_questions(request, red):
    args = request.args
    cookie = request.cookies
    page = 0
    sessionInfo = {}

    if not args.has_key('page'):
        page = 1
    else:
        page = args['page']

    import loadHome
    ques, hot_articles = loadHome.load_home(int(page), 1)

    if cookie.has_key('session_id'):
        sessionInfo = getSessionInfo(
            red, cookie['session_id'],
            ['nickname', 'head_url', 'reputation', 'authority'])

    return render_template('home.html',
                           questions=ques,
                           type='questions',
                           user=sessionInfo,
                           url='/questions/newest',
                           hot_articles=hot_articles)
示例#4
0
def new_articles(request, red):
    args = request.args
    cookie = request.cookies
    page = 0
    sessionInfo = {}

    if not args.has_key('page'):
        page = 1
    else:
        page = args['page']

    import loadArticles
    arti = loadArticles.load_articles(int(page), 1)

    print '=================='
    print arti
    print '=================='

    if cookie.has_key('session_id'):
        sessionInfo = getSessionInfo(
            red, cookie['session_id'],
            ['nickname', 'head_url', 'reputation', 'authority'])

    return render_template('articles.html',
                           articles=arti,
                           user=sessionInfo,
                           type='new')
示例#5
0
def activity():
    cookie = request.cookies
    sessionInfo = {}

    if cookie.has_key('session_id'):
        session_id  = cookie['session_id']
        sessionInfo = getSessionInfo(red, session_id, ['nickname', 'head_url', 'authority'])


    return render_template('activity.html', user=sessionInfo)
示例#6
0
def upload_head():
    info = ''
    ret_data = {}
    req  = {}

    if request.cookies.has_key('session_id'):
        session_id = request.cookies['session_id']
    else:
        info = 'user not login'
        return check_result(False, USER_NOT_LOGIN, info, ret_data)

    sessionInfo = getSessionInfo(red, session_id, ['uid'])

    if not session_id:
        info = 'user not login'
        return check_result(False, USER_NOT_LOGIN, info, ret_data)

    req['uid'] = sessionInfo['uid']

    print 'upload'
    if request.method == 'POST':
        try:
            file = request.files['File1']
        except Exception as e:
            print e
            print e.message

        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            file.save(os.path.join(server.config['UPLOAD_HEAD_FOLDER'], filename))

        ret = {
                "success":1,
                "message":"success",
                "url":"http://" + HOST + ":" + str(PORT) + "/static/upload_head/" + filename
        }

        import updateUserInfo
        result, mtype, info, ret_data = updateUserInfo.updateUserInfo(req, 'head_url', ret['url'])

        red.hset(session_id, 'head_url', ret['url'])

        ret = json.dumps(ret)
        response = make_response(ret)
        response.headers['Access-Control-Allow-Origin'] = '*'

        return response
示例#7
0
def hello_world():
    cookie      = request.cookies
    sessionInfo = {}
    info        = ''
    page        = 1

    req = request.args

    if req.has_key('page'):
        page = req['page']

    import loadHome
    ques, hot_articles = loadHome.load_home(int(page), 1)

    if cookie.has_key('session_id'):
        sessionInfo = getSessionInfo(red, cookie['session_id'], ['nickname', 'head_url', 'reputation', 'authority'])

    return render_template('home.html', questions=ques, type='questions', user=sessionInfo, url='/', hot_articles=hot_articles)
示例#8
0
def write_article(request, red):
    ret_data = {}
    req_data = request.get_data()
    try:
        req = json.loads(req_data)
    except ValueError:
        info = 'register failed:json analyse failure'
        logger.error(info)
        return check_result(False, JSON_ERR_ANALY, info, ret_data)

    session_id = request.cookies['session_id']
    sessionInfo = getSessionInfo(red, session_id, ['uid'])

    req['uid'] = sessionInfo['uid']

    import writeArticle
    result, mtype, info, ret_data = writeArticle.writeArticle(req)

    response = make_response(check_result(result, mtype, info, ret_data))
    response.headers['Access-Control-Allow-Origin'] = '*'
    return response
示例#9
0
def scan_article(aid):
    cookie = request.cookies
    sessionInfo = {}

    if cookie.has_key('session_id'):
        session_id  = cookie['session_id']
        sessionInfo = getSessionInfo(red, session_id, ['nickname', 'head_url', 'authority'])

    import loadArticle
    result, mtype, info, ret_data = loadArticle.loadArticle(aid)

    if result == True:
        arti      = ret_data['article']
        comments  = ret_data['comments']
        title     = arti[0]
        content   = markdown.markdown(arti[1], extensions=['markdown.extensions.extra'])
        scan_time = arti[2]
        agree_time= arti[3]
        time      = arti[4]

        return render_template('article.html', user=sessionInfo, comments=comments, title=title, content=content, scan_time=scan_time,
                               agree_time=agree_time, time=time, aid=aid, comment_num=len(comments))
    else:
        return abort()