Retrieve student list depending on current time and period time
If I plan a period for next year, I should obtain the students for the period level minus one.
This commit is contained in:
parent
dc3033ae3c
commit
a139570222
3 changed files with 83 additions and 34 deletions
|
|
@ -1,8 +1,11 @@
|
|||
# -*- encoding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from datetime import date
|
||||
|
||||
from django.db import models
|
||||
|
||||
from . import utils
|
||||
|
||||
|
||||
def is_int(s):
|
||||
try:
|
||||
|
|
@ -33,6 +36,14 @@ class Level(models.Model):
|
|||
def __unicode__(self):
|
||||
return self.name
|
||||
|
||||
def delta(self, diff):
|
||||
if diff == 0:
|
||||
return self
|
||||
try:
|
||||
return Level.objects.get(name=str(int(self.name)+diff))
|
||||
except Level.DoesNotExist:
|
||||
return None
|
||||
|
||||
|
||||
class Klass(models.Model):
|
||||
name = models.CharField(max_length=10, verbose_name='Nom')
|
||||
|
|
@ -166,11 +177,17 @@ class Period(models.Model):
|
|||
|
||||
@property
|
||||
def school_year(self):
|
||||
if self.start_date.month < 8:
|
||||
start_year = self.start_date.year - 1
|
||||
else:
|
||||
start_year = self.start_date.year
|
||||
return "%d — %d" % (start_year, start_year + 1)
|
||||
return utils.school_year(self.start_date)
|
||||
|
||||
@property
|
||||
def relative_level(self):
|
||||
"""
|
||||
Return the level depending on current school year. For example, if the
|
||||
period is planned for next school year, level will be level - 1.
|
||||
"""
|
||||
diff = (utils.school_year(self.start_date, as_tuple=True)[0] -
|
||||
utils.school_year(date.today(), as_tuple=True)[0])
|
||||
return self.level.delta(-diff)
|
||||
|
||||
@property
|
||||
def weeks(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue