Skip to content

Commit

Permalink
Criado a exibição das turmas cadastradas
Browse files Browse the repository at this point in the history
Close #47
  • Loading branch information
thiago-garcia committed Aug 10, 2024
1 parent 84ef6d0 commit d642231
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 16 deletions.
13 changes: 8 additions & 5 deletions project/base/templates/base/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@
<a class="nav-link dropdown-toggle" href="#" data-bs-toggle="dropdown" aria-expanded="false">Módulos</a>
<ul class="dropdown-menu">
{% for modulo in MODULOS %}
<li>
<a class="dropdown-item" href="{{ modulo.get_absolute_url }}">
{{ modulo.titulo }}
</a>
</li>
<li>
<a class="dropdown-item" href="{{ modulo.get_absolute_url }}">
{{ modulo.titulo }}
</a>
</li>
{% endfor %}
</ul>
</li>
<li class="nav-item">
<a class="nav-link " href="{% url 'turmas:indice' %}">Turmas</a>
</li>
</ul>
{% if user.is_authenticated %}
<ul class="navbar-nav mb-2 mb-lg-0">
Expand Down
9 changes: 9 additions & 0 deletions project/turmas/facade.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from typing import List
from project.turmas.models import Turma


def listar_turmas_ordenadas() -> List[Turma]:
"""
Lista as turmas ordenadas pelo inicio
"""
return list(Turma.objects.order_by('inicio').all())
13 changes: 4 additions & 9 deletions project/turmas/templates/turmas/indice.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@
<div class="container mt-3">
<h2>Confira nossas turmas</h2>

{% for modulo in modulos %}
{% for turma in turmas %}
<div class="bg-body-secondary mt-3 p-3 rounded">
<h3>{{ modulo.titulo }}</h3>
<p>Público: {{ modulo.publico }}</p>
<p>Descrição: {{ modulo.descricao }}.</p>
<ol>
{% for aula in modulo.aulas %}
<li><a href="{{ aula.get_absolute_url }}">{{ aula.titulo }}</a></li>
{% endfor %}
</ol>
<h3 class="mb-3">{{ turma.nome }}</h3>
<p>Data de inicio: {{ turma.inicio|date:"d/m/Y" }}</p>
<p>Data de término: {{ turma.fim|date:"d/m/Y" }}.</p>
</div>
{% endfor %}
</div>
Expand Down
25 changes: 24 additions & 1 deletion project/turmas/tests/test_indice.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
import pytest
from django.urls import reverse
from model_bakery import baker
from project.turmas.models import Turma
from project.django_assertions import assert_contains


@pytest.fixture
def resp(client, db):
def turmas(db):
return baker.make(Turma, 2)


@pytest.fixture
def resp(client, turmas):
return client.get(reverse('turmas:indice'))


def test_status_code(resp):
assert resp.status_code == 200


def test_nomes_turmas(resp, turmas):
for turma in turmas:
assert_contains(resp, turma.nome)


def test_inicio_turmas(resp, turmas):
for turma in turmas:
assert_contains(resp, turma.inicio.strftime("%d/%m/%Y"))


def test_fim_turmas(resp, turmas):
for turma in turmas:
assert_contains(resp, turma.fim.strftime("%d/%m/%Y"))
5 changes: 4 additions & 1 deletion project/turmas/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from django.shortcuts import render
from project.turmas import facade


def indice(request):
return render(request, 'turmas/indice.html')
turmas = facade.listar_turmas_ordenadas()

return render(request, 'turmas/indice.html', {'turmas': turmas})

0 comments on commit d642231

Please sign in to comment.