Skip to content

Commit

Permalink
Implementação do listar e cadastrar tarefas #18
Browse files Browse the repository at this point in the history
  • Loading branch information
tacianosilva committed Nov 5, 2020
1 parent 24ee350 commit 4e46daa
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 13 deletions.
19 changes: 7 additions & 12 deletions tasktracking/tasks/templates/tasks/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,23 @@
{% block content %}
<div class="offset-1 col-10 list-div">
<div class="col-2 add-div">
<i class="fas fa-plus"></i> Adicionar tarefa
<a href="{% url 'cadastrar_tarefa' %}" class="btn">
<i class="fas fa-plus"></i>Adicionar Tarefa
</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>
<ul class="task-list">

{% for tarefa in lista_tarefas %}
<li class="task-item">
<span>Título da tarefa</span>
<span><i class="fas fa-trash"></i></span>
<span><i class="fas fa-edit"></i></span>
</li>
<li class="task-item">
<span>Título da tarefa</span>
<span><i class="fas fa-trash"></i></i></span>
<span><i class="fas fa-edit"></i></span>
</li>
<li class="task-item">
<span>Título da tarefa</span>
<span>{{tarefa}}</span>
<span><i class="fas fa-trash"></i></span>
<span><i class="fas fa-edit"></i></span>
</li>
{% endfor %}
</ul>
</div>
{% endblock%}
35 changes: 35 additions & 0 deletions tasktracking/tasks/templates/tasks/tarefa/cadastrar_tarefa.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{% extends "base.html" %}

{% block titulo %}
<title>PWeb 2020.6 - Adicionar Tarefa</title>
{% endblock %}

{% block content %}
<div class="container">
<form method="post">
{% csrf_token %}

<table class="table table-sm table-responsive-sm">
{% for field in form_tarefa.visible_fields %}
<tr>
<th class="align-middle">
<label>{{ field.label_tag }}</label>
</th>
<td class="align-middle">{{ field }}
{% if field.help_text %}
<small style="color: grey">{{ field.help_text }}</small>
{% endif %}
{% for error in field.errors %}
<p style="color: red">{{ error }}</p>
{% endfor %}
</td>
</tr>
{% endfor %}
</table>

<div>
<input type="submit" value="Salvar">
</div>
</form>
</div>
{% endblock %}
1 change: 1 addition & 0 deletions tasktracking/tasks/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

urlpatterns = [
path('', views.index, name='index'),
path('cadastrar_tarefa', views.cadastrar_tarefa, name='cadastrar_tarefa'),
]
24 changes: 23 additions & 1 deletion tasktracking/tasks/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
from django.shortcuts import render
from django.http import request
from django.shortcuts import redirect, render
from tasks.forms import TarefaForm

from tasks.models import Tarefa

def index(request):
"""View function for home page of site."""

lista_tarefas = Tarefa.objects.all()

context = {
'lista_tarefas': lista_tarefas
}

return render(request, 'tasks/index.html', context=context)


def cadastrar_tarefa(request):
if request.method == 'POST':
form_tarefa = TarefaForm(request.POST)
if form_tarefa.is_valid():
form_tarefa.save()
return redirect('index')
else:
form_tarefa = TarefaForm()

context = {
'form_tarefa': form_tarefa
}
return render(request, 'tasks/tarefa/cadastrar_tarefa.html', context=context)

0 comments on commit 4e46daa

Please sign in to comment.