## $Id: vocabularies.py 7192 2011-11-25 07:15:50Z 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
##
"""Vocabularies and sources for the application section.
"""
from zope.component import getUtility
from zope.catalog.interfaces import ICatalog
from waeup.sirp.interfaces import SimpleWAeUPVocabulary
from waeup.sirp.students.vocabularies import CertificateSource

#: Types of applications we support.
APPLICATION_TYPES = (
    ('General Studies', 'app','APP'),
    ('Pre-NCE Programme', 'prence','PRE'),
    ('Post UME Screening Test', 'pume','PUME'),
    ('Post UDE Screening', 'pude','PUDE'),
    ('Part Time Degree in Education', 'sandwich','SAND'),
    ('Part-Time Degree Programmes', 'pt','PTP'),
    ('Diploma Programmes', 'dp','DPP'),
    ('PCE Screening', 'pce','PCE'),
    ('Certificate Programmes', 'ct','CTP'),
    ('Common Entry Screening Test', 'cest','CEST'),
    )

#: A :class:`waeup.sirp.interfaces.SimpleWAeUPVocabulary` of supported
#: application or screening types.
application_types_vocab = SimpleWAeUPVocabulary(
    *[(x[0],x[1]) for x in APPLICATION_TYPES])
application_pins_vocab = SimpleWAeUPVocabulary(
    *[(u"%s (%s)" % (x[2],x[0]),x[2]) for x in APPLICATION_TYPES])


class AppCatCertificateSource(CertificateSource):
    """An application certificate source delivers all courses which belong to
    a certain application_category.
    """
    def getValues(self, context):
        appcat = context.__parent__.application_category
        catalog = getUtility(ICatalog, name='certificates_catalog')
        return sorted(list(
                catalog.searchResults(
                    code=('', 'z*'),
                    application_category=(appcat,appcat))),
                    key=lambda value: value.code)
