Skip to content
Snippets Groups Projects
Commit 77f32350 authored by florimondmanca's avatar florimondmanca
Browse files

refactoring: add persons and tutoring apps

parent 0d49b3b4
No related branches found
No related tags found
No related merge requests found
Showing
with 164 additions and 109 deletions
......@@ -32,12 +32,15 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'users.apps.UsersConfig',
'api.apps.ApiConfig',
# Django REST Framework (DRF)
'rest_framework',
# DRF Swagger (API documentation generator)
'rest_framework_swagger',
# Site apps
'users.apps.UsersConfig',
'persons.apps.PersonsConfig',
'tutoring.apps.TutoringConfig',
'api.apps.ApiConfig',
]
MIDDLEWARE = [
......
"""Persons admin panel configuration."""
from django.contrib import admin
from persons.models import Tutor
from tutoring.admin import TutoringGroupMembershipInline
# Register your models here.
@admin.register(Tutor)
class TutorAdmin(admin.ModelAdmin):
"""Tutor admin panel."""
inlines = [
TutoringGroupMembershipInline
]
class Meta: # noqa
model = Tutor
from django.apps import AppConfig
class PersonsConfig(AppConfig):
name = 'persons'
verbose_name = 'Personnes'
"""Persons models."""
from django.db import models
from django.contrib.auth import get_user_model
from persons.utils import get_promotion_range
# Create your models here.
# TODO define the abstract Person model
class Person:
"""Represents a person who can use the website."""
class Tutor(models.Model):
"""Represents a tutor.
Fields
------
user : 1-1 with User
Deleting the user will delete the tutor too (delete cascade).
promotion : int
tutoring_groups : 1-n with TutoringGroup
"""
user = models.OneToOneField(get_user_model(), on_delete=models.CASCADE)
PROMOTION_CHOICES = tuple(
(year, str(year)) for year in get_promotion_range()
)
promotion = models.IntegerField(choices=PROMOTION_CHOICES,
default=PROMOTION_CHOICES[0][0])
class Meta: # noqa
verbose_name = 'tuteur'
def __str__(self):
return str(self.user)
"""Users utilities tests."""
"""Persons utilities tests."""
import datetime
from django.test import TestCase
from django.conf import settings
from users.utils import get_promotion_range
from .utils import get_promotion_range
class TestUtils(TestCase):
"""Test the users utilities."""
"""Test the persons utilities."""
def make_date(self, year, months_after_arrival, days_after_arrival):
return datetime.date(
......
File moved
from django.shortcuts import render
# Create your views here.
"""Tutoring admin panel configuration."""
from django.contrib import admin
from .models import TutoringGroup
# Register your models here.
class TutoringGroupMembershipInline(admin.TabularInline):
"""Inline for tutoring group membership."""
model = TutoringGroup.tutors.through
extra = 0
@admin.register(TutoringGroup)
class TutoringGroupAdmin(admin.ModelAdmin):
"""Tutoring group admin panel."""
inlines = [
TutoringGroupMembershipInline
]
class Meta: # noqa
model = TutoringGroup
from django.apps import AppConfig
class TutoringConfig(AppConfig):
name = 'tutoring'
verbose_name = 'Tutorat'
"""Tutoring models."""
from django.db import models
# Create your models here.
class SchoolYear(models.Model):
"""Represents a school year.
If year is 2017, the school_year object represents the '2017-2018'
school year.
Fields
------
year : int field
"""
year = models.IntegerField('année', help_text=(
"Année calendaire du début de l'année scolaire. "
"Exemple : pour l'année scolaire 2017-2018, entrez 2017."
))
class Meta: # noqa
verbose_name = 'année scolaire'
verbose_name_plural = 'années scolaires'
def __str__(self):
return f'{self.year}-{self.year + 1}'
class TutoringGroup(models.Model):
"""Represents a tutoring group to which tutors and students participate.
Fields
------
name : char
tutors : 1-n with Tutor
"""
name = models.CharField('nom', max_length=200)
tutors = models.ManyToManyField('persons.Tutor',
verbose_name='tuteurs', blank=True)
class Meta: # noqa
ordering = ('name',)
verbose_name = 'groupe de tutorat'
verbose_name_plural = 'groupes de tutorat'
def __str__(self):
return str(self.name)
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render
# Create your views here.
......@@ -4,9 +4,7 @@ from django.contrib import admin
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.admin import UserAdmin
from .models import (
User, Tutor, TutoringGroup,
)
from .models import User
# Register your models here.
......@@ -44,32 +42,3 @@ class CustomUserAdmin(UserAdmin):
'fields': ('email', 'password1', 'password2')}
),
)
class TutoringGroupMembershipInline(admin.TabularInline):
model = TutoringGroup.tutors.through
extra = 0
@admin.register(Tutor)
class TutorAdmin(admin.ModelAdmin):
"""Tutor admin panel."""
inlines = [
TutoringGroupMembershipInline
]
class Meta: # noqa
model = Tutor
@admin.register(TutoringGroup)
class TutoringGroupAdmin(admin.ModelAdmin):
"""Tutoring group admin panel."""
inlines = [
TutoringGroupMembershipInline
]
class Meta: # noqa
model = TutoringGroup
......@@ -3,3 +3,4 @@ from django.apps import AppConfig
class UsersConfig(AppConfig):
name = 'users'
verbose_name = 'Utilisateurs'
......@@ -6,7 +6,6 @@ from django.shortcuts import reverse
from django.contrib.auth.models import AbstractUser
from django.contrib.auth.models import UserManager as _UserManager
from users.utils import get_promotion_range
from utils import modify_fields
# Create your models here.
......@@ -88,74 +87,3 @@ class User(AbstractUser):
def get_absolute_url(self):
return reverse('api:user-detail', args=[str(self.id)])
class Tutor(models.Model):
"""Represents a tutor.
Fields
------
user : 1-1 with User
Deleting the user will delete the tutor too (delete cascade).
promotion : int
tutoring_groups : 1-n with TutoringGroup
"""
user = models.OneToOneField('User', on_delete=models.CASCADE)
PROMOTION_CHOICES = tuple(
(year, str(year)) for year in get_promotion_range()
)
promotion = models.IntegerField(choices=PROMOTION_CHOICES,
default=PROMOTION_CHOICES[0][0])
class Meta: # noqa
verbose_name = 'tuteur'
def __str__(self):
return str(self.user)
class SchoolYear(models.Model):
"""Represents a school year.
If year is 2017, the school_year object represents the '2017-2018'
school year.
Fields
------
year : int field
"""
year = models.IntegerField('année', help_text=(
"Année calendaire du début de l'année scolaire. "
"Exemple : pour l'année scolaire 2017-2018, entrez 2017."
))
class Meta: # noqa
verbose_name = 'année scolaire'
verbose_name_plural = 'années scolaires'
def __str__(self):
return f'{self.year}-{self.year + 1}'
class TutoringGroup(models.Model):
"""Represents a tutoring group to which tutors and students participate.
Fields
------
name : char
tutors : 1-n with Tutor
"""
name = models.CharField('nom', max_length=200)
tutors = models.ManyToManyField('Tutor',
verbose_name='tuteurs')
class Meta: # noqa
ordering = ('name',)
verbose_name = 'groupe de tutorat'
verbose_name_plural = 'groupes de tutorat'
def __str__(self):
return str(self.name)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment