Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Criado link para páginas de aulas close #41 #42

Merged
merged 1 commit into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pypro/modulos/facade.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import List

from pypro.modulos.models import Modulo
from pypro.modulos.models import Modulo, Aula


def listar_modulos_ordenados() -> List[Modulo]:
Expand All @@ -18,3 +18,7 @@ def encontrar_modulo(slug: str) -> Modulo:

def listar_aulas_de_modulo_ordenadas(modulo: Modulo):
return list(modulo.aula_set.order_by('order').all())


def encontrar_aula(slug):
return Aula.objects.get(slug=slug)
18 changes: 18 additions & 0 deletions pypro/modulos/migrations/0006_aula_vimeo_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.6 on 2023-10-21 13:17

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("modulos", "0005_aula"),
]

operations = [
migrations.AddField(
model_name="aula",
name="vimeo_id",
field=models.CharField(default="1", max_length=32),
),
]
18 changes: 18 additions & 0 deletions pypro/modulos/migrations/0007_alter_vimeo_obrigatorio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.6 on 2023-10-21 13:19

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("modulos", "0006_aula_vimeo_id"),
]

operations = [
migrations.AlterField(
model_name="aula",
name="vimeo_id",
field=models.CharField(max_length=32),
),
]
1 change: 1 addition & 0 deletions pypro/modulos/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Aula(OrderedModel):
slug = models.SlugField(unique=True)
modulo = models.ForeignKey('Modulo', on_delete=models.PROTECT)
order_with_respect_to = 'modulo'
vimeo_id = models.CharField(max_length=32)

class Meta(OrderedModel.Meta):
pass
Expand Down
18 changes: 18 additions & 0 deletions pypro/modulos/templates/modulos/aula_detalhe.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% extends 'base/base.html' %}
{% load static %}
{% block title %}Python Pro - Aperitivo{% endblock title %}
{% block description %}Página com vídeo gratuito de Python{% endblock description %}
{% block body %}
<div class="container">
<div class="row">
<div class="col-md-12">
<h1 class="mt-4 mb-3">{{ aula.titulo | default:"Título não encontrado" }}</h1>
<iframe src="https://player.vimeo.com/video/{{ aula.vimeo_id }}"
width="640" height="480" frameborder="0" allow="autoplay; fullscreen; picture-in-picture"
title="SnapInsta.io-2 Luciano Ramalho OO em Python sem sotaque-(480p)">
</iframe>
</div>
</div>
</div>
{% endblock body %}

2 changes: 1 addition & 1 deletion pypro/modulos/templates/modulos/modulo_detalhe.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h1 class="mt-4 mb-3">{{ modulo.titulo }}</h1>
<h2>Aulas</h2>
<ol>
{% for aula in aulas %}
<li>{{ aula.titulo }}</li>
<li><a href="{{ aula.get_absolute_url }}">{{ aula.titulo }}</a></li>
{% endfor %}
</ol>
</div>
Expand Down
30 changes: 30 additions & 0 deletions pypro/modulos/tests/test_aula_detalhe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import pytest
from django.urls import reverse
from pypro.django_assertions import assert_contains
from model_mommy import mommy

from pypro.modulos.models import Modulo, Aula


@pytest.fixture
def modulo(db):
return mommy.make(Modulo)


@pytest.fixture
def aula(modulo):
return mommy.make(Aula, modulo=modulo)


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


def test_titulo(resp, aula: Aula):
assert_contains(resp, aula.titulo)


def test_vimeo(resp, aula: Aula):
assert_contains(resp, f'src="https://player.vimeo.com/video/{ aula.vimeo_id }"')
5 changes: 5 additions & 0 deletions pypro/modulos/tests/test_modulo_detalhe.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ def test_publico(resp, modulo: Modulo):
def test_aulas_titulos(resp, aulas):
for aula in aulas:
assert_contains(resp, aula.titulo)


def test_aulas_links(resp, aulas):
for aula in aulas:
assert_contains(resp, aula.get_absolute_url())
1 change: 1 addition & 0 deletions pypro/modulos/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
app_name = 'modulos'
urlpatterns = [
path('<slug:slug>', views.detalhe, name='detalhe'),
path('aulas/<slug:slug>', views.aula, name='aula'),
]
5 changes: 5 additions & 0 deletions pypro/modulos/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ def detalhe(request, slug):
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):
aula = facade.encontrar_aula(slug)
return render(request, 'modulos/aula_detalhe.html', {'aula': aula})
Loading