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 página de detalhamento do módulo #83

Merged
merged 4 commits into from
Apr 12, 2024
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
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ django-s3-folder-storage = "*"
collectfast = "*"
django-debug-toolbar = "*"
sentry-sdk = {extras = ["django"], version = "*"}
django-ordered-model = "*"

[dev-packages]
flake8 = "*"
Expand Down
22 changes: 15 additions & 7 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions pypro/aperitivos/migrations/0002_alter_video_slug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.4 on 2024-04-12 13:32

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('aperitivos', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='video',
name='slug',
field=models.SlugField(max_length=32),
),
]
11 changes: 11 additions & 0 deletions pypro/base/templates/base/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@

<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Módulos
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
{% for modulo in MODULOS %}
<a class="dropdown-item" href="{{ modulo.get_absolute_url }}">{{ modulo.titulo }}</a>
<div class="dropdown-divider"></div>
{% endfor %}
</div>
</li>
</ul>
</div>
</nav>
Expand Down
2 changes: 1 addition & 1 deletion pypro/base/tests/test_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


@pytest.fixture
def resp(client):
def resp(client, db):
resp = client.get(reverse('base:home'))
return resp

Expand Down
Empty file added pypro/modulos/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions pypro/modulos/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.contrib import admin
from ordered_model.admin import OrderedModelAdmin

from pypro.modulos.models import Modulo


@admin.register(Modulo)
class ModuloAdmin(OrderedModelAdmin):
list_display = ('titulo', 'publico', 'move_up_down_links')
prepopulated_fields = {'slug': ('titulo',)}
6 changes: 6 additions & 0 deletions pypro/modulos/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class ModulosConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'pypro.modulos'
5 changes: 5 additions & 0 deletions pypro/modulos/context_processors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from pypro.modulos import facade


def listar_modulos(request):
return {'MODULOS': facade.listar_modulos_ordenados()}
16 changes: 16 additions & 0 deletions pypro/modulos/facade.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from typing import List

from pypro.modulos.models import Modulo


def listar_modulos_ordenados() -> List[Modulo]:
"""
Lista módulos ordenados por títulos
:return:
"""

return list(Modulo.objects.order_by('order').all())


def encontrar_modulo(slug: str) -> Modulo:
return Modulo.objects.get(slug=slug)
28 changes: 28 additions & 0 deletions pypro/modulos/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 5.0.4 on 2024-04-12 13:32

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Modulo',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('order', models.PositiveIntegerField(db_index=True, editable=False, verbose_name='order')),
('titulo', models.CharField(max_length=64)),
('publico', models.TextField()),
('descricao', models.TextField()),
],
options={
'ordering': ('order',),
'abstract': False,
},
),
]
18 changes: 18 additions & 0 deletions pypro/modulos/migrations/0002_modulo_slug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.4 on 2024-04-12 16:49

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('modulos', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='modulo',
name='slug',
field=models.SlugField(null=True),
),
]
22 changes: 22 additions & 0 deletions pypro/modulos/migrations/0003_populando_slug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 5.0.4 on 2024-04-12 16:55

from django.db import migrations
from django.utils.text import slugify


def popular_slug(apps, schema_editor):
Modulo = apps.get_model('modulos', 'Modulo')
for modulo in Modulo.objects.all():
modulo.slug = slugify(modulo.titulo)
modulo.save()

Check warning on line 11 in pypro/modulos/migrations/0003_populando_slug.py

View check run for this annotation

Codecov / codecov/patch

pypro/modulos/migrations/0003_populando_slug.py#L10-L11

Added lines #L10 - L11 were not covered by tests


class Migration(migrations.Migration):

dependencies = [
('modulos', '0002_modulo_slug'),
]

operations = [
migrations.RunPython(popular_slug)
]
18 changes: 18 additions & 0 deletions pypro/modulos/migrations/0004_slug_unico_e_nao_nulo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.4 on 2024-04-12 17:07

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('modulos', '0003_populando_slug'),
]

operations = [
migrations.AlterField(
model_name='modulo',
name='slug',
field=models.SlugField(unique=True),
),
]
Empty file.
19 changes: 19 additions & 0 deletions pypro/modulos/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from django.db import models
from django.urls import reverse
from ordered_model.models import OrderedModel


