-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finalizada a implementação de matrícula em turma close #45
- Loading branch information
1 parent
7a85ac7
commit 593effe
Showing
15 changed files
with
207 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
release: python manage.py migrate --noinput | ||
deac | ||
web: gunicorn pypro.wsgi --log-file - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class TurmasConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "pypro.turmas" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
), | ||
), | ||
] |
23 changes: 23 additions & 0 deletions
23
pypro/turmas/migrations/0003_restricao_de_matricula_unica.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")}, | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 %} | ||
<div class="container"> | ||
{% for modulo in modulos %} | ||
<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> | ||
<h2>Aulas</h2> | ||
<ol> | ||
{% for aula in modulo.aulas %} | ||
<li><a href="{{ aula.get_absolute_url }}">{{ aula.titulo }}</a></li> | ||
{% endfor %} | ||
</ol> | ||
</div> | ||
</div> | ||
{% endfor %} | ||
</div> | ||
{% endblock body %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django.urls import path | ||
|
||
from pypro.turmas import views | ||
|
||
app_name = 'turmas' | ||
urlpatterns = [ | ||
path('', views.indice, name='indice'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.shortcuts import render | ||
|
||
|
||
# Create your views here. | ||
def indice(request): | ||
return render(request, 'turmas/indice.html') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters