INNER CODE UNIT · Python

vote

kingname/SourceCodeofMongoRedis · chapter_11/QASystem/main.py:141

def vote():
    session_data = redis.fetch_session(request.cookies.get('session'))
    if not session_data:
        return json.dumps({'success': False, 'reason': '未登录!'})
    vote_data = request.json
    is_valid = check_vote(vote_data)
    if not is_valid['success']:
        return json.dumps(is_valid)
    doc_type = vote_data['doc_type']
    value = vote_data['value']
    doc_id = vote_data['doc_id']
    if doc_type == 'question':
        mongo.vote_for_question(doc_id, value)
    else:
        mongo.vote_for_answer(doc_id, value)
    return json.dumps({'success': True})

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…