diff --git a/scheduleManagement/forms.py b/scheduleManagement/forms.py
new file mode 100644
index 0000000..c87e9c9
--- /dev/null
+++ b/scheduleManagement/forms.py
@@ -0,0 +1,10 @@
+from django import forms
+from django.contrib.auth.forms import UserCreationForm
+from django.contrib.auth.models import User
+
+class CustomUserCreationForm(UserCreationForm):
+ email = forms.EmailField(required=True)
+
+ class Meta:
+ model = User
+ fields = ("username", "email", "password1", "password2")
\ No newline at end of file
diff --git a/scheduleManagement/templates/home.html b/scheduleManagement/templates/home.html
index 0cd3efa..be62092 100644
--- a/scheduleManagement/templates/home.html
+++ b/scheduleManagement/templates/home.html
@@ -6,6 +6,16 @@
{% block title %}
Home page {% endblock %}
+ {% block navbar %}
+
+ {% endblock %}
+
{% block content%}
Courses
Disciplines
diff --git a/scheduleManagement/templates/list-object.html b/scheduleManagement/templates/list-object.html
index 3ed93d6..4a9dab3 100644
--- a/scheduleManagement/templates/list-object.html
+++ b/scheduleManagement/templates/list-object.html
@@ -7,8 +7,11 @@ {{ object_type | title }} | List
{% for object in objects %}
{{ object }}
+
+ {% empty %}
+ No {{ object_type | title }} yet
{% endfor %}
-
+
Back
{% endblock %}
diff --git a/scheduleManagement/templates/registration/login.html b/scheduleManagement/templates/registration/login.html
new file mode 100644
index 0000000..5ddd92f
--- /dev/null
+++ b/scheduleManagement/templates/registration/login.html
@@ -0,0 +1,15 @@
+{% extends 'home.html' %}
+
+{% block navbar %} {% endblock %}
+
+{% block title %} Login Page {% endblock %}
+
+{% block content %}
+ Login Page
+
+{% endblock %}
diff --git a/scheduleManagement/templates/registration/sign_up.html b/scheduleManagement/templates/registration/sign_up.html
new file mode 100644
index 0000000..1fb62d2
--- /dev/null
+++ b/scheduleManagement/templates/registration/sign_up.html
@@ -0,0 +1,15 @@
+{% extends 'home.html' %}
+
+{% block navbar %} {% endblock %}
+
+{% block title %} Sign Up Page {% endblock %}
+
+{% block content %}
+ Sign Up Page
+
+{% endblock %}
diff --git a/scheduleManagement/urls.py b/scheduleManagement/urls.py
index 8325779..7337b6a 100644
--- a/scheduleManagement/urls.py
+++ b/scheduleManagement/urls.py
@@ -1,9 +1,9 @@
from django.urls import path
from . import views
-from django.views.generic import TemplateView
urlpatterns = [
- path("", TemplateView.as_view(template_name="home.html"), name="home"),
+ path("", views.HomeRequestHandler.as_view(), name="home"),
+ path("sign-up/", views.UserCreateRequestHandler.as_view(), name="sign_up"),
path(
"list-courses/", views.CourseListRequestHandler.as_view(), name="list_courses"
),
diff --git a/scheduleManagement/views.py b/scheduleManagement/views.py
deleted file mode 100644
index 114e32e..0000000
--- a/scheduleManagement/views.py
+++ /dev/null
@@ -1,169 +0,0 @@
-from django.views.generic.edit import UpdateView, DeleteView, CreateView
-from django.views.generic import ListView, DetailView
-from django.urls import reverse_lazy
-from django.shortcuts import render
-
-from .models import Curso, Disciplina, Horario
-from .extras import get_field_values
-
-
-class CourseListRequestHandler(ListView):
- model = Curso
-
- def get(self, request):
- return render(
- request,
- "list-object.html",
- {"objects": Curso.objects.all(), "object_type": "Course"},
- )
-
-
-class CourseCreateRequestHandler(CreateView):
- model = Curso
- fields = ["nome", "codigo", "disciplinas", "horario"]
- template_name = "form.html"
- success_url = reverse_lazy("list_courses")
-
-
-class CourseDetailsRequestHandler(DetailView):
- model = Curso
- template_name = "object-details.html"
-
- def get_context_data(self, **kwargs):
- context = super().get_context_data(**kwargs)
- context["object"] = get_field_values(context["object"])
- context["object_type"] = "course"
- return context
-
-
-class CourseUpdateRequestHandler(UpdateView):
- model = Curso
- fields = ["nome", "codigo", "disciplinas", "horario"]
- template_name = "form.html"
-
- def get_success_url(self):
- return reverse_lazy("detail_course", kwargs={"pk": self.object.pk})
-
- def get_context_data(self, **kwargs):
- context = super().get_context_data(**kwargs)
- context["object_type"] = "course"
- return context
-
-
-class CourseDeleteRequestHandler(DeleteView):
- model = Curso
- template_name = "confirm-delete.html"
- success_url = reverse_lazy("list_courses")
-
- def get_context_data(self, **kwargs):
- context = super().get_context_data(**kwargs)
- context["object_type"] = "course"
- return context
-
-
-class DisciplineListRequestHandler(ListView):
- model = Curso
-
- def get(self, request):
- return render(
- request,
- "list-object.html",
- {"objects": Disciplina.objects.all(), "object_type": "Discipline"},
- )
-
-
-class DisciplineCreateRequestHandler(CreateView):
- model = Disciplina
- fields = ["nome", "codigo", "horario"]
- template_name = "form.html"
- success_url = reverse_lazy("list_disciplines")
-
-
-class DisciplineDetailsRequestHandler(DetailView):
- model = Disciplina
- template_name = "object-details.html"
-
- def get_context_data(self, **kwargs):
- context = super().get_context_data(**kwargs)
- context["object"] = get_field_values(context["object"])
- context["object_type"] = "discipline"
- return context
-
-
-class DisciplineUpdateRequestHandler(UpdateView):
- model = Disciplina
- fields = ["nome", "codigo"]
- template_name = "form.html"
-
- def get_success_url(self):
- return reverse_lazy("detail_discipline", kwargs={"pk": self.object.pk})
-
- def get_context_data(self, **kwargs):
- context = super().get_context_data(**kwargs)
- context["object_type"] = "discipline"
- return context
-
-
-class DisciplineDeleteRequestHandler(DeleteView):
- model = Disciplina
- template_name = "confirm-delete.html"
- success_url = reverse_lazy("list_disciplines")
-
- def get_context_data(self, **kwargs):
- context = super().get_context_data(**kwargs)
- context["object_type"] = "discipline"
- return context
-
-
-class ScheduleListRequestHandler(ListView):
- model = Horario
-
- def get(self, request):
- return render(
- request,
- "list-object.html",
- {"objects": Horario.objects.all(), "object_type": "Schedule"},
- )
-
-
-class ScheduleCreateRequestHandler(CreateView):
- model = Horario
- fields = ["dia", "hora_inicio", "hora_fim"]
- template_name = "form.html"
- success_url = reverse_lazy("list_schedules")
-
-
-class ScheduleDetailsRequestHandler(DetailView):
- model = Horario
- template_name = "object-details.html"
-
- def get_context_data(self, **kwargs):
- context = super().get_context_data(**kwargs)
- context["object"] = get_field_values(context["object"])
- context["object_type"] = "schedule"
- return context
-
-
-class ScheduleUpdateRequestHandler(UpdateView):
- model = Horario
- fields = ["dia", "hora_inicio", "hora_fim"]
- template_name = "form.html"
-
- def get_success_url(self):
- return reverse_lazy("detail_schedule", kwargs={"pk": self.object.pk})
-
- def get_context_data(self, **kwargs):
- context = super().get_context_data(**kwargs)
- context["object_type"] = "schedule"
- return context
-
-
-class ScheduleDeleteRequestHandler(DeleteView):
- model = Horario
- template_name = "confirm-delete.html"
- success_url = reverse_lazy("list_schedules")
-
- def get_context_data(self, **kwargs):
- context = super().get_context_data(**kwargs)
- context["object_type"] = "schedule"
- return context
diff --git a/scheduleManagement/views/__init__.py b/scheduleManagement/views/__init__.py
index fe12e91..99fe631 100644
--- a/scheduleManagement/views/__init__.py
+++ b/scheduleManagement/views/__init__.py
@@ -1,4 +1,7 @@
+from .home import HomeRequestHandler # noqa: F401
+
from .create import (
+ UserCreateRequestHandler, # noqa: F401
CourseCreateRequestHandler, # noqa: F401
DisciplineCreateRequestHandler, # noqa: F401
ScheduleCreateRequestHandler, # noqa: F401
diff --git a/scheduleManagement/views/create.py b/scheduleManagement/views/create.py
index 70d3b99..c79df1c 100644
--- a/scheduleManagement/views/create.py
+++ b/scheduleManagement/views/create.py
@@ -1,24 +1,39 @@
+from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic.edit import CreateView
+from django.contrib.auth import login
from django.urls import reverse_lazy
from ..models import Curso, Disciplina, Horario
+from ..forms import CustomUserCreationForm
-class CourseCreateRequestHandler(CreateView):
+class UserCreateRequestHandler(CreateView):
+ form_class = CustomUserCreationForm
+ template_name = "registration/sign_up.html"
+ success_url = reverse_lazy("login")
+
+ def form_valid(self, form):
+ user = form.save()
+ login(self.request, user)
+ return super().form_valid(form)
+
+
+class CourseCreateRequestHandler(LoginRequiredMixin, CreateView):
model = Curso
fields = ["nome", "codigo", "disciplinas", "horario"]
template_name = "form.html"
success_url = reverse_lazy("list_courses")
-class DisciplineCreateRequestHandler(CreateView):
+class DisciplineCreateRequestHandler(LoginRequiredMixin, CreateView):
model = Disciplina
fields = ["nome", "codigo", "horario"]
template_name = "form.html"
success_url = reverse_lazy("list_disciplines")
-class ScheduleCreateRequestHandler(CreateView):
+
+class ScheduleCreateRequestHandler(LoginRequiredMixin,CreateView):
model = Horario
fields = ["dia", "hora_inicio", "hora_fim"]
template_name = "form.html"
- success_url = reverse_lazy("list_schedules")
\ No newline at end of file
+ success_url = reverse_lazy("list_schedules")
diff --git a/scheduleManagement/views/details.py b/scheduleManagement/views/details.py
index bd9a164..932f6df 100644
--- a/scheduleManagement/views/details.py
+++ b/scheduleManagement/views/details.py
@@ -1,10 +1,11 @@
+from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic import DetailView
from ..models import Curso, Disciplina, Horario
from ..extras import get_field_values
-class CourseDetailsRequestHandler(DetailView):
+class CourseDetailsRequestHandler(LoginRequiredMixin, DetailView):
model = Curso
template_name = "object-details.html"
@@ -15,7 +16,7 @@ def get_context_data(self, **kwargs):
return context
-class DisciplineDetailsRequestHandler(DetailView):
+class DisciplineDetailsRequestHandler(LoginRequiredMixin, DetailView):
model = Disciplina
template_name = "object-details.html"
@@ -26,7 +27,7 @@ def get_context_data(self, **kwargs):
return context
-class ScheduleDetailsRequestHandler(DetailView):
+class ScheduleDetailsRequestHandler(LoginRequiredMixin, DetailView):
model = Horario
template_name = "object-details.html"
diff --git a/scheduleManagement/views/home.py b/scheduleManagement/views/home.py
new file mode 100644
index 0000000..83ce852
--- /dev/null
+++ b/scheduleManagement/views/home.py
@@ -0,0 +1,6 @@
+from django.contrib.auth.mixins import LoginRequiredMixin
+from django.views.generic import TemplateView
+
+
+class HomeRequestHandler(LoginRequiredMixin, TemplateView):
+ template_name = "home.html"
diff --git a/scheduleManagement/views/list.py b/scheduleManagement/views/list.py
index 6e6351f..5d23912 100644
--- a/scheduleManagement/views/list.py
+++ b/scheduleManagement/views/list.py
@@ -1,10 +1,11 @@
+from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic import ListView
from django.shortcuts import render
from ..models import Curso, Disciplina, Horario
-class CourseListRequestHandler(ListView):
+class CourseListRequestHandler(LoginRequiredMixin, ListView):
model = Curso
def get(self, request):
@@ -15,7 +16,7 @@ def get(self, request):
)
-class DisciplineListRequestHandler(ListView):
+class DisciplineListRequestHandler(LoginRequiredMixin, ListView):
model = Curso
def get(self, request):
@@ -26,7 +27,7 @@ def get(self, request):
)
-class ScheduleListRequestHandler(ListView):
+class ScheduleListRequestHandler(LoginRequiredMixin, ListView):
model = Horario
def get(self, request):
diff --git a/schoolschedules/urls.py b/schoolschedules/urls.py
index 601c81d..adafa1f 100644
--- a/schoolschedules/urls.py
+++ b/schoolschedules/urls.py
@@ -19,5 +19,6 @@
urlpatterns = [
path('', include('scheduleManagement.urls')),
+ path('', include('django.contrib.auth.urls')),
path('admin/', admin.site.urls),
]