Add possibility to export non-attributed availabilities
This commit is contained in:
parent
1e6f91f59a
commit
8931842ccb
4 changed files with 72 additions and 25 deletions
|
|
@ -78,6 +78,9 @@ function update_trainings(period_id) {
|
|||
if ($('ul#training_list').children().length > 0)
|
||||
$('input#export').show();
|
||||
else $('input#export').hide();
|
||||
if ($('#corp_select').attr('options').length > 0)
|
||||
$('input#export_non_attr').show();
|
||||
else $('input#export_non_attr').hide();
|
||||
}
|
||||
|
||||
if (period_id == '') $('ul#training_list').html('');
|
||||
|
|
@ -221,7 +224,14 @@ $(document).ready(function() {
|
|||
|
||||
$('input#export').click(function(ev) {
|
||||
ev.preventDefault();
|
||||
$('form#list_export').find('input#filter').val($('#period_select').val());
|
||||
$('form#list_export').find('input#period').val($('#period_select').val());
|
||||
$('form#list_export').find('input#non_attr').val('0');
|
||||
$('form#list_export').submit();
|
||||
});
|
||||
$('input#export_non_attr').click(function(ev) {
|
||||
ev.preventDefault();
|
||||
$('form#list_export').find('input#period').val($('#period_select').val());
|
||||
$('form#list_export').find('input#non_attr').val('1');
|
||||
$('form#list_export').submit();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -20,10 +20,13 @@ class StagesTest(TestCase):
|
|||
response1 = self.client.get(reverse('stages_export'))
|
||||
self.assertEqual(response1.status_code, 200)
|
||||
|
||||
response2 = self.client.get(reverse('stages_export'), {'filter': '2'})
|
||||
response2 = self.client.get(reverse('stages_export'), {'period': '2', 'non_attr': '0'})
|
||||
self.assertEqual(response2.status_code, 200)
|
||||
self.assertGreater(len(response1.content), len(response2.content))
|
||||
|
||||
response3 = self.client.get(reverse('stages_export'), {'period': '1', 'non_attr': '1'})
|
||||
self.assertEqual(response2.status_code, 200)
|
||||
|
||||
def test_new_training(self):
|
||||
student = Student.objects.get(last_name='Varrin')
|
||||
avail = Availability.objects.get(pk=2)
|
||||
|
|
|
|||
|
|
@ -202,34 +202,66 @@ def del_training(request):
|
|||
return HttpResponse(json.dumps({'ref_id': ref_id}), content_type="application/json")
|
||||
|
||||
|
||||
EXPORT_FIELDS = [
|
||||
('Prénom', 'student__first_name'), ('Nom', 'student__last_name'),
|
||||
('Classe', 'student__klass__name'), ('Filière', 'student__klass__section__name'),
|
||||
('Nom du stage', 'availability__period__title'),
|
||||
('Début', 'availability__period__start_date'), ('Fin', 'availability__period__end_date'),
|
||||
('Remarques stage', 'comment'),
|
||||
('Prénom référent', 'referent__first_name'), ('Nom référent', 'referent__last_name'),
|
||||
('Courriel référent', 'referent__email'),
|
||||
('Institution', 'availability__corporation__name'),
|
||||
('Rue Inst.', 'availability__corporation__street'),
|
||||
('NPA Inst.', 'availability__corporation__pcode'),
|
||||
('Ville Inst.', 'availability__corporation__city'),
|
||||
('Domaine', 'availability__domain__name'),
|
||||
('Remarques Inst.', 'availability__comment'),
|
||||
('Civilité contact', 'availability__contact__title'),
|
||||
('Prénom contact', 'availability__contact__first_name'),
|
||||
('Nom contact', 'availability__contact__last_name'),
|
||||
('Courriel contact', 'availability__contact__email'),
|
||||
]
|
||||
|
||||
NON_ATTR_EXPORT_FIELDS = [
|
||||
('Filière', 'period__section__name'),
|
||||
('Nom du stage', 'period__title'),
|
||||
('Début', 'period__start_date'), ('Fin', 'period__end_date'),
|
||||
('Institution', 'corporation__name'),
|
||||
('Rue Inst.', 'corporation__street'),
|
||||
('NPA Inst.', 'corporation__pcode'),
|
||||
('Ville Inst.', 'corporation__city'),
|
||||
('Domaine', 'domain__name'),
|
||||
('Remarques Inst.', 'comment'),
|
||||
('Civilité contact', 'contact__title'),
|
||||
('Prénom contact', 'contact__first_name'),
|
||||
('Nom contact', 'contact__last_name'),
|
||||
('Courriel contact', 'contact__email'),
|
||||
]
|
||||
|
||||
def stages_export(request):
|
||||
from datetime import date
|
||||
from openpyxl import Workbook
|
||||
from openpyxl.writer.excel import save_virtual_workbook
|
||||
|
||||
export_fields = [
|
||||
('Prénom', 'student__first_name'), ('Nom', 'student__last_name'),
|
||||
('Classe', 'student__klass__name'), ('Filière', 'student__klass__section__name'),
|
||||
('Début', 'availability__period__start_date'), ('Fin', 'availability__period__end_date'),
|
||||
('Remarques stage', 'comment'),
|
||||
('Prénom référent', 'referent__first_name'), ('Nom référent', 'referent__last_name'),
|
||||
('Courriel référent', 'referent__email'),
|
||||
('Institution', 'availability__corporation__name'),
|
||||
('Rue Inst.', 'availability__corporation__street'),
|
||||
('NPA Inst.', 'availability__corporation__pcode'),
|
||||
('Ville Inst.', 'availability__corporation__city'),
|
||||
('Domaine', 'availability__domain__name'),
|
||||
('Remarques Inst.', 'availability__comment'),
|
||||
('Civilité contact', 'availability__contact__title'),
|
||||
('Prénom contact', 'availability__contact__first_name'),
|
||||
('Nom contact', 'availability__contact__last_name'),
|
||||
('Courriel contact', 'availability__contact__email'),
|
||||
]
|
||||
period_filter = request.GET.get('period')
|
||||
non_attributed = bool(int(request.GET.get('non_attr', 0)))
|
||||
|
||||
export_fields = EXPORT_FIELDS
|
||||
contact_test_field = 'availability__contact__last_name'
|
||||
corp_name_field = 'availability__corporation__name'
|
||||
|
||||
period_filter = request.GET.get('filter')
|
||||
if period_filter:
|
||||
query = Training.objects.filter(availability__period_id=period_filter)
|
||||
if non_attributed:
|
||||
# Export non attributed availabilities for a specific period
|
||||
query = Availability.objects.filter(period_id=period_filter, training__isnull=True)
|
||||
export_fields = NON_ATTR_EXPORT_FIELDS
|
||||
contact_test_field = 'contact__last_name'
|
||||
corp_name_field = 'corporation__name'
|
||||
else:
|
||||
# Export trainings for a specific period
|
||||
query = Training.objects.filter(availability__period_id=period_filter)
|
||||
else:
|
||||
# Export all trainings in the database
|
||||
query = Training.objects.all()
|
||||
|
||||
# Prepare "default" contacts (when not defined on training)
|
||||
|
|
@ -250,9 +282,9 @@ def stages_export(request):
|
|||
for row_idx, tr in enumerate(query.values(*query_keys), start=1):
|
||||
for col_idx, field in enumerate(query_keys):
|
||||
ws.cell(row=row_idx, column=col_idx).value = tr[field]
|
||||
if tr['availability__contact__last_name'] is None:
|
||||
if tr[contact_test_field] is None:
|
||||
# Use default contact
|
||||
contact = contacts.get(tr['availability__corporation__name'])
|
||||
contact = contacts.get(tr[corp_name_field])
|
||||
if contact:
|
||||
ws.cell(row=row_idx, column=col_idx-3).value = contact.title
|
||||
ws.cell(row=row_idx, column=col_idx-2).value = contact.first_name
|
||||
|
|
|
|||
|
|
@ -99,8 +99,10 @@
|
|||
<ul id="training_list">-
|
||||
</ul>
|
||||
<form id="list_export" method="get" action="{% url 'stages_export' %}">{% csrf_token %}
|
||||
<input id="filter" name="filter" type="hidden" value="">
|
||||
<input id="period" name="period" type="hidden" value="">
|
||||
<input id="non_attr" name="non_attr" type="hidden" value="0">
|
||||
<input id="export" type="button" value="Exporter la liste">
|
||||
<input id="export_non_attr" type="button" value="Exporter la liste des stages non attribués">
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue