2017-10-19 09:29:08 +02:00
|
|
|
|
from collections import OrderedDict
|
|
|
|
|
|
|
2017-10-18 18:52:59 +02:00
|
|
|
|
from django.contrib import admin
|
2017-10-19 09:29:08 +02:00
|
|
|
|
from django.db.models import BooleanField
|
2018-01-26 18:19:16 +01:00
|
|
|
|
from django.urls import reverse
|
2018-02-02 09:55:09 +01:00
|
|
|
|
from django.utils.html import format_html
|
2017-10-19 09:29:08 +02:00
|
|
|
|
|
2018-06-16 18:40:34 +02:00
|
|
|
|
from stages.views.export import OpenXMLExport
|
2018-02-01 14:55:03 +01:00
|
|
|
|
from .forms import CandidateForm
|
2018-02-14 19:08:03 +01:00
|
|
|
|
from .models import (
|
|
|
|
|
|
Candidate, Interview, GENDER_CHOICES, DIPLOMA_CHOICES, DIPLOMA_STATUS_CHOICES,
|
|
|
|
|
|
SECTION_CHOICES, OPTION_CHOICES, AES_ACCORDS_CHOICES, RESIDENCE_PERMITS_CHOICES,
|
|
|
|
|
|
)
|
2017-10-19 09:29:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def export_candidates(modeladmin, request, queryset):
|
|
|
|
|
|
"""
|
|
|
|
|
|
Export all candidates fields.
|
|
|
|
|
|
"""
|
2018-02-02 10:07:24 +01:00
|
|
|
|
export_fields = OrderedDict([
|
|
|
|
|
|
(getattr(f, 'verbose_name', f.name), f.name)
|
2018-02-14 19:08:03 +01:00
|
|
|
|
for f in Candidate._meta.get_fields() if f.name not in ('ID', 'interview')
|
2018-02-02 10:07:24 +01:00
|
|
|
|
])
|
2017-10-19 09:29:08 +02:00
|
|
|
|
export_fields['Employeur'] = 'corporation__name'
|
2018-06-11 17:27:25 +02:00
|
|
|
|
export_fields['Employeur_canton'] = 'corporation__district'
|
2018-05-02 09:34:40 +02:00
|
|
|
|
export_fields['FEE/FPP_civilité'] = 'instructor__civility'
|
2018-04-17 09:50:54 +02:00
|
|
|
|
export_fields['FEE/FPP_Nom'] = 'instructor__last_name'
|
|
|
|
|
|
export_fields['FEE/FPP_Prénom'] = 'instructor__first_name'
|
|
|
|
|
|
export_fields['FEE/FPP_email'] = 'instructor__email'
|
2018-02-14 19:08:03 +01:00
|
|
|
|
export_fields['Prof. entretien'] = 'interview__teacher_int__abrev'
|
2018-02-15 08:09:45 +01:00
|
|
|
|
export_fields['Correct. examen'] = 'examination_teacher__abrev'
|
2018-02-14 19:08:03 +01:00
|
|
|
|
export_fields['Prof. dossier'] = 'interview__teacher_file__abrev'
|
|
|
|
|
|
export_fields['Date entretien'] = 'interview__date'
|
|
|
|
|
|
export_fields['Salle entretien'] = 'interview__room'
|
|
|
|
|
|
boolean_fields = [f.name for f in Candidate._meta.get_fields() if isinstance(f, BooleanField)]
|
|
|
|
|
|
choice_fields = {
|
|
|
|
|
|
'gender': dict(GENDER_CHOICES),
|
|
|
|
|
|
'section': dict(SECTION_CHOICES),
|
|
|
|
|
|
'option': dict(OPTION_CHOICES),
|
|
|
|
|
|
'diploma': dict(DIPLOMA_CHOICES),
|
|
|
|
|
|
'diploma_status': dict(DIPLOMA_STATUS_CHOICES),
|
|
|
|
|
|
'aes_accords': dict(AES_ACCORDS_CHOICES),
|
|
|
|
|
|
'residence_permits': dict(RESIDENCE_PERMITS_CHOICES),
|
|
|
|
|
|
}
|
2017-10-19 09:29:08 +02:00
|
|
|
|
|
|
|
|
|
|
export = OpenXMLExport('Exportation')
|
|
|
|
|
|
export.write_line(export_fields.keys(), bold=True)
|
|
|
|
|
|
for cand in queryset.values_list(*export_fields.values()):
|
|
|
|
|
|
values = []
|
|
|
|
|
|
for value, field_name in zip(cand, export_fields.values()):
|
2021-02-01 18:12:59 +01:00
|
|
|
|
if value != '' and value is not None and field_name in choice_fields:
|
2018-02-14 19:08:03 +01:00
|
|
|
|
value = choice_fields[field_name][value]
|
2017-10-19 09:29:08 +02:00
|
|
|
|
if field_name in boolean_fields:
|
|
|
|
|
|
value = 'Oui' if value else ''
|
|
|
|
|
|
values.append(value)
|
|
|
|
|
|
export.write_line(values)
|
|
|
|
|
|
return export.get_http_response('candidats_export')
|
2017-10-18 18:52:59 +02:00
|
|
|
|
|
2017-10-19 09:29:08 +02:00
|
|
|
|
export_candidates.short_description = "Exporter les candidats sélectionnés"
|
2017-10-18 18:52:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CandidateAdmin(admin.ModelAdmin):
|
2018-02-01 14:55:03 +01:00
|
|
|
|
form = CandidateForm
|
2018-06-15 09:02:16 +02:00
|
|
|
|
list_display = ('last_name', 'first_name', 'section', 'confirm_mail', 'validation_mail', 'convocation_mail',
|
|
|
|
|
|
'convoc_confirm_receipt_OK')
|
2017-10-18 18:52:59 +02:00
|
|
|
|
list_filter = ('section', 'option')
|
2018-02-14 17:45:41 +01:00
|
|
|
|
search_fields = ('last_name', 'city')
|
2018-02-02 09:55:09 +01:00
|
|
|
|
readonly_fields = (
|
2018-06-15 09:02:16 +02:00
|
|
|
|
'total_result', 'confirmation_date', 'convocation_date', 'candidate_actions'
|
2018-02-02 09:55:09 +01:00
|
|
|
|
)
|
|
|
|
|
|
actions = [export_candidates]
|
2017-10-18 18:52:59 +02:00
|
|
|
|
fieldsets = (
|
|
|
|
|
|
(None, {
|
|
|
|
|
|
'fields': (('first_name', 'last_name', 'gender'),
|
|
|
|
|
|
('street', 'pcode', 'city', 'district'),
|
|
|
|
|
|
('mobile', 'email'),
|
2018-02-02 09:55:09 +01:00
|
|
|
|
('birth_date', 'avs', 'handicap'),
|
2017-10-18 18:52:59 +02:00
|
|
|
|
('section', 'option'),
|
|
|
|
|
|
('corporation', 'instructor'),
|
2018-02-02 09:36:05 +01:00
|
|
|
|
('deposite_date', 'confirmation_date', 'canceled_file'),
|
2017-10-18 18:52:59 +02:00
|
|
|
|
'comment',
|
|
|
|
|
|
),
|
|
|
|
|
|
}),
|
|
|
|
|
|
("FE", {
|
|
|
|
|
|
'classes': ('collapse',),
|
|
|
|
|
|
'fields': (('exemption_ecg', 'integration_second_year', 'validation_sfpo'),),
|
|
|
|
|
|
}),
|
|
|
|
|
|
("EDE/EDS", {
|
|
|
|
|
|
'classes': ('collapse',),
|
2018-01-26 16:14:00 +01:00
|
|
|
|
'fields': (('diploma', 'diploma_detail', 'diploma_status'),
|
2018-02-02 09:55:09 +01:00
|
|
|
|
('registration_form', 'has_photo', 'certificate_of_payement', 'cv', 'police_record', 'reflexive_text',
|
2018-01-26 16:14:00 +01:00
|
|
|
|
'marks_certificate', 'residence_permits', 'aes_accords'),
|
2018-02-01 10:09:18 +01:00
|
|
|
|
('certif_of_800_childhood', 'certif_of_800_general', 'work_certificate'),
|
2018-01-26 16:14:00 +01:00
|
|
|
|
('promise', 'contract', 'activity_rate'),
|
2018-02-14 18:30:10 +01:00
|
|
|
|
('inscr_other_school',),
|
|
|
|
|
|
('interview', 'examination_teacher'),
|
2018-02-14 18:41:57 +01:00
|
|
|
|
('examination_result', 'interview_result', 'file_result', 'total_result'),
|
2018-06-15 09:02:16 +02:00
|
|
|
|
('confirmation_date', 'validation_date', 'convocation_date', 'convoc_confirm_receipt'),
|
2018-01-26 16:14:00 +01:00
|
|
|
|
),
|
2017-10-18 18:52:59 +02:00
|
|
|
|
}),
|
2018-02-02 09:55:09 +01:00
|
|
|
|
(None, {
|
|
|
|
|
|
'fields': (('candidate_actions',)),
|
|
|
|
|
|
}),
|
2017-10-18 18:52:59 +02:00
|
|
|
|
)
|
|
|
|
|
|
|
2017-11-23 18:09:59 +01:00
|
|
|
|
def confirm_mail(self, obj):
|
2018-02-02 09:36:05 +01:00
|
|
|
|
return obj.confirmation_date is not None
|
2017-11-23 18:09:59 +01:00
|
|
|
|
confirm_mail.boolean = True
|
2018-06-15 09:02:16 +02:00
|
|
|
|
confirm_mail.short_description = 'Confirm. inscript.'
|
2017-10-18 18:52:59 +02:00
|
|
|
|
|
2018-02-14 17:45:41 +01:00
|
|
|
|
def validation_mail(self, obj):
|
|
|
|
|
|
return obj.validation_date is not None
|
|
|
|
|
|
validation_mail.boolean = True
|
2018-06-15 09:02:16 +02:00
|
|
|
|
validation_mail.short_description = 'Validation prof.'
|
2018-02-14 17:45:41 +01:00
|
|
|
|
|
|
|
|
|
|
def convocation_mail(self, obj):
|
|
|
|
|
|
return obj.convocation_date is not None
|
|
|
|
|
|
convocation_mail.boolean = True
|
2018-06-15 09:02:16 +02:00
|
|
|
|
convocation_mail.short_description = 'Conv. exam.'
|
|
|
|
|
|
|
|
|
|
|
|
def convoc_confirm_receipt_OK(self, obj):
|
|
|
|
|
|
return obj.convoc_confirm_receipt is not None
|
|
|
|
|
|
convoc_confirm_receipt_OK.boolean = True
|
|
|
|
|
|
convoc_confirm_receipt_OK.short_description = 'Accusé de récept.'
|
2018-01-26 18:19:16 +01:00
|
|
|
|
|
2018-02-02 09:55:09 +01:00
|
|
|
|
def candidate_actions(self, obj):
|
2018-06-06 18:51:16 +02:00
|
|
|
|
if not obj.pk:
|
|
|
|
|
|
return ''
|
2018-02-02 09:55:09 +01:00
|
|
|
|
return format_html(
|
2018-06-08 13:50:09 +02:00
|
|
|
|
'<a class="button" href="{}">Confirmation de l’inscription FE + ES</a> '
|
2018-02-02 09:55:09 +01:00
|
|
|
|
'<a class="button" href="{}">Validation enseignants EDE</a> '
|
2022-02-15 11:04:35 +01:00
|
|
|
|
'<a class="button" href="{}">Convocation aux examens EDE/EDS</a> '
|
2018-02-02 09:55:09 +01:00
|
|
|
|
'<a class="button" href="{}">Impression du résumé du dossier EDE</a>',
|
|
|
|
|
|
reverse('candidate-confirmation', args=[obj.pk]),
|
|
|
|
|
|
reverse('candidate-validation', args=[obj.pk]),
|
|
|
|
|
|
reverse('candidate-convocation', args=[obj.pk]),
|
|
|
|
|
|
reverse('candidate-summary', args=[obj.pk]),
|
|
|
|
|
|
)
|
|
|
|
|
|
candidate_actions.short_description = 'Actions pour candidats'
|
|
|
|
|
|
candidate_actions.allow_tags = True
|
|
|
|
|
|
|
2018-01-25 15:51:51 +01:00
|
|
|
|
|
|
|
|
|
|
class InterviewAdmin(admin.ModelAdmin):
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-18 18:52:59 +02:00
|
|
|
|
admin.site.register(Candidate, CandidateAdmin)
|
2018-01-25 15:51:51 +01:00
|
|
|
|
admin.site.register(Interview, InterviewAdmin)
|