Skip to content

Commit

Permalink
Merge pull request #5 from Django-Projects-Ls/main
Browse files Browse the repository at this point in the history
Main
  • Loading branch information
LopesLs authored Dec 26, 2023
2 parents 06f65f2 + a7c0cb1 commit 86af356
Show file tree
Hide file tree
Showing 14 changed files with 373 additions and 269 deletions.
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
# SchoolSchedules
# SchoolSchedules

## Setup Virtual Environment (venv)

### Linux

These commands bellow are creating a folder .venv and activate the environment in the terminal.

```bash
python3 manage.py venv .venv
source .venv/bin/activate
```

### Windows

```bash
py manage.py venv .venv
.venv/Scripts/activate
```

## Installing Dependencies (requirements.txt)

```bash
pip install -r requirements.txt
```

## Running server

```bash
python3 manage.py runserver
```
5 changes: 2 additions & 3 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'schoolschedules.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "schoolschedules.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand All @@ -19,6 +19,5 @@ def main():
) from exc
execute_from_command_line(sys.argv)


if __name__ == '__main__':
if __name__ == "__main__":
main()
9 changes: 6 additions & 3 deletions scheduleManagement/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from django.contrib import admin
from .models import Disciplina, Curso, Horario

# Register your models here.
for model in [Disciplina, Curso, Horario]:
admin.site.register(model)
for model in [
Disciplina,
Curso,
Horario,
]:
admin.site.register(model)
30 changes: 15 additions & 15 deletions scheduleManagement/extras.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
from django.db.models import ManyToManyField

def get_field_values(instance):
field_values = {}
fields = instance._meta.get_fields(include_hidden=True)
field_values = {}
fields = instance._meta.get_fields(include_hidden=True)

for field in fields:
try:
if isinstance(field, ManyToManyField):
# If the field is a many-to-many field, get all related objects
related_objects = getattr(instance, field.name).all()
field_values[field.name] = ", ".join(
str(obj) for obj in related_objects
)
continue
for field in fields:
try:
if isinstance(field, ManyToManyField):
# If the field is a many-to-many field, get all related objects
related_objects = getattr(instance, field.name).all()
field_values[field.name] = ", ".join(
str(obj) for obj in related_objects
)
continue

field_values[field.name] = getattr(instance, field.name)
field_values[field.name] = getattr(instance, field.name)

except Exception:
pass
except Exception:
pass

return field_values
return field_values
110 changes: 56 additions & 54 deletions scheduleManagement/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,62 @@
from django.template.defaultfilters import slugify

class Horario(models.Model):
dia = models.DateField()
hora_inicio = models.TimeField()
hora_fim = models.TimeField()
slug = models.SlugField(unique=True, null=True)

def get_absolute_url(self):
"""Returns the URL to access a particular instance of the model."""
return reverse_lazy('detail_schedule', kwargs={'slug': self.slug})

def save(self, *args, **kwargs):
"""Create an automatic slug for the schedule."""

self.slug = slugify(self.dia)
super().save(*args, **kwargs)

def __str__(self):
return f'{self.dia} | {self.hora_inicio} - {self.hora_fim}'
dia = models.DateField()
hora_inicio = models.TimeField()
hora_fim = models.TimeField()
slug = models.SlugField(unique=True, null=True)

def get_absolute_url(self):
"""Returns the URL to access a particular instance of the model."""
return reverse_lazy("detail_schedule", kwargs={"slug": self.slug})

def save(self, *args, **kwargs):
"""Create an automatic slug for the schedule."""

self.slug = slugify(self.dia)
super().save(*args, **kwargs)

def __str__(self):
return f"{self.dia} | {self.hora_inicio} - {self.hora_fim}"


class Disciplina(models.Model):
nome = models.CharField(max_length=255)
codigo = models.CharField(max_length=255)
horario = models.OneToOneField(Horario, on_delete=models.CASCADE)
slug = models.SlugField(unique=True, null=True)

def get_absolute_url(self):
"""Returns the URL to access a particular instance of the model."""
return reverse_lazy('detail_discipline', kwargs={'slug': self.slug})

def save(self, *args, **kwargs):
"""Create an automatic slug for the discipline."""

self.slug = slugify(self.nome)
super().save(*args, **kwargs)

def __str__(self):
return self.nome

nome = models.CharField(max_length=255)
codigo = models.CharField(max_length=255)
horario = models.OneToOneField(Horario, on_delete=models.CASCADE)
slug = models.SlugField(unique=True, null=True)

def get_absolute_url(self):
"""Returns the URL to access a particular instance of the model."""
return reverse_lazy("detail_discipline", kwargs={"slug": self.slug})

def save(self, *args, **kwargs):
"""Create an automatic slug for the discipline."""

self.slug = slugify(self.nome)
super().save(*args, **kwargs)

def __str__(self):
return self.nome


class Curso(models.Model):
nome = models.CharField(max_length=255)
codigo = models.CharField(max_length=255)
disciplinas = models.ManyToManyField(Disciplina)
horario = models.OneToOneField(Horario, on_delete=models.CASCADE)
slug = models.SlugField(unique=True, null=True)
def get_absolute_url(self):
"""Returns the URL to access a particular instance of the model."""
return reverse_lazy('detail_course', kwargs={'slug': self.slug})
def save(self, *args, **kwargs):
"""Create an automatic slug for the course."""
self.slug = slugify(self.nome)
super().save(*args, **kwargs)

def __str__(self):
"""Returns the name of the course."""
return self.nome
nome = models.CharField(max_length=255)
codigo = models.CharField(max_length=255)
disciplinas = models.ManyToManyField(Disciplina)
horario = models.OneToOneField(Horario, on_delete=models.CASCADE)
slug = models.SlugField(unique=True, null=True)

def get_absolute_url(self):
"""Returns the URL to access a particular instance of the model."""
return reverse_lazy("detail_course", kwargs={"slug": self.slug})

def save(self, *args, **kwargs):
"""Create an automatic slug for the course."""

self.slug = slugify(self.nome)
super().save(*args, **kwargs)

def __str__(self):
"""Returns the name of the course."""
return self.nome
20 changes: 7 additions & 13 deletions scheduleManagement/templates/confirm-delete.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ object_type | capfirst }} | Delete</title>
</head>
<body>
{% extends "home.html" %}

{% block title %} <title>{{ object_type | capfirst }} | Delete</title> {% endblock %}

{% block content %}
<h1>{{ object_type | capfirst }} | Delete</h1>

<p>Are you sure you want to delete <strong>{{ object }}?</strong></p>

<form method="post">
{% csrf_token %}
<input type="submit" value="Yes, I'm sure">
</body>
</html>
{% include 'partials/form_component.html' with value="Yes, i'm sure" delete=true %}
{% endblock %}
12 changes: 0 additions & 12 deletions scheduleManagement/templates/disciplina.html

This file was deleted.

31 changes: 16 additions & 15 deletions scheduleManagement/templates/form.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% if object_type %} {{ object_type | capfirst }} | Update {% else %} Create {% endif %}</title>
</head>
<body>
{% extends 'home.html' %}

{% block title %}
<title>
{% if object_type %}
{{ object_type | capfirst }} | Update
{% else %}
Create
{% endif %}
</title>
{% endblock %}

{% block content %}
{% if object_type %}
<h1>{{ object_type | capfirst }} | Update</h1>
{% else %}
<h1>Create</h1>
{% endif %}

<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save">
</form>
{% include 'partials/form_component.html' with value="Save" %}

<a href="{{request.META.HTTP_REFERER}}">Back</a>
</body>
</html>
{% endblock %}
14 changes: 8 additions & 6 deletions scheduleManagement/templates/home.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<!DOCTYPE html>
<html lang="pt-br">
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home page</title>
{% block title %} <title>Home page</title> {% endblock %}
</head>
<body>
<a href="list-courses"><p>Courses</p></a>
<a href="list-disciplines"><p>Disciplines</p></a>
<a href="list-schedules"><p>Schedules</p></a>
{% block content%}
<a href="list-courses"><p>Courses</p></a>
<a href="list-disciplines"><p>Disciplines</p></a>
<a href="list-schedules"><p>Schedules</p></a>
{% endblock %}
</body>
</html>
</html>
20 changes: 9 additions & 11 deletions scheduleManagement/templates/list-object.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ object_type | capfirst }} | List</title>
</head>
<body>
<h1>{{ object_type | capfirst }} | List</h1>
{% extends 'home.html' %}

{% block title %} <title>{{ object_type | title }} | List</title> {% endblock %}

{% block content %}
<h1>{{ object_type | title }} | List</h1>

{% for object in objects %}
<a href="{{ object.get_absolute_url }}"><p>{{ object }}</p></a>
{% endfor %}

<button onclick="location.href = 'create'">Adicionar {{ object_type }}</button>
<a href="/">Back</a>
</body>
</html>
{% endblock %}
18 changes: 7 additions & 11 deletions scheduleManagement/templates/object-details.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ object_type | capfirst }} | Details</title>
</head>
<body>
<h1> {{ object_type | capfirst }} | Details</h1>
{% extends 'home.html' %}

{% block title %} <title>{{ object_type | title }} | Details</title> {% endblock %}

{% block content %}
<h1> {{ object_type | title }} | Details</h1>

{% for field, value in object.items %}
<ul>
Expand All @@ -19,5 +16,4 @@ <h1> {{ object_type | capfirst }} | Details</h1>
<button onclick="location.href = 'edit/{{ object.slug }}'" >Update</button>
<button onclick="location.href = 'delete/{{ object.slug }}'" >Delete</button>
<a href="/list-{{ object_type }}s">Back</a>
</body>
</html>
{% endblock %}
9 changes: 9 additions & 0 deletions scheduleManagement/templates/partials/form_component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<form method="post">
{% csrf_token %}

{% if not delete %}
{{ form.as_p }}
{% endif %}

<input type="submit" value="{{ value }}">
</form>
Loading

0 comments on commit 86af356

Please sign in to comment.