Skip to content

Commit

Permalink
Implementação do Buscar Tarefa pelo nome #18
Browse files Browse the repository at this point in the history
  • Loading branch information
tacianosilva committed Nov 19, 2020
1 parent 93c5258 commit 10f00c3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
12 changes: 8 additions & 4 deletions tasktracking/tasks/templates/tasks/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,20 @@
</a>
</div>

<div class="col-9 search-div">
<input class="form-control" type="text" id="search" name="search" placeholder="Digite o nome da tarefa para buscar...">
<i class="fas fa-search"></i>
</div>
<form action="/pesquisar_tarefas" method="post" class="col-9 search-div">
{% csrf_token %}
<input class="form-control" type="text" id="search" name="search"
placeholder="Digite o nome da tarefa para buscar...">
<button type="submit" class="fas fa-search btn-light">
</button>
</form>

<ul class="task-list">
{% for tarefa in lista_tarefas %}
<li class="task-item">
<span><i class="fas fa-play"></i></span>
<span><i class="fas fa-stop"></i></span>
<span>&nbsp;</span>
<a href="{% url 'detalhar_tarefa' tarefa.pk %}"
<span>{{ tarefa }}</span>
</a>
Expand Down
1 change: 1 addition & 0 deletions tasktracking/tasks/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
path('detalhar_tarefa/<int:pk>/', views.TarefaDetailView.as_view(), name='detalhar_tarefa'),
path('cadastrar_link', views.cadastrar_link, name='cadastrar_link'),
path('cadastrar_tag', views.cadastrar_tag, name='cadastrar_tag'),
path('pesquisar_tarefas', views.buscar_tarefas, name='buscar_tarefas'),
]
14 changes: 13 additions & 1 deletion tasktracking/tasks/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,16 @@ def cadastrar_tag(request):
context = {
'form_tag': form_tag
}
return render(request, 'tasks/tags/cadastrar_tag.html', context=context)
return render(request, 'tasks/tags/cadastrar_tag.html', context=context)


def buscar_tarefas(request):

search = request.POST.get("search")

lista_tarefas = Tarefa.objects.filter(nome__icontains=search)

context = {
'lista_tarefas': lista_tarefas
}
return render(request, 'tasks/index.html', context=context)

0 comments on commit 10f00c3

Please sign in to comment.