diff --git a/Procfile b/Procfile index 01e0e2f..a5ca7be 100644 --- a/Procfile +++ b/Procfile @@ -1,2 +1,2 @@ -release: python manage.py migrate --noinput +deac web: gunicorn pypro.wsgi --log-file - \ No newline at end of file diff --git a/pypro/settings.py b/pypro/settings.py index 29a1aff..d61b91e 100644 --- a/pypro/settings.py +++ b/pypro/settings.py @@ -46,6 +46,7 @@ 'collectfast', 'django.contrib.staticfiles', 'pypro.base', + 'pypro.turmas', 'pypro.aperitivos', 'pypro.modulos', 'ordered_model', diff --git a/pypro/turmas/__init__.py b/pypro/turmas/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pypro/turmas/admin.py b/pypro/turmas/admin.py new file mode 100644 index 0000000..c08af5e --- /dev/null +++ b/pypro/turmas/admin.py @@ -0,0 +1,20 @@ +from django.contrib import admin + +# Register your models here. +from pypro.turmas.models import Turma + + +class MatriculaInline(admin.TabularInline): + model = Turma.alunos.through + extra = 1 + readonly_fields = ('data',) + autocomplete_fields = ('usuario',) + ordering = ('-data',) + + +@admin.register(Turma) +class TurmaAdmin(admin.ModelAdmin): + inlines = [MatriculaInline] + list_display = ('nome', 'slug', 'inicio', 'fim') + prepopulated_fields = {'slug': ('nome', )} + ordering = ('-inicio', ) diff --git a/pypro/turmas/apps.py b/pypro/turmas/apps.py new file mode 100644 index 0000000..3f536ce --- /dev/null +++ b/pypro/turmas/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class TurmasConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "pypro.turmas" diff --git a/pypro/turmas/migrations/0001_initial.py b/pypro/turmas/migrations/0001_initial.py new file mode 100644 index 0000000..95beb2f --- /dev/null +++ b/pypro/turmas/migrations/0001_initial.py @@ -0,0 +1,31 @@ +# Generated by Django 4.2.6 on 2023-11-11 23:10 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [] + + operations = [ + migrations.CreateModel( + name="Turma", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("nome", models.CharField(max_length=64)), + ("slug", models.SlugField(max_length=64)), + ("inicio", models.DateField()), + ("fim", models.DateField()), + ], + ), + ] diff --git a/pypro/turmas/migrations/0002_criacao_matricula.py b/pypro/turmas/migrations/0002_criacao_matricula.py new file mode 100644 index 0000000..6bfe793 --- /dev/null +++ b/pypro/turmas/migrations/0002_criacao_matricula.py @@ -0,0 +1,51 @@ +# Generated by Django 4.2.6 on 2023-11-12 00:22 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ("turmas", "0001_initial"), + ] + + operations = [ + migrations.CreateModel( + name="Matricula", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("data", models.DateTimeField(auto_now_add=True)), + ( + "turma", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="turmas.turma" + ), + ), + ( + "usuario", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to=settings.AUTH_USER_MODEL, + ), + ), + ], + ), + migrations.AddField( + model_name="turma", + name="alunos", + field=models.ManyToManyField( + through="turmas.Matricula", to=settings.AUTH_USER_MODEL + ), + ), + ] diff --git a/pypro/turmas/migrations/0003_restricao_de_matricula_unica.py b/pypro/turmas/migrations/0003_restricao_de_matricula_unica.py new file mode 100644 index 0000000..86bfb9f --- /dev/null +++ b/pypro/turmas/migrations/0003_restricao_de_matricula_unica.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.6 on 2023-11-12 00:33 + +from django.conf import settings +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ("turmas", "0002_criacao_matricula"), + ] + + operations = [ + migrations.AlterModelOptions( + name="matricula", + options={"ordering": ["turma", "data"]}, + ), + migrations.AlterUniqueTogether( + name="matricula", + unique_together={("usuario", "turma")}, + ), + ] diff --git a/pypro/turmas/migrations/__init__.py b/pypro/turmas/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pypro/turmas/models.py b/pypro/turmas/models.py new file mode 100644 index 0000000..9a74319 --- /dev/null +++ b/pypro/turmas/models.py @@ -0,0 +1,20 @@ +from django.db import models +from django.contrib.auth import get_user_model + + +class Turma(models.Model): + nome = models.CharField(max_length=64) + slug = models.SlugField(max_length=64) + inicio = models.DateField() + fim = models.DateField() + alunos = models.ManyToManyField(get_user_model(), through='Matricula') + + +class Matricula(models.Model): + data = models.DateTimeField(auto_now_add=True) + usuario = models.ForeignKey(get_user_model(), on_delete=models.CASCADE) + turma = models.ForeignKey(Turma, on_delete=models.CASCADE) + + class Meta: + unique_together = [['usuario', 'turma']] + ordering = ['turma', 'data'] diff --git a/pypro/turmas/templates/turmas/indice.html b/pypro/turmas/templates/turmas/indice.html new file mode 100644 index 0000000..9c5d18c --- /dev/null +++ b/pypro/turmas/templates/turmas/indice.html @@ -0,0 +1,28 @@ +{% extends 'base/base.html' %} +{% load static %} +{% block title %}Índice de turmas{% endblock title %} +{% block description %}Página com todas as turmas do curso Dev Pro {{modulo.titulo}}{% endblock description %} +{% block body %} +
+ {% for modulo in modulos %} +
+
+

{{ modulo.titulo }}

+
+
Público
+
{{ modulo.publico }}
+
Descrição
+
{{ modulo.descricao }}
+
+

Aulas

+
    + {% for aula in modulo.aulas %} +
  1. {{ aula.titulo }}
  2. + {% endfor %} +
+
+
+ {% endfor %} +
+{% endblock body %} + diff --git a/pypro/turmas/tests/test_indice.py b/pypro/turmas/tests/test_indice.py new file mode 100644 index 0000000..729a6bb --- /dev/null +++ b/pypro/turmas/tests/test_indice.py @@ -0,0 +1,11 @@ +import pytest +from django.urls import reverse + + +@pytest.fixture +def resp(client, db): + return client.get(reverse('turmas:indice')) + + +def test_status_code(resp): + assert resp.status_code == 200 diff --git a/pypro/turmas/urls.py b/pypro/turmas/urls.py new file mode 100644 index 0000000..2d1e274 --- /dev/null +++ b/pypro/turmas/urls.py @@ -0,0 +1,8 @@ +from django.urls import path + +from pypro.turmas import views + +app_name = 'turmas' +urlpatterns = [ + path('', views.indice, name='indice'), +] diff --git a/pypro/turmas/views.py b/pypro/turmas/views.py new file mode 100644 index 0000000..08445ff --- /dev/null +++ b/pypro/turmas/views.py @@ -0,0 +1,6 @@ +from django.shortcuts import render + + +# Create your views here. +def indice(request): + return render(request, 'turmas/indice.html') diff --git a/pypro/urls.py b/pypro/urls.py index 094a870..3475bb6 100644 --- a/pypro/urls.py +++ b/pypro/urls.py @@ -24,6 +24,7 @@ path('', include('pypro.base.urls')), path('aperitivos/', include('pypro.aperitivos.urls')), path('modulos/', include('pypro.modulos.urls')), + path('turmas/', include('pypro.turmas.urls')), ] if settings.DEBUG: