Display student age at period start on attributions view
This commit is contained in:
parent
473493542c
commit
894cc172a8
4 changed files with 27 additions and 10 deletions
|
|
@ -1,4 +1,4 @@
|
|||
from datetime import date
|
||||
from datetime import date, timedelta
|
||||
|
||||
from django.db import models
|
||||
|
||||
|
|
@ -77,6 +77,13 @@ class Student(models.Model):
|
|||
def __str__(self):
|
||||
return '%s %s' % (self.last_name, self.first_name)
|
||||
|
||||
def age_at(self, date_):
|
||||
"""Return age of student at `date_` time, as a string."""
|
||||
age = (date.today() - self.birth_date) / timedelta(days=365.2425)
|
||||
age_y = int(age)
|
||||
age_m = int((age - age_y) * 12)
|
||||
return '%d ans%s' % (age_y, ' %d m.' % age_m if age_m > 0 else '')
|
||||
|
||||
@classmethod
|
||||
def prepare_import(cls, values):
|
||||
''' Hook for tabimport, before new object get created '''
|
||||
|
|
|
|||
|
|
@ -144,14 +144,16 @@ $(document).ready(function() {
|
|||
});
|
||||
|
||||
$('#student_select').change(function(ev) {
|
||||
$('#student_detail').load('/student/' + $(this).val() + '/summary/', function() {
|
||||
$('div#previous_stages_head').toggle(function() {
|
||||
$('ul#previous_stages_list').toggle();
|
||||
$(this).find('img').attr('src', static_url + 'img/open.png');
|
||||
}, function() {
|
||||
$('ul#previous_stages_list').toggle();
|
||||
$(this).find('img').attr('src', static_url + 'img/closed.png');
|
||||
});
|
||||
$('#student_detail').load(
|
||||
'/student/' + $(this).val() + '/summary/?period=' + $.cookie('periode'),
|
||||
function() {
|
||||
$('div#previous_stages_head').toggle(function() {
|
||||
$('ul#previous_stages_list').toggle();
|
||||
$(this).find('img').attr('src', static_url + 'img/open.png');
|
||||
}, function() {
|
||||
$('ul#previous_stages_list').toggle();
|
||||
$(this).find('img').attr('src', static_url + 'img/closed.png');
|
||||
});
|
||||
}).addClass("filled");
|
||||
current_student = $(this).val();
|
||||
if (current_avail !== null) $('input#valid_training').show();
|
||||
|
|
|
|||
|
|
@ -102,6 +102,14 @@ class StudentSummaryView(DetailView):
|
|||
context = super(StudentSummaryView, self).get_context_data(**kwargs)
|
||||
context['previous_stages'] = self.object.training_set.all(
|
||||
).select_related('availability__corporation').order_by('availability__period__end_date')
|
||||
period_id = self.request.GET.get('period')
|
||||
if period_id:
|
||||
try:
|
||||
period = Period.objects.get(pk=int(period_id))
|
||||
except Period.DoesNotExist:
|
||||
pass
|
||||
else:
|
||||
context['age_for_stage'] = self.object.age_at(period.start_date)
|
||||
return context
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -12,5 +12,5 @@
|
|||
<div id="summary">
|
||||
{{ object.first_name }} {{ object.last_name }}<br>
|
||||
{{ object.pcode }} {{ object.city }}<br>
|
||||
Date de naissance: {{ object.birth_date }}
|
||||
Date de naissance: {{ object.birth_date }} {% if age_for_stage %}(<span title="Âge au début du stage">{{ age_for_stage }}){% endif %}</span>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue