Add export by period
This commit is contained in:
parent
66f941ed61
commit
93b84289fe
5 changed files with 62 additions and 5 deletions
|
|
@ -98,7 +98,7 @@
|
|||
"city": "La Sagne",
|
||||
"first_name": "Andr\u00e9",
|
||||
"last_name": "Allemand",
|
||||
"klass": 1,
|
||||
"klass": 2,
|
||||
"pcode": "2314",
|
||||
"birth_date": "1994-10-11",
|
||||
"archived": false
|
||||
|
|
@ -167,6 +167,17 @@
|
|||
"end_date": "2012-12-07"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 2,
|
||||
"model": "stages.period",
|
||||
"fields": {
|
||||
"title": "Stage final",
|
||||
"section": 1,
|
||||
"level": 2,
|
||||
"start_date": "2013-02-01",
|
||||
"end_date": "2013-03-15"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 1,
|
||||
"model": "stages.availability",
|
||||
|
|
@ -174,7 +185,7 @@
|
|||
"corporation": 1,
|
||||
"domain": 1,
|
||||
"period": 1,
|
||||
"comment": ""
|
||||
"comment": "Dispo pour pré-sensibilisation"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
@ -187,6 +198,16 @@
|
|||
"comment": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 3,
|
||||
"model": "stages.availability",
|
||||
"fields": {
|
||||
"corporation": 1,
|
||||
"domain": 2,
|
||||
"period": 2,
|
||||
"comment": "Dispo pour stage final"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 1,
|
||||
"model": "stages.training",
|
||||
|
|
@ -196,5 +217,15 @@
|
|||
"referent": 1,
|
||||
"comment": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 2,
|
||||
"model": "stages.training",
|
||||
"fields": {
|
||||
"availability": 3,
|
||||
"student": 4,
|
||||
"referent": 1,
|
||||
"comment": ""
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -74,6 +74,12 @@ function update_corporations(period_id) {
|
|||
}
|
||||
|
||||
function update_trainings(period_id) {
|
||||
function set_export_visibility() {
|
||||
if ($('ul#training_list').children().length > 0)
|
||||
$('input#export').show();
|
||||
else $('input#export').hide();
|
||||
}
|
||||
|
||||
if (period_id == '') $('ul#training_list').html('');
|
||||
else $('ul#training_list').load('/training/by_period/' + period_id + '/', function() {
|
||||
$('img.delete_training').click(function() {
|
||||
|
|
@ -86,8 +92,10 @@ function update_trainings(period_id) {
|
|||
// dispatch student and corp in their listings
|
||||
update_students($('#period_select').val());
|
||||
update_corporations($('#period_select').val());
|
||||
set_export_visibility();
|
||||
});
|
||||
});
|
||||
set_export_visibility();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -172,6 +180,10 @@ $(document).ready(function() {
|
|||
);
|
||||
});
|
||||
|
||||
$('input#export').click(function() {
|
||||
$('form#list_export').attr('action', '/stages/export/?filter=' + $('#period_select').val()).submit();
|
||||
});
|
||||
|
||||
update_periods($('#section_select').val());
|
||||
update_class_filter($('#section_select').val());
|
||||
});
|
||||
|
|
|
|||
|
|
@ -12,8 +12,12 @@ class StagesTest(TestCase):
|
|||
self.client.login(username='me', password='mepassword')
|
||||
|
||||
def test_export(self):
|
||||
response = self.client.get(reverse('stages_export'))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
response1 = self.client.get(reverse('stages_export'))
|
||||
self.assertEqual(response1.status_code, 200)
|
||||
|
||||
response2 = self.client.get(reverse('stages_export'), {'filter': '2'})
|
||||
self.assertEqual(response2.status_code, 200)
|
||||
self.assertGreater(len(response1.content), len(response2.content))
|
||||
|
||||
def test_new_training(self):
|
||||
student = Student.objects.get(last_name='Varrin')
|
||||
|
|
|
|||
|
|
@ -115,6 +115,12 @@ def stages_export(request):
|
|||
('Prénom référent', 'referent__first_name'), ('Nom référent', 'referent__last_name')
|
||||
]
|
||||
|
||||
period_filter = request.GET.get('filter')
|
||||
if period_filter:
|
||||
query = Training.objects.filter(availability__period_id=period_filter)
|
||||
else:
|
||||
query = Training.objects.all()
|
||||
|
||||
wb = Workbook()
|
||||
ws = wb.get_active_sheet()
|
||||
ws.title = 'Stages'
|
||||
|
|
@ -123,7 +129,7 @@ def stages_export(request):
|
|||
ws.cell(row=0, column=col_idx).value = header
|
||||
ws.cell(row=0, column=col_idx).style.font.bold = True
|
||||
# Data
|
||||
for row_idx, tr in enumerate(Training.objects.all().values_list(*[f[1] for f in export_fields]), start=1):
|
||||
for row_idx, tr in enumerate(query.values_list(*[f[1] for f in export_fields]), start=1):
|
||||
for col_idx, field in enumerate(tr):
|
||||
ws.cell(row=row_idx, column=col_idx).value = field
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
input#valid_training { display: none; }
|
||||
|
||||
div#trainings { clear: both; padding-top: 1em; }
|
||||
input#export { display: none; margin-left: 2em; }
|
||||
|
||||
.missing { font-style: italic; color: red; }
|
||||
</style>
|
||||
|
|
@ -88,5 +89,8 @@
|
|||
<h3>Stages planifiés pour la période choisie</h3>
|
||||
<ul id="training_list">-
|
||||
</ul>
|
||||
<form id="list_export" method="get" action=".">{% csrf_token %}
|
||||
<input id="export" type="button" value="Exporter la liste">
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue