Skip to content

Commit

Permalink
Add metodo de criar tags #16 #21
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonasfaria committed Nov 13, 2020
1 parent ec93adf commit 03e4031
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 4 deletions.
7 changes: 6 additions & 1 deletion tasktracking/tasks/forms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django import forms
from tasks.models import Link, Tarefa
from tasks.models import Link, Tarefa, Tag


class TarefaForm(forms.ModelForm):
Expand All @@ -11,3 +11,8 @@ class LinkForm(forms.ModelForm):
class Meta:
model = Link
fields = '__all__'

class TagForm(forms.ModelForm):
class Meta:
model = Tag
fields = '__all__'
19 changes: 19 additions & 0 deletions tasktracking/tasks/migrations/0005_tag_tarefa.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 3.1.2 on 2020-11-13 01:58

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('tasks', '0004_link_tarefa'),
]

operations = [
migrations.AddField(
model_name='tag',
name='tarefa',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='tasks.tarefa'),
),
]
7 changes: 7 additions & 0 deletions tasktracking/tasks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ class Usuario(models.Model):
def __str__(self):
return self.nome


class Tag(models.Model):
"""
Jonas
Args:
models ([type]): [description]
"""
nome = models.CharField(max_length=50)
tarefa = models.ForeignKey('Tarefa', on_delete=models.CASCADE, null=True)

def __str__(self):
return self.nome


class Link(models.Model):
"""
Expand Down Expand Up @@ -70,6 +76,7 @@ class Tarefa(models.Model):
def __str__(self):
return self.identificador + ' - ' + self.nome


class Execucao(models.Model):
"""[summary]
Pedro
Expand Down
3 changes: 1 addition & 2 deletions tasktracking/tasks/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul type="disc" class="navbar-nav">
<li><a class="nav-link" href="#">Tarefas</a></li>
<li><a class="nav-link" href="#">Tags</a></li>
<li><a class="nav-link" href="/cadastrar_tag">Tags</a></li>
<li><a class="nav-link" href="/cadastrar_link">Links</a></li>
<li><a class="nav-link" href="#">Usuário</a></li>
<li><a class="nav-link" href="#">Execuções</a></li>
</ul>
</div>
Expand Down
35 changes: 35 additions & 0 deletions tasktracking/tasks/templates/tasks/tags/cadastrar_tag.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 Tags</title>
{% endblock %}

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

<table class="table table-sm table-responsive-sm">
{% for field in form_tag.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 %}
10 changes: 10 additions & 0 deletions tasktracking/tasks/templates/tasks/tarefa/detalhar.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@
</ul>
</td>
</tr>
<tr>
<td class="font-weight-bold" width="20%">Tags</td>
<td>
<ul>
{% for tag in object.tag_set.all %}
<li>{{ tag }}</li>
{% endfor %}
</ul>
</td>
</tr>
</table>
</div>
{% endblock%}
1 change: 1 addition & 0 deletions tasktracking/tasks/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
path('cadastrar_tarefa', views.cadastrar_tarefa, name='cadastrar_tarefa'),
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'),
]
18 changes: 17 additions & 1 deletion tasktracking/tasks/views.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
from django.http import request
from django.shortcuts import redirect, render
from django.views.generic import DetailView
from tasks.forms import LinkForm, TarefaForm
from tasks.forms import LinkForm, TarefaForm, TagForm

from tasks.models import Tarefa
from tasks.models import Link
from tasks.models import Tag

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

lista_tarefas = Tarefa.objects.all()
lista_link = Link.objects.all()
lista_tag = Tag.objects.all()

context = {
'lista_tarefas': lista_tarefas
Expand Down Expand Up @@ -53,3 +55,17 @@ def cadastrar_link(request):
}
return render(request, 'tasks/link/cadastrar_link.html', context=context)


def cadastrar_tag(request):
if request.method == 'POST':
form_tag = TagForm(request.POST)
if form_tag.is_valid():
form_tag.save()
return redirect('index')
else:
form_tag = TagForm()

context = {
'form_tag': form_tag
}
return render(request, 'tasks/tags/cadastrar_tag.html', context=context)

0 comments on commit 03e4031

Please sign in to comment.