## $Id: browser.py 12888 2015-04-26 19:45:46Z henrik $
##
## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##
"""UI components for basic applicants and related components.
"""
import grok
from zope.component import getUtility
from zope.i18n import translate
from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
from zope.formlib.textwidgets import BytesDisplayWidget
from waeup.kofa.students.interfaces import IStudentsUtils
from kofacustom.nigeria.applicants.browser import (
NigeriaApplicantDisplayFormPage,
NigeriaApplicantManageFormPage,
NigeriaApplicantEditFormPage,
NigeriaPDFApplicationSlip)
from kofacustom.nigeria.applicants.interfaces import (
OMIT_DISPLAY_FIELDS,
#UG_OMIT_DISPLAY_FIELDS,
#UG_OMIT_PDF_FIELDS,
#UG_OMIT_MANAGE_FIELDS,
#UG_OMIT_EDIT_FIELDS,
#PUTME_OMIT_DISPLAY_FIELDS,
#PUTME_OMIT_PDF_FIELDS,
#PUTME_OMIT_MANAGE_FIELDS,
#PUTME_OMIT_EDIT_FIELDS,
#PUTME_OMIT_RESULT_SLIP_FIELDS,
#PUDE_OMIT_DISPLAY_FIELDS,
#PUDE_OMIT_PDF_FIELDS,
#PUDE_OMIT_MANAGE_FIELDS,
#PUDE_OMIT_EDIT_FIELDS,
#PUDE_OMIT_RESULT_SLIP_FIELDS,
)
from kofacustom.wdu.applicants.interfaces import (
ICustomUGApplicant,
ICustomUGApplicantEdit,
ICustomPUTMEApplicantEdit,
)
from kofacustom.wdu.interfaces import MessageFactory as _
# UG students are all undergraduate students.
UG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS
UG_OMIT_PDF_FIELDS = UG_OMIT_DISPLAY_FIELDS + ('phone',)
UG_OMIT_MANAGE_FIELDS = ('special_application',)
UG_OMIT_EDIT_FIELDS = UG_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + (
'student_id', 'notice',
'screening_score',
'screening_venue',
'screening_date',
#'jamb_age',
#'jamb_subjects',
#'jamb_score',
'aggregate')
# PUTME is a subgroup of UG with the same interface.
PUTME_OMIT_FIELDS = (
'hq_type',
'hq_matric_no',
'hq_degree',
'hq_school',
'hq_session',
'hq_disc',
)
PUTME_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + PUTME_OMIT_FIELDS
PUTME_OMIT_MANAGE_FIELDS = UG_OMIT_MANAGE_FIELDS + PUTME_OMIT_FIELDS
PUTME_OMIT_EDIT_FIELDS = UG_OMIT_EDIT_FIELDS + PUTME_OMIT_FIELDS + (
#'firstname',
#'middlename',
#'lastname',
#'sex',
#'course1',
#'lga'
)
PUTME_OMIT_PDF_FIELDS = PUTME_OMIT_DISPLAY_FIELDS + ('phone',)
PUTME_OMIT_RESULT_SLIP_FIELDS = PUTME_OMIT_DISPLAY_FIELDS + (
'phone',
'date_of_birth', 'sex',
'nationality', 'lga', #'perm_address',
'course2', 'screening_venue',
'screening_date')
# PUDE is a subgroup of UG with the same interface.
PUDE_OMIT_FIELDS = (
'jamb_subjects',
'jamb_score',
'jamb_age',
'aggregate')
PUDE_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + PUDE_OMIT_FIELDS
PUDE_OMIT_MANAGE_FIELDS = UG_OMIT_MANAGE_FIELDS + PUDE_OMIT_FIELDS
PUDE_OMIT_EDIT_FIELDS = set(UG_OMIT_EDIT_FIELDS + PUDE_OMIT_FIELDS + (
#'firstname',
#'middlename',
#'lastname',
#'sex',
#'course1',
#'lga'
))
PUDE_OMIT_PDF_FIELDS = PUDE_OMIT_DISPLAY_FIELDS + ('phone',)
PUDE_OMIT_RESULT_SLIP_FIELDS = PUDE_OMIT_DISPLAY_FIELDS + (
'phone',
'date_of_birth', 'sex',
'nationality', 'lga', #'perm_address',
'course2', 'screening_venue',
'screening_date')
class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
"""A display view for applicant data.
"""
@property
def form_fields(self):
if self.target is not None and self.target.startswith('putme'):
form_fields = grok.AutoFields(ICustomUGApplicant)
for field in PUTME_OMIT_DISPLAY_FIELDS:
form_fields = form_fields.omit(field)
elif self.target is not None and self.target.startswith('pude'):
form_fields = grok.AutoFields(ICustomUGApplicant)
for field in PUDE_OMIT_DISPLAY_FIELDS:
form_fields = form_fields.omit(field)
else:
form_fields = grok.AutoFields(ICustomUGApplicant)
for field in UG_OMIT_DISPLAY_FIELDS:
form_fields = form_fields.omit(field)
#form_fields['perm_address'].custom_widget = BytesDisplayWidget
form_fields['notice'].custom_widget = BytesDisplayWidget
if not getattr(self.context, 'student_id'):
form_fields = form_fields.omit('student_id')
if not getattr(self.context, 'screening_score'):
form_fields = form_fields.omit('screening_score')
if not getattr(self.context, 'screening_venue') or self._not_paid():
form_fields = form_fields.omit('screening_venue')
if not getattr(self.context, 'screening_date') or self._not_paid():
form_fields = form_fields.omit('screening_date')
return form_fields
class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
@property
def note(self):
if self.context.sex == 'm':
pronoun = ('he', 'his', 'him')
else:
pronoun = ('she', 'her', 'her')
return ("
The applicant has confirmed "
"that the passport photograph uploaded on this form is a true "
"picture of %s. The applicant also declared that, by submitting this form, %s wish to enter "
"Wester Delta University, Oghara, that the particulars given in this form are "
"to the best of %s knowledge and belief correct and that if admitted to the "
"university, %s shall regard %sself bound by the Ordinance Statutes and "
"Regulations of the University in so far as they affect %s. The applicant understands that "
"withholding any information requested or giving information may make %s "
"ineligable for admission, regsitration or matriculation, or compel %s "
"expulsion from the institution."
% (pronoun[2],
pronoun[0],
pronoun[1],
pronoun[0],
pronoun[2],
pronoun[2],
pronoun[2],
pronoun[1])
)
@property
def form_fields(self):
if self.target is not None and self.target.startswith('putme'):
form_fields = grok.AutoFields(ICustomUGApplicant)
if self._reduced_slip():
for field in PUTME_OMIT_RESULT_SLIP_FIELDS:
form_fields = form_fields.omit(field)
else:
for field in PUTME_OMIT_PDF_FIELDS:
form_fields = form_fields.omit(field)
elif self.target is not None and self.target.startswith('pude'):
form_fields = grok.AutoFields(ICustomUGApplicant)
if self._reduced_slip():
for field in PUDE_OMIT_RESULT_SLIP_FIELDS:
form_fields = form_fields.omit(field)
else:
for field in PUDE_OMIT_PDF_FIELDS:
form_fields = form_fields.omit(field)
else:
form_fields = grok.AutoFields(ICustomUGApplicant)
for field in UG_OMIT_PDF_FIELDS:
form_fields = form_fields.omit(field)
if not getattr(self.context, 'student_id'):
form_fields = form_fields.omit('student_id')
if not getattr(self.context, 'screening_score'):
form_fields = form_fields.omit('screening_score')
if not getattr(self.context, 'screening_venue'):
form_fields = form_fields.omit('screening_venue')
if not getattr(self.context, 'screening_date'):
form_fields = form_fields.omit('screening_date')
return form_fields
class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
"""A full edit view for applicant data.
"""
@property
def form_fields(self):
if self.target is not None and self.target.startswith('putme'):
form_fields = grok.AutoFields(ICustomUGApplicant)
for field in PUTME_OMIT_MANAGE_FIELDS:
form_fields = form_fields.omit(field)
elif self.target is not None and self.target.startswith('pude'):
form_fields = grok.AutoFields(ICustomUGApplicant)
for field in PUDE_OMIT_MANAGE_FIELDS:
form_fields = form_fields.omit(field)
else:
form_fields = grok.AutoFields(ICustomUGApplicant)
for field in UG_OMIT_MANAGE_FIELDS:
form_fields = form_fields.omit(field)
form_fields['student_id'].for_display = True
form_fields['applicant_id'].for_display = True
return form_fields
class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
"""An applicant-centered edit view for applicant data.
"""
@property
def form_fields(self):
if self.target is not None and self.target.startswith('putme'):
form_fields = grok.AutoFields(ICustomPUTMEApplicantEdit)
for field in PUTME_OMIT_EDIT_FIELDS:
form_fields = form_fields.omit(field)
elif self.target is not None and self.target.startswith('pude'):
form_fields = grok.AutoFields(ICustomUGApplicantEdit)
for field in PUDE_OMIT_EDIT_FIELDS:
form_fields = form_fields.omit(field)
else:
form_fields = grok.AutoFields(ICustomUGApplicantEdit)
for field in UG_OMIT_EDIT_FIELDS:
form_fields = form_fields.omit(field)
form_fields['applicant_id'].for_display = True
form_fields['reg_number'].for_display = True
return form_fields