diff --git a/hotsite/rotas.py b/hotsite/rotas.py index 72158d5..1dbdf53 100644 --- a/hotsite/rotas.py +++ b/hotsite/rotas.py @@ -36,11 +36,14 @@ def login(): return redirect(url_for('auth.login')) -@bp.route('/avaliar/', methods=['GET', 'POST']) +@bp.route('/palestras/', methods=['GET', 'POST']) @login_required -def rate_palestra(palestra): - palestra = Palestra.query.get_or_404(palestra) - if request.method == 'POST': +def rate_palestra(titulo_slug): + palestra = Palestra.query.filter_by(titulo_slug=titulo_slug).one() + palestra_aluno = PalestraAluno.query \ + .filter_by(palestra_id=palestra.id, aluno_id=current_user.id) \ + .first() + if request.method == 'POST' and not palestra_aluno: comentario = request.form['comentario'] rating = int(request.form['rating']) palestra_aluno = PalestraAluno(palestra_id=palestra.id, rating=rating, @@ -48,5 +51,5 @@ def rate_palestra(palestra): aluno_id=current_user.id) db.session.add(palestra_aluno) db.session.commit() - return redirect(url_for('.index')) - return render_template('rate_palestra.html', palestra=palestra) + return render_template('rate_palestra.html', palestra=palestra, + palestra_aluno=palestra_aluno) diff --git a/hotsite/templates/index.html b/hotsite/templates/index.html index 095f753..24e1c1d 100644 --- a/hotsite/templates/index.html +++ b/hotsite/templates/index.html @@ -43,7 +43,7 @@ {{ palestra.autor }} - Avaliar + Avaliar {% endfor %} @@ -93,7 +93,7 @@ @@ -142,7 +142,7 @@

Sobre a Semana Acadêmica

-
+