Skip to content

Commit

Permalink
Apresenta receitas na dashboard do usuário
Browse files Browse the repository at this point in the history
  • Loading branch information
brnocesar committed Jan 22, 2021
1 parent 1b4275f commit 13d19cc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion apps/templates/partials/_header.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
<!-- Nav Start -->
<div class="classynav">
<ul>
<li><a href="{% url 'index' %}">Home</a></li>
{% if user.is_authenticated %}
<li><a href="{% url 'index' %}">Home</a></li>
<li><a href="{% url 'dashboard' %}">Minhas receitas</a></li>
<li><a href="{% url 'receita.create' %}">Nova Receita</a></li>
<li><a href="{% url 'logout' %}">Logout</a></li>
Expand Down
21 changes: 21 additions & 0 deletions apps/templates/usuarios/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,27 @@
<h3>Olá {{ user.username }}</h3>
</div>
</div>

{% if receitas %}
{% for receita in receitas %}
<div class="col-12 col-sm-6 col-lg-4">
<div class="single-best-receipe-area mb-30">
{% if receita.foto == '' %}
<img src="{% static 'img/bg-img/foto_receita.png' %}" alt="">
{% else %}
<img src="{{ receita.foto.url }}" alt="">
{% endif %}
<div class="receipe-content">
<a href="{% url 'receita' receita.id %}">
<h5>{{ receita }}</h5>
</a>
</div>
</div>
</div>
{% endfor %}
{% else %}
<p>Não foram encontradas receitas.</p>
{% endif %}
</div>
</div>
</div>
Expand Down
9 changes: 6 additions & 3 deletions apps/usuarios/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.shortcuts import render, redirect
from django.contrib.auth.models import User
from django.contrib import auth
from apps.receitas.models import Receita

def login(request):
if request.method == 'POST':
Expand Down Expand Up @@ -62,7 +63,9 @@ def cadastro(request):
return render(request, 'usuarios/cadastro.html')

def dashboard(request):
if request.user.is_authenticated:
return render(request, 'usuarios/dashboard.html')
if not request.user.is_authenticated:
return redirect('index')

return redirect('index')
receitas = Receita.objects.filter(pessoa=request.user.id).order_by('data_criacao')

return render(request, 'usuarios/dashboard.html', {'receitas': receitas})

0 comments on commit 13d19cc

Please sign in to comment.