diff --git a/apps/receitas/urls.py b/apps/receitas/urls.py index c6caee2..b72221b 100644 --- a/apps/receitas/urls.py +++ b/apps/receitas/urls.py @@ -2,9 +2,9 @@ from . import views urlpatterns = [ - path('', views.index, name='index'), - path('receitas/', views.receita, name='receita'), # mudar o nome dessa rota para receita.show + path('', views.index, name='receita.index'), path('receitas/criar', views.create, name='receita.create'), + path('receitas/', views.show, name='receita.show'), path('receitas/editar/', views.edit, name='receita.edit'), path('receitas/deletar/', views.destroy, name='receita.destroy'), ] \ No newline at end of file diff --git a/apps/receitas/views.py b/apps/receitas/views.py index 908e710..6c8eb19 100644 --- a/apps/receitas/views.py +++ b/apps/receitas/views.py @@ -6,20 +6,17 @@ def index(request): receitas = Receita.objects.filter(publicada=True) - if 'procurar_receita' in request.GET and request.GET['procurar_receita']: - receitas = receitas.filter(nome__icontains=request.GET['procurar_receita']) + if 'procurar' in request.GET and request.GET['procurar']: + receitas = receitas.filter(nome__icontains=request.GET['procurar']) receitas = receitas.order_by('-data_criacao') return render(request, 'receitas/index.html', {'receitas': receitas}) -def receita(request, receita_id): - return render(request, 'receitas/receita.html', {'receita': get_object_or_404(Receita, pk=receita_id)}) - def create(request): if not request.user.is_authenticated: messages.error(request, 'Realize login para cadastrar uma receita!') - return redirect('index') + return redirect('receita.index') if request.method == 'POST': nome = request.POST['nome'] @@ -49,6 +46,9 @@ def create(request): return render(request, 'receitas/create.html') +def show(request, receita_id): + return render(request, 'receitas/receita.html', {'receita': get_object_or_404(Receita, pk=receita_id)}) + def edit(request, receita_id): if request.method == 'POST': receita = Receita.objects.get(pk=receita_id) diff --git a/apps/templates/partials/_footer.html b/apps/templates/partials/_footer.html index 3f96f1b..04c4226 100644 --- a/apps/templates/partials/_footer.html +++ b/apps/templates/partials/_footer.html @@ -10,7 +10,7 @@ diff --git a/apps/templates/partials/_header.html b/apps/templates/partials/_header.html index a29bdf3..90d8486 100644 --- a/apps/templates/partials/_header.html +++ b/apps/templates/partials/_header.html @@ -1,20 +1,6 @@ {% load static %} - -
- -
-
-
-
-
- - -
-
-
-
-
+{% include 'partials/_search.html' %}
@@ -54,7 +40,7 @@
- diff --git a/apps/templates/partials/_search.html b/apps/templates/partials/_search.html new file mode 100644 index 0000000..44297d4 --- /dev/null +++ b/apps/templates/partials/_search.html @@ -0,0 +1,15 @@ +
+ +
+ +
+
+
+
+ + +
+
+
+
+
\ No newline at end of file diff --git a/apps/templates/receitas/index.html b/apps/templates/receitas/index.html index eae7cca..d18431d 100755 --- a/apps/templates/receitas/index.html +++ b/apps/templates/receitas/index.html @@ -16,7 +16,7 @@ {% endif %} diff --git a/apps/templates/usuarios/dashboard.html b/apps/templates/usuarios/dashboard.html index a76dd31..fd613fa 100644 --- a/apps/templates/usuarios/dashboard.html +++ b/apps/templates/usuarios/dashboard.html @@ -22,7 +22,7 @@

Olá {{ user.username }}

{% endif %}
- +
{{ receita }}
Editar diff --git a/apps/usuarios/views.py b/apps/usuarios/views.py index 9064e13..6637c5b 100644 --- a/apps/usuarios/views.py +++ b/apps/usuarios/views.py @@ -69,7 +69,7 @@ def dashboard(request): def logout(request): auth.logout(request) - return redirect('index') + return redirect('receita.index') def campo_vazio(campo): return not campo.strip()