コード例 #1
0
ファイル: views.py プロジェクト: gabrielhpugliese/eventos-usp
def vote(request, event):
    ''' Receives a grade as a POST parameter and event as positional in url.
        Saves the grade in db. '''

    grade_value = request.POST.get('grade')
    if not grade_value:
        return HttpResponseServerError('Param grade not found')

    user = users.get_current_user()
    grade_value = int(grade_value) + 1
    GradeFacade.save_grade(user, grade_value, event)

    return HttpResponse('Voted {0} on event {1}'.format(grade_value, event))
コード例 #2
0
ファイル: views.py プロジェクト: gabrielhpugliese/eventos-usp
def show_grade(request, event):
    ''' Renders the event grade as a json object {'value': int(grade)} '''

    user = users.get_current_user()
    grade_value = GradeFacade.get_grade_value(event, user.nickname())

    response = json.dumps({'value': grade_value})
    return HttpResponse(response, mimetype='application/json')
コード例 #3
0
ファイル: views.py プロジェクト: gabrielhpugliese/eventos-usp
def recommend(request, template='recommendations.html'):
    ''' Renders a html with all recommendations and grades for the user '''

    my_user = users.get_current_user()
    grades = GradeFacade.get_all_grades()
    grades_dct = utils.format_grades(grades)
    my_voted_events = {grade.event for grade
                       in GradeFacade.get_grades_from_user(my_user)}
    all_voted_events = {grade.event for grade in grades
                        if grade.user != my_user}

    filtered_events = filtering.slope_one(my_user, my_voted_events,
                                          all_voted_events, grades_dct)

    recommendations = {}
    for event_key, grade in filtered_events.items():
        event = event_key.get()
        recommendations[event.title] = {'info': event, 'grade': grade}

    template_context = {'recommendations': recommendations}
    return render_to_response(template, template_context)