Skip to content

Commit

Permalink
Adicionado a busca dinamica do modulo e aulas
Browse files Browse the repository at this point in the history
Close #30
  • Loading branch information
thiago-garcia committed Aug 2, 2024
1 parent 419727d commit ad0e4e9
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 11 deletions.
8 changes: 8 additions & 0 deletions project/modulos/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ def listar_modulos_com_aulas():
"""
aulas_ordenadas = Aula.objects.order_by('order').all()
return Modulo.objects.order_by('order').prefetch_related(Prefetch('aula_set', aulas_ordenadas, 'aulas')).all()


def encontrar_modulo(slug):
return Modulo.objects.get(slug=slug)


def listar_aulas_de_modulo_ordenadas(modulo):
return modulo.aula_set.order_by('order').all()
13 changes: 7 additions & 6 deletions project/modulos/templates/modulos/modulo_detalhe.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{% extends "base/base.html" %}
{% block title %}Site de aulas - Módulos{% endblock title %}
{% block title %}Site de aulas - {{ modulo.titulo }}{% endblock title %}
{% block body %}
<div class="container mt-3">
<h2>Conheça nossos módulos</h2>

<div class="bg-body-secondary mt-3 p-3 rounded">
<h3>Introdução</h3>
<p>Público: Iniciantes</p>
<p>Descrição: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed viverra purus ipsum. Nulla facilisi.</p>
<h3>{{ modulo.titulo }}</h3>
<p>Público: {{ modulo.publico }}</p>
<p>Descrição: {{ modulo.descricao }}.</p>
<ol>
<li><a href="/modulos/aulas/aula-inicial">Aula inicial</a></li>
<li><a href="/modulos/aulas/historia-do-computador">História do computador</a></li>
{% for aula in aulas %}
<li><a href="{{ aula.get_absolute_url }}">{{ aula.titulo }}</a></li>
{% endfor %}
</ol>
</div>
</div>
Expand Down
40 changes: 37 additions & 3 deletions project/modulos/tests/test_modulo_detalhe.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,47 @@
from django.urls import reverse
import pytest
# from project.django_assertions import assert_contains
from model_bakery import baker
from project.modulos.models import Modulo, Aula
from project.django_assertions import assert_contains


@pytest.fixture
def resp(client, db):
resp = client.get(reverse('modulos:detalhe', kwargs={'slug': 'introducao'}))
def modulo(db):
return baker.make(Modulo)


@pytest.fixture
def aulas(modulo):
return baker.make(Aula, 3, modulo=modulo)


@pytest.fixture
def resp(client, modulo, aulas):
resp = client.get(reverse('modulos:detalhe', kwargs={'slug': modulo.slug}))
return resp


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


def test_titulo(resp, modulo):
assert_contains(resp, f'<h3>{modulo.titulo}</h3>')


def test_publico(resp, modulo):
assert_contains(resp, modulo.publico)


def test_descricao(resp, modulo):
assert_contains(resp, modulo.descricao)


def test_aulas_titulo(resp, aulas):
for aula in aulas:
assert_contains(resp, aula.titulo)


def test_aulas_link(resp, aulas):
for aula in aulas:
assert_contains(resp, aula.get_absolute_url())
5 changes: 3 additions & 2 deletions project/modulos/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ def indice(request):


def detalhe(request, slug):
if slug == 'introducao':
return render(request, 'modulos/modulo_detalhe.html')
modulo = facade.encontrar_modulo(slug)
aulas = facade.listar_aulas_de_modulo_ordenadas(modulo)
return render(request, 'modulos/modulo_detalhe.html', {'modulo': modulo, 'aulas': aulas})


def aula(request, slug):
Expand Down

0 comments on commit ad0e4e9

Please sign in to comment.