## $Id: browser.py 16695 2021-11-03 15:38:36Z henrik $
##
## Copyright (C) 2012 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
##
import grok
import os
from zope.i18n import translate
from zope.schema.interfaces import ConstraintNotSatisfied
from zope.component import getUtility
from hurry.workflow.interfaces import IWorkflowInfo
from waeup.kofa.interfaces import REQUESTED, IExtFileStore, IKofaUtils
from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
from waeup.kofa.browser.layout import KofaEditFormPage
from waeup.kofa.browser.layout import action, jsaction
from waeup.kofa.students.browser import (
    StudyLevelEditFormPage, StudyLevelDisplayFormPage,
    StudentBasePDFFormPage, ExportPDFCourseRegistrationSlip,
    CourseTicketDisplayFormPage, StudentTriggerTransitionFormPage,
    ExportPDFAdmissionSlip,
    msave, emit_lock_message)
from waeup.kofa.students.interfaces import IStudentsUtils, ICourseTicket
from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS
from kofacustom.nigeria.students.browser import (
    NigeriaOnlinePaymentDisplayFormPage,
    NigeriaStudentBaseManageFormPage,
    NigeriaStudentClearanceEditFormPage,
    NigeriaOnlinePaymentAddFormPage,
    NigeriaExportPDFPaymentSlip,
    NigeriaExportPDFClearanceSlip,
    )

from kofacustom.edocons.students.interfaces import (
    ICustomStudentOnlinePayment, ICustomStudentStudyCourse,
    ICustomStudentStudyLevel)
from kofacustom.edocons.interfaces import MessageFactory as _

class CustomExportPDFAdmissionSlip(ExportPDFAdmissionSlip):
    """Deliver a PDF Admission slip.
    """

    omit_fields = ('date_of_birth', 'current_level', 'current_mode',
                   'certificate', 'faculty')
    #form_fields = grok.AutoFields(IStudentBase).select('student_id', 'reg_number')

    post_text = '''
You are expected to proceed and pay your school fees of before the 12th of Nov. and on resumption you are to present a sworn affidavit on:

1. Good behavior
2. Renunciation of cultism

Others are:

1. Letter of sponsorship
2. Acceptance letter

Please visit the College Registry (student affairs division) for more enquiries.

Congratulations!
'''

    @property
    def label(self):
        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
        return translate(_('Admission Letter of'),
            'waeup.kofa', target_language=portal_language) \
            + ' %s' % self.context.display_fullname

    def render(self):
        students_utils = getUtility(IStudentsUtils)
        letterhead_path = os.path.join(
            os.path.dirname(__file__), 'static', 'letterhead_admission.jpg')
        if not os.path.exists(letterhead_path):
            letterhead_path = None
        return students_utils.renderPDFAdmissionLetter(self,
            self.context.student, omit_fields=self.omit_fields,
            letterhead_path=letterhead_path, post_text=self.post_text)

