Skip to content

Commit

Permalink
Melhorias na página de rate_palestra. ref #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Bressan committed Nov 4, 2015
1 parent 5b4b98d commit 60a4ec1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 22 deletions.
15 changes: 9 additions & 6 deletions hotsite/rotas.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,20 @@ def login():
return redirect(url_for('auth.login'))


@bp.route('/avaliar/<palestra>', methods=['GET', 'POST'])
@bp.route('/palestras/<titulo_slug>', 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,
comentario=comentario,
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)
6 changes: 3 additions & 3 deletions hotsite/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
{{ palestra.autor }}
</td>
<td>
<a href="{{ url_for('palestras.rate_palestra', palestra=palestra.id) }}" >Avaliar </a>
<a href="{{ url_for('palestras.rate_palestra', titulo_slug=palestra.titulo_slug) }}" >Avaliar </a>
</td>
</tr>
{% endfor %}
Expand Down Expand Up @@ -93,7 +93,7 @@
<ul class="nav navbar-nav navbar-right">
<li class="active"><a class="page-scroll" href="#body-container">Home</a></li>
<li class="active"><a class="page-scroll" href="#sobre">Sobre</a></li>
<li><a class="page-scroll" href="#cursos">Cursos</a></li>
<li><a class="page-scroll" href="#palestras">Palestras</a></li>
<li><a class="page-scroll" href="#contact-section">Localização</a></li>
</ul>
</div>
Expand Down Expand Up @@ -142,7 +142,7 @@ <h1>Sobre a <span class="text-main">Semana Acadêmica</span></h1>
</div>
<div class="more-space-l"></div>
</section>
<section id="cursos" class="page">
<section id="palestras" class="page">
<div class="page-header-wrapper">
<div class="container">
<div class="page-header text-center wow fadeInUp" data-wow-delay="0.3s">
Expand Down
43 changes: 30 additions & 13 deletions hotsite/templates/rate_palestra.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,36 @@ <h2>{{ palestra.autor }}</h2>
<p style="margin-bottom: 100px;">
{{ palestra.bio_autor }}
</p>
<h1 style="margin-bottom: 30px;">Dê a sua avaliação!</h1>
<form action="{{ url_for('palestras.rate_palestra', palestra=palestra.id) }}" method="POST">
<textarea name="comentario" class="form-control" rows="5" style="margin-bottom: 10px"></textarea>
<button type="submit" name="rating" value="-1" class="btn btn-danger">
<i class="fa fa-thumbs-down fa-3x" name="rating" value="1" style="color: white;"></i>
</button>
<span style="margin-left: 10px; margin-right: 10px;">
</span>
<button type="submit" name="rating" value="1" class="btn btn-success">
<i class="fa fa-thumbs-up fa-3x" name="rating" value="1" style="color: white;"></i>
</button>
</form>
<div class="more-space-m"></div>
{% if palestra_aluno %}
<h1>Obrigado por sua avaliação!</h1>
<p>
Sua avaliação:
{% if palestra_aluno.rating == 1 %}
<i class="fa fa-thumbs-up fa-3x"></i>
{% else %}
<i class="fa fa-thumbs-down fa-3x"></i>
{% endif %}
</p>
{% if palestra_aluno.comentario %}
<p>
Seu comentário: {{ palestra_aluno.comentario }}
</p>
{% endif %}
{% else %}
<h1 style="margin-bottom: 30px;">Dê a sua avaliação!</h1>
<form action="{{ url_for('palestras.rate_palestra', titulo_slug=palestra.titulo_slug) }}" method="POST">
<textarea name="comentario" class="form-control" rows="5" style="margin-bottom: 10px"></textarea>
<button type="submit" name="rating" value="-1" class="btn btn-danger">
<i class="fa fa-thumbs-down fa-3x" name="rating" value="1" style="color: white;"></i>
</button>
<span style="margin-left: 10px; margin-right: 10px;">
</span>
<button type="submit" name="rating" value="1" class="btn btn-success">
<i class="fa fa-thumbs-up fa-3x" name="rating" value="1" style="color: white;"></i>
</button>
</form>
<div class="more-space-m"></div>
{% endif %}
<h3><a href="{{ url_for('index') }}"><i class="fa fa-chevron-left"></i> Voltar</a></h3>
</div></div>
</div>
Expand Down

0 comments on commit 60a4ec1

Please sign in to comment.