class Modulo(OrderedModel):
titulo = models.CharField(max_length=64)
publico = models.TextField()
descricao = models.TextField()
slug = models.SlugField(unique=True)

class Meta(OrderedModel.Meta):
pass

def __str__(self):
return self.titulo

Check warning on line 16 in pypro/modulos/models.py

View check run for this annotation

Codecov / codecov/patch

pypro/modulos/models.py#L16

Added line #L16 was not covered by tests

def get_absolute_url(self):
return reverse("modulos:detalhe", kwargs={'slug': self.slug})
18 changes: 18 additions & 0 deletions pypro/modulos/templates/modulos/modulo_detalhe.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% extends 'base/base.html' %}
{% block title %}{{ modulo.titulo }}{% endblock title %}
{% block description %}Página com detalhes do módulo {{ modulo.titulo }}{% endblock description %}
{% block body %}
<div class="container">
<div class="row">
<div class="col-md-12">
<h1 class="mt-4 mb-3">{{ modulo.titulo }}</h1>
<dl>
<dt>Público</dt>
<dd>{{ modulo.publico }}</dd>
<dt>Descrição</dt>
<dd>{{ modulo.descricao }}</dd>
</dl>
</div>
</div>
</div>
{% endblock body %}
27 changes: 27 additions & 0 deletions pypro/modulos/tests/test_aba_de_modulos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from django.urls import reverse
import pytest
from pypro.django_assertions import assert_contains
from model_bakery import baker

from pypro.modulos.models import Modulo


@pytest.fixture
def modulos(db):
return baker.make(Modulo, 2)


@pytest.fixture
def resp(client, modulos):
resp = client.get(reverse('base:home'))
return resp


def test_titulos_dos_modulos(resp, modulos):
for modulo in modulos:
assert_contains(resp, modulo.titulo)


def test_link_dos_modulos(resp, modulos):
for modulo in modulos:
assert_contains(resp, modulo.get_absolute_url())
14 changes: 14 additions & 0 deletions pypro/modulos/tests/test_facade.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pytest
from model_bakery import baker

from pypro.modulos import facade
from pypro.modulos.models import Modulo


@pytest.fixture
def modulos(db):
return [baker.make(Modulo, titulo=s) for s in 'Antes Depois'.split()]


def test_listar_modulos_ordenados(modulos):
assert list(sorted(modulos, key=lambda modulo: modulo.order)) == facade.listar_modulos_ordenados()
29 changes: 29 additions & 0 deletions pypro/modulos/tests/test_modulo_detalhe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from django.urls import reverse
import pytest
from pypro.django_assertions import assert_contains
from model_bakery import baker

from pypro.modulos.models import Modulo


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


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


def test_titulo(resp, modulo: Modulo):
assert_contains(resp, modulo.titulo)


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


def test_publico(resp, modulo: Modulo):
assert_contains(resp, modulo.publico)
9 changes: 9 additions & 0 deletions pypro/modulos/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.urls import path

from pypro.modulos import views


app_name = 'modulos'
urlpatterns = [
path('<slug:slug>', views.detalhe, name='detalhe'),
]
8 changes: 8 additions & 0 deletions pypro/modulos/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.shortcuts import render

from pypro.modulos import facade


def detalhe(request, slug):
modulo = facade.encontrar_modulo(slug)
return render(request, 'modulos/modulo_detalhe.html', {'modulo': modulo})
3 changes: 3 additions & 0 deletions pypro/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
'django.contrib.staticfiles',
'pypro.base',
'pypro.aperitivos',
'pypro.modulos',
'ordered_model',
]

MIDDLEWARE = [
Expand All @@ -71,6 +73,7 @@
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'pypro.modulos.context_processors.listar_modulos',
],
},
},
Expand Down
1 change: 1 addition & 0 deletions pypro/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
path('admin/', admin.site.urls),
path('', include('pypro.base.urls')),
path('aperitivos/', include('pypro.aperitivos.urls')),
path('modulos/', include('pypro.modulos.urls')),
]


Expand Down
Loading