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

Finalizada a implementação de matrícula em turma close #45 #46

Merged
merged 1 commit into from
Nov 12, 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
2 changes: 1 addition & 1 deletion Procfile
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 -
1 change: 1 addition & 0 deletions pypro/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
'collectfast',
'django.contrib.staticfiles',
'pypro.base',
'pypro.turmas',
'pypro.aperitivos',
'pypro.modulos',
'ordered_model',
Expand Down
Empty file added pypro/turmas/__init__.py
Empty file.
20 changes: 20 additions & 0 deletions pypro/turmas/admin.py
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', )
6 changes: 6 additions & 0 deletions pypro/turmas/apps.py
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"
31 changes: 31 additions & 0 deletions pypro/turmas/migrations/0001_initial.py
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()),
],
),
]
51 changes: 51 additions & 0 deletions pypro/turmas/migrations/0002_criacao_matricula.py
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 pypro/turmas/migrations/0003_restricao_de_matricula_unica.py
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.
20 changes: 20 additions & 0 deletions pypro/turmas/models.py
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']
28 changes: 28 additions & 0 deletions pypro/turmas/templates/turmas/indice.html
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 %}

11 changes: 11 additions & 0 deletions pypro/turmas/tests/test_indice.py
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
8 changes: 8 additions & 0 deletions pypro/turmas/urls.py
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'),
]
6 changes: 6 additions & 0 deletions pypro/turmas/views.py
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')
1 change: 1 addition & 0 deletions pypro/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading