コード例 #1
0
ファイル: views.py プロジェクト: nhutlv01/heroku
def getOrPostComment(request, photo_id):
    """
    Get or Post comment
    """
    if request.method == 'GET':
        c = Command()
        result = c.getComment(int(photo_id))
        return JSONResponse(result)

    if request.method == 'POST':
        if 'user_id' in request.session:
            user_id = request.session['user_id']
            text = request.POST['text']
            c = Command(user_id)
            result = c.postComment(int(photo_id), text)
            return JSONResponse(result)
        else:
            return JSONResponse(dict(meta = {'code':401, 'message':'Authentication required'}), status = status.HTTP_401_UNAUTHORIZED)