예제 #1
0
def submit_rating():
    student = get_current_student()
    qaire_id = request.form['qaire_id']
    like = request.form['like']

    qaires = Questionnaire.select().where(Questionnaire.id == qaire_id)

    for qaire in qaires:
        ratings = Rating.select().where(Rating.student == student).where(Rating.questionnaire == qaire)
        for rating in ratings:
            return response_error('already_rated')

        if like == "1" or like == "true":
            like = True
        else:
            like = False

        Rating.create(like=like, student=student, questionnaire=qaire)

        return response_success()

    return response_error('questionnaire_not_found')
예제 #2
0
파일: common.py 프로젝트: vojto/riddle
def get_rating():
    qaire_id = request.form['qaire_id']

    qaires = Questionnaire.select().where(Questionnaire.id == qaire_id)
    for qaire in qaires:
        ratings = Rating.select(Rating, fn.Count(Rating.id).alias('count')).where(Rating.questionnaire == qaire).group_by(Rating.like)
        ret = {'likes': 0, 'dislikes': 0}

        for rating in ratings:
            if rating.like:
                ret['likes'] = rating.count
            else:
                ret['dislikes'] = rating.count

        return json.dumps(ret)

    return response_error('questionnaire_not_found')
예제 #3
0
def get_rating():
    qaire_id = request.form['qaire_id']

    qaires = Questionnaire.select().where(Questionnaire.id == qaire_id)
    for qaire in qaires:
        ratings = Rating.select(Rating,
                                fn.Count(Rating.id).alias('count')).where(
                                    Rating.questionnaire == qaire).group_by(
                                        Rating.like)
        ret = {'likes': 0, 'dislikes': 0}

        for rating in ratings:
            if rating.like:
                ret['likes'] = rating.count
            else:
                ret['dislikes'] = rating.count

        return json.dumps(ret)

    return response_error('questionnaire_not_found')