From 60a4ec15cfc43a2fe12b4cda0db0d89f1ca78b59 Mon Sep 17 00:00:00 2001 From: Arthur Bressan Date: Wed, 4 Nov 2015 21:28:03 -0200 Subject: [PATCH] =?UTF-8?q?Melhorias=20na=20p=C3=A1gina=20de=20rate=5Fpale?= =?UTF-8?q?stra.=20ref=20#3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hotsite/rotas.py | 15 ++++++---- hotsite/templates/index.html | 6 ++-- hotsite/templates/rate_palestra.html | 43 +++++++++++++++++++--------- 3 files changed, 42 insertions(+), 22 deletions(-) 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

-
+