Changeset 7683 for main


Ignore:
Timestamp:
23 Feb 2012, 07:43:06 (13 years ago)
Author:
Henrik Bettermann
Message:

Merge the vocabularies module with the interfaces module. I don't see any other way to avoid conflicting imports since we have now IApplicantsUtils defined in interfaces and needed in vocabularies.

Location:
main/waeup.sirp/trunk/src/waeup/sirp/applicants
Files:
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/browser.py

    r7494 r7683  
    2929from waeup.sirp.applicants.interfaces import (
    3030    IApplicant, IApplicantEdit, IApplicantsRoot,
    31     IApplicantsContainer, IApplicantsContainerAdd, application_types_vocab,
    32     MAX_UPLOAD_SIZE, IApplicantOnlinePayment,
     31    IApplicantsContainer, IApplicantsContainerAdd,
     32    MAX_UPLOAD_SIZE, IApplicantOnlinePayment, IApplicantsUtils
    3333    )
    3434from waeup.sirp.applicants.workflow import INITIALIZED, STARTED, PAID, SUBMITTED
     
    158158        year = data['year']
    159159        code = u'%s%s' % (data['prefix'], year)
    160         prefix = application_types_vocab.getTerm(data['prefix'])
     160        appcats_dict = getUtility(IApplicantsUtils).getApplicationTypeDict()
     161        prefix = appcats_dict[data['prefix']][0]
    161162        title = u'%s %s/%s' % (prefix.title, year, year + 1)
    162163        if code in self.context.keys():
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/interfaces.py

    r7682 r7683  
    2323from zope import schema
    2424from zope.interface import Interface, Attribute, implements, directlyProvides
    25 from zope.component import getUtilitiesFor, queryUtility
     25from zope.component import getUtilitiesFor, queryUtility, getUtility
    2626from zope.catalog.interfaces import ICatalog
    2727from zope.schema.interfaces import (
    2828    ValidationError, ISource, IContextSourceBinder)
    2929from zc.sourcefactory.basic import BasicSourceFactory
     30from zc.sourcefactory.contextual import BasicContextualSourceFactory
    3031from waeup.sirp.schema import TextLineChoice
    3132from waeup.sirp.interfaces import (
     
    3536from waeup.sirp.students.vocabularies import (
    3637    lgas_vocab, CertificateSource, GenderSource)
    37 from waeup.sirp.applicants.vocabularies import (
    38     application_types_vocab, AppCatCertificateSource)
    3938from waeup.sirp.payments.interfaces import IOnlinePayment
    4039
     
    7877directlyProvides(contextual_reg_num_source, IContextSourceBinder)
    7978
     79class AppCatCertificateSource(CertificateSource):
     80    """An application certificate source delivers all courses which belong to
     81    a certain application_category.
     82    """
     83    def getValues(self, context):
     84        # appliction category not available when certificate was deleted.
     85        # shouldn't that info be part of applicant info instead?
     86        # when we cannot determine the appcat, we will display all courses.
     87        appcat = getattr(getattr(context, '__parent__', None),
     88                         'application_category', None)
     89        catalog = getUtility(ICatalog, name='certificates_catalog')
     90        result = catalog.searchResults(
     91            application_category=(appcat,appcat))
     92        result = sorted(result, key=lambda value: value.code)
     93        curr_course = context.course1
     94        if curr_course is not None and curr_course not in result:
     95            # display also current course even if it is not catalogued
     96            # (any more)
     97            result = [curr_course,] + result
     98        return result
     99
     100class ApplicationTypeSource(BasicContextualSourceFactory):
     101    """An application type source delivers screening types defined in the
     102    portal.
     103    """
     104    def getValues(self, context):
     105        self.appcats_dict = getUtility(
     106            IApplicantsUtils).getApplicationTypeDict()
     107        return sorted(self.appcats_dict.keys())
     108
     109    def getToken(self, context, value):
     110        return value
     111
     112    def getTitle(self, context, value):
     113        return self.appcats_dict[value][0]
     114
     115# Maybe Uniben still needs this ...
     116#class ApplicationPinSource(BasicContextualSourceFactory):
     117#    """An application pin source delivers PIN prefixes for application
     118#    defined in the portal.
     119#    """
     120#    def getValues(self, context):
     121#        self.apppins_dict = getUtility(
     122#            IApplicantsUtils).getApplicationTypeDict()
     123#        return sorted(self.appcats_dict.keys())
     124#
     125#    def getToken(self, context, value):
     126#        return value
     127#
     128#    def getTitle(self, context, value):
     129#        return u"%s (%s)" % (
     130#            self.apppins_dict[value][1],self.apppins_dict[value][0])
     131
    80132class ApplicantContainerProviderSource(BasicSourceFactory):
    81133    """A source offering all available applicants container types.
     
    119171    """A collection of methods which are subject to customization.
    120172    """
     173    pass
    121174
    122175class IApplicantsRoot(ISIRPObject, IContainer):
     
    151204
    152205    prefix = schema.Choice(
    153         title = u'Application target',
    154         required = True,
    155         default = None,
    156         source = application_types_vocab,
     206        title = u'Application Target',
     207        required = True,
     208        default = None,
     209        source = ApplicationTypeSource(),
    157210        readonly = True,
    158211        )
     
    166219
    167220    year = schema.Choice(
    168         title = u'Year of entrance',
     221        title = u'Year of Entrance',
    169222        required = True,
    170223        default = None,
     
    174227
    175228    provider = schema.Choice(
    176         title = u'Applicants container type',
     229        title = u'Applicants Container Type',
    177230        required = True,
    178231        default = None,
     
    181234        )
    182235
     236    # Maybe Uniben still needs this ...
    183237    #ac_prefix = schema.Choice(
    184238    #    title = u'Activation code prefix',
    185239    #    required = True,
    186240    #    default = None,
    187     #    source = application_pins_vocab,
     241    #    source = ApplicationPinSource(),
    188242    #    )
    189243
     
    203257
    204258    startdate = schema.Date(
    205         title = u'Application start date',
     259        title = u'Application Start Date',
    206260        required = False,
    207261        default = None,
     
    209263
    210264    enddate = schema.Date(
    211         title = u'Application closing date',
     265        title = u'Application Closing Date',
    212266        required = False,
    213267        default = None,
     
    254308    """
    255309    prefix = schema.Choice(
    256         title = u'Application target',
    257         required = True,
    258         default = None,
    259         source = application_types_vocab,
     310        title = u'Application Target',
     311        required = True,
     312        default = None,
     313        source = ApplicationTypeSource(),
    260314        readonly = False,
    261315        )
    262316
    263317    year = schema.Choice(
    264         title = u'Year of entrance',
     318        title = u'Year of Entrance',
    265319        required = True,
    266320        default = None,
     
    270324
    271325    provider = schema.Choice(
    272         title = u'Applicants container type',
     326        title = u'Applicants Container Type',
    273327        required = True,
    274328        default = None,
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_interfaces.py

    r7193 r7683  
    2222from zc.sourcefactory.browser.source import FactoredTerms
    2323from zope.publisher.browser import TestRequest
    24 from waeup.sirp.applicants.vocabularies import application_types_vocab
     24from waeup.sirp.applicants.interfaces import ApplicationTypeSource
    2525from waeup.sirp.students.vocabularies import GenderSource
    26 
    27 class ApplicationCategoriesTestCase(unittest.TestCase):
    28 
    29     def setUp(self):
    30         self.vocab = application_types_vocab
    31         return
    32 
    33     def test_vocabulary_len(self):
    34         self.assertEqual(len(self.vocab), 10)
    35         return
    36 
    37     def test_vocabulary_items(self):
    38         self.assertTrue('pude' in self.vocab)
    39         return
    40 
    41     def test_term_attributes(self):
    42         # Check that each vocab entry provided value, token, and title.
    43         term = self.vocab.getTermByToken('pude')
    44         self.assertEqual(term.token, 'pude')
    45         self.assertEqual(term.value, 'pude')
    46         self.assertEqual(term.title, 'Post UDE Screening')
    47         return
    4826
    4927class InterfacesTest(unittest.TestCase):
     
    8260    suite = unittest.TestSuite()
    8361    for testcase in [
    84             ApplicationCategoriesTestCase,
    8562            InterfacesTest,
    8663            ]:
Note: See TracChangeset for help on using the changeset viewer.