Changeset 7681


Ignore:
Timestamp:
22 Feb 2012, 21:14:09 (13 years ago)
Author:
Henrik Bettermann
Message:

Uses sources instead of vocabularies and feed sources with dictionaries defined in SIRPUtils. This way we can easily customize the sources.

Location:
main/waeup.sirp/trunk/src/waeup/sirp
Files:
14 edited

Legend:

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

    r7555 r7681  
    3232    ISIRPObject, year_range, validate_email, academic_sessions_vocab)
    3333from waeup.sirp.university.vocabularies import (
    34     application_categories, course_levels)
     34    course_levels, AppCatSource)
    3535from waeup.sirp.students.vocabularies import (
    3636    lgas_vocab, CertificateSource, GenderSource)
     
    188188        required = True,
    189189        default = None,
    190         source = application_categories,
     190        source = AppCatSource(),
    191191        )
    192192
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/browser.txt

    r7674 r7681  
    568568  >>> ctrl = browser.getControl(name='form.semester')
    569569  >>> ctrl.options
    570   ['9', '1', '2', '3']
     570  ['1', '2', '3', '9']
    571571
    572572  >>> ctrl.displayOptions
    573   ['N/A', 'First Semester', 'Second Semester', 'Combined']
     573  ['First Semester', 'Second Semester', 'Combined', 'N/A']
    574574
    575575  >>> ctrl.value = ['1']
  • main/waeup.sirp/trunk/src/waeup/sirp/locales/waeup.sirp.pot

    r7680 r7681  
    1515msgstr ""
    1616"Project-Id-Version: Development/Unknown\n"
    17 "POT-Creation-Date: Wed Feb 22 12:23:01 2012\n"
     17"POT-Creation-Date: Wed Feb 22 22:06:51 2012\n"
    1818"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    1919"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     
    130130msgstr ""
    131131
    132 #: waeup/sirp/objecthistory.py:69
     132#: waeup/sirp/objecthistory.py:73
    133133msgid "by"
    134134msgstr ""
     
    290290msgstr ""
    291291
     292#: waeup/sirp/university/vocabularies.py:28
     293msgid "Pre-Studies"
     294msgstr ""
     295
     296#: waeup/sirp/university/vocabularies.py:29
     297msgid "100 (Year 1)"
     298msgstr ""
     299
     300#: waeup/sirp/university/vocabularies.py:30
     301msgid "200 (Year 2)"
     302msgstr ""
     303
     304#: waeup/sirp/university/vocabularies.py:31
     305msgid "300 (Year 3)"
     306msgstr ""
     307
     308#: waeup/sirp/university/vocabularies.py:32
     309msgid "400 (Year 4)"
     310msgstr ""
     311
     312#: waeup/sirp/university/vocabularies.py:33
     313msgid "500 (Year 5)"
     314msgstr ""
     315
     316#: waeup/sirp/university/vocabularies.py:34
     317msgid "600 (Year 6)"
     318msgstr ""
     319
     320#: waeup/sirp/university/vocabularies.py:35
     321msgid "700 (Year 7)"
     322msgstr ""
     323
     324#: waeup/sirp/university/vocabularies.py:36
     325msgid "800 (Year 8)"
     326msgstr ""
     327
  • main/waeup.sirp/trunk/src/waeup/sirp/objecthistory.py

    r7679 r7681  
    7272        if portal_language != 'en':
    7373            by = translate(_('by'),'waeup.sirp',target_language=portal_language)
    74         msg = '%s - %s %s %s' % (timestamp, msg, by, user)
     74        msg = u'%s - %s %s %s' % (timestamp, msg, by, user)
    7575        msgs.append(msg)
    7676        self._annotations[self.history_key] = msgs
  • main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py

    r7671 r7681  
    4444    FriendlyDateWidget, FriendlyDateDisplayWidget,
    4545    FriendlyDatetimeDisplayWidget)
    46 from waeup.sirp.university.vocabularies import study_modes
    4746from waeup.sirp.students.interfaces import (
    4847    IStudentsContainer, IStudent, IStudentClearance,
     
    533532    def current_mode(self):
    534533        if self.context.certificate is not None:
    535             current_mode = study_modes.getTermByToken(
    536                 self.context.certificate.study_mode).title
    537             return current_mode
     534            studymodes_dict = getUtility(ISIRPUtils).getStudyModesDict()
     535            return studymodes_dict[self.context.certificate.study_mode]
    538536        return
    539537
  • main/waeup.sirp/trunk/src/waeup/sirp/students/interfaces.py

    r7665 r7681  
    2222from zc.sourcefactory.contextual import BasicContextualSourceFactory
    2323from waeup.sirp.interfaces import (
    24     ISIRPObject, academic_sessions_vocab, validate_email)
     24    ISIRPObject, academic_sessions_vocab, validate_email, ISIRPUtils)
    2525from waeup.sirp.schema import TextLineChoice
    26 from waeup.sirp.university.vocabularies import CourseSource, study_modes
     26from waeup.sirp.university.vocabularies import CourseSource, StudyModeSource
    2727from waeup.sirp.students.vocabularies import (
    2828  CertificateSource, StudyLevelSource,
     
    4747    def getTitle(self, context, value):
    4848        return self.verdicts_dict[value]
     49
    4950
    5051class IStudentsUtils(Interface):
     
    278279    entry_mode = schema.Choice(
    279280        title = u'Entry Mode',
    280         vocabulary = study_modes,
     281        source = StudyModeSource(),
    281282        default = u'ug_ft',
    282283        required = True,
  • main/waeup.sirp/trunk/src/waeup/sirp/students/workflow.py

    r7679 r7681  
    182182    """Append message to student history and log file when transition happened.
    183183
    184       Lock and unlock clearance form.
     184    Lock and unlock clearance form.
    185185    """
    186186
  • main/waeup.sirp/trunk/src/waeup/sirp/university/__init__.py

    r7333 r7681  
    22from waeup.sirp.university.course import Course
    33from waeup.sirp.university.coursescontainer import CoursesContainer
     4from waeup.sirp.university.certificate import Certificate
     5from waeup.sirp.university.certificatescontainer import CertificatesContainer
    46from waeup.sirp.university.faculty import Faculty
     7from waeup.sirp.university.department import Department
    58from waeup.sirp.university.facultiescontainer import FacultiesContainer
    69__all__ = (
    7     'Course', 'CoursesContainer', 'Faculty', 'FacultiesContainer')
     10    'Course', 'CoursesContainer',
     11    'Certificate', 'CertificatesContainer',
     12    'Faculty', 'FacultiesContainer', 'Department')
  • main/waeup.sirp/trunk/src/waeup/sirp/university/department.py

    r7334 r7681  
    1919"""
    2020import grok
    21 from zope.component import createObject
    2221from zope.component.interfaces import IFactory
    2322from zope.interface import implementedBy
     23from zope.component import getUtility
     24from waeup.sirp.university.coursescontainer import CoursesContainer
     25from waeup.sirp.university.certificatescontainer import CertificatesContainer
     26from waeup.sirp.interfaces import ISIRPUtils
    2427from waeup.sirp.university.interfaces import IDepartment, IDepartmentAdd
    25 from waeup.sirp.university.vocabularies import inst_types
    2628
    2729class Department(grok.Container):
     
    5355        self.title_prefix = title_prefix
    5456        self.code = code
    55         self.courses = createObject(u'waeup.CoursesContainer')
     57        self.courses = CoursesContainer()
    5658        self.courses.__parent__ = self
    5759        self.courses.__name__ = 'courses'
    58         self.certificates = createObject(u'waeup.CertificatesContainer')
     60        self.certificates = CertificatesContainer()
    5961        self.certificates.__parent__ = self
    6062        self.certificates.__name__ = 'certificates'
     
    7173
    7274    def longtitle(self):
     75        insttypes_dict = getUtility(ISIRPUtils).getInstTypeDict()
    7376        return "%s %s (%s)" % (
    74             inst_types.getTerm(self.title_prefix).title,
     77            insttypes_dict[self.title_prefix],
    7578            self.title, self.code)
    7679
  • main/waeup.sirp/trunk/src/waeup/sirp/university/faculty.py

    r7334 r7681  
    2222from zope.component.interfaces import IFactory
    2323from zope.interface import implementedBy
     24from zope.component import getUtility
     25from waeup.sirp.interfaces import ISIRPUtils
    2426from waeup.sirp.university.interfaces import (
    2527    IFaculty, IFacultyAdd, IDepartment)
    26 from waeup.sirp.university.vocabularies import inst_types
    2728
    2829class Faculty(grok.Container):
     
    6061
    6162    def longtitle(self):
    62         try:
    63             result = "%s %s (%s)" % (
    64                 inst_types.getTerm(
    65                     self.title_prefix).title,
    66                 self.title, self.code)
    67         except:
    68             result = "%s (%s)" % (self.title, self.code)
     63        insttypes_dict = getUtility(ISIRPUtils).getInstTypeDict()
     64        result = "%s %s (%s)" % (
     65            insttypes_dict[self.title_prefix],
     66            self.title, self.code)
    6967        return result
    7068
  • main/waeup.sirp/trunk/src/waeup/sirp/university/interfaces.py

    r7670 r7681  
    2626from waeup.sirp.university.vocabularies import (
    2727    course_levels,
    28     semester,
    29     application_categories,
    30     study_modes,
    31     inst_types,
    3228    CourseSource,
     29    StudyModeSource,
     30    AppCatSource,
     31    InstTypeSource,
     32    SemesterSource,
    3333    )
    3434
     
    5353        title = u'Name prefix',
    5454        default = u'faculty',
    55         vocabulary = inst_types,
     55        source = InstTypeSource(),
    5656        required = True,
    5757        )
     
    100100    title_prefix = schema.Choice(
    101101        title = u'Name prefix',
    102         vocabulary = inst_types,
     102        source = InstTypeSource(),
    103103        default = u'department',
    104104        required = True,
     
    166166        title = u'Semester/Term',
    167167        default = 9,
    168         vocabulary = semester,
     168        source = SemesterSource(),
    169169        required = True,
    170170        )
     
    206206    study_mode = schema.Choice(
    207207        title = u'Study Mode',
    208         vocabulary = study_modes,
     208        source = StudyModeSource(),
    209209        default = u'ug_ft',
    210210        required = True,
     
    227227    application_category = schema.Choice(
    228228        title = u'Application Category',
    229         vocabulary = application_categories,
     229        source = AppCatSource(),
    230230        default = u'basic',
    231231        required = True,
  • main/waeup.sirp/trunk/src/waeup/sirp/university/tests/test_faculty.py

    r7195 r7681  
    2222import unittest
    2323from zope.interface.verify import verifyObject, verifyClass
    24 from waeup.sirp.university import Faculty
    25 from waeup.sirp.university.interfaces import IFaculty
     24from waeup.sirp.university import Faculty, Department
     25from waeup.sirp.university.interfaces import IFaculty, IDepartment
    2626
    27 class FacultyTests(unittest.TestCase):
     27class FacultyAndDepartmentTests(unittest.TestCase):
    2828
    2929    def test_ifaces(self):
     
    3232        verifyClass(IFaculty, Faculty)
    3333        verifyObject(IFaculty, fac)
     34        dep = Department()
     35        verifyClass(IDepartment, Department)
     36        verifyObject(IDepartment, dep)
    3437        return
    35 
    36     def test_longtitle(self):
    37         # Make sure we get a longtitle
    38         fac = Faculty()
    39         self.assertEqual(fac.longtitle(),
    40                          u'Faculty of Unnamed Faculty (NA)')
    41 
    42     def test_longtitle_no_terms(self):
    43         # Make sure we get a longtitle also if no term for the title
    44         # prefix is available
    45         fac = Faculty()
    46         fac.title_prefix = 'Studio for' # Not a valid prefix
    47         self.assertEqual(fac.longtitle(),
    48                          u'Unnamed Faculty (NA)')
  • main/waeup.sirp/trunk/src/waeup/sirp/university/vocabularies.py

    r7601 r7681  
    1919"""
    2020from zc.sourcefactory.basic import BasicSourceFactory
     21from zc.sourcefactory.contextual import BasicContextualSourceFactory
    2122from zope.catalog.interfaces import ICatalog
    2223from zope.component import getUtility
    23 from waeup.sirp.interfaces import SimpleSIRPVocabulary
     24from waeup.sirp.interfaces import SimpleSIRPVocabulary, ISIRPUtils
     25from waeup.sirp.interfaces import MessageFactory as _
    2426
    25 inst_types = SimpleSIRPVocabulary(
    26     ('Faculty of','faculty'),
    27     ('Department of','department'),
    28     ('School of','school'),
    29     ('School for','school_for'),
    30     ('Institute of','institute'),
    31     ('Office for','office'),
    32     ('Centre for','centre'),
    33     ('College','college'),
     27course_levels = SimpleSIRPVocabulary(
     28    (_('Pre-Studies'),10),
     29    (_('100 (Year 1)'),100),
     30    (_('200 (Year 2)'),200),
     31    (_('300 (Year 3)'),300),
     32    (_('400 (Year 4)'),400),
     33    (_('500 (Year 5)'),500),
     34    (_('600 (Year 6)'),600),
     35    (_('700 (Year 7)'),700),
     36    (_('800 (Year 8)'),800),
    3437    )
    3538
    36 course_levels = SimpleSIRPVocabulary(
    37     ('Pre-Studies', 10),
    38     ('100 (Year 1)',100),
    39     ('200 (Year 2)',200),
    40     ('300 (Year 3)',300),
    41     ('400 (Year 4)',400),
    42     ('500 (Year 5)',500),
    43     ('600 (Year 6)',600),
    44     ('700 (Year 7)',700),
    45     ('800 (Year 8)',800),
    46     )
     39class SemesterSource(BasicContextualSourceFactory):
     40    """An institution type source delivers semester or term descriptors.
     41    """
     42    def getValues(self, context):
     43        self.semesters_dict = getUtility(ISIRPUtils).getSemesterDict()
     44        return self.semesters_dict.keys()
    4745
    48 semester = SimpleSIRPVocabulary(
    49     ('N/A', 9),
    50     ('First Semester', 1),
    51     ('Second Semester', 2),
    52     ('Combined', 3)
    53     )
     46    def getToken(self, context, value):
     47        return str(value)
    5448
    55 application_categories = SimpleSIRPVocabulary(
    56     ('PUME, PDE, PCE, PRENCE','basic'),
    57     ('Part-Time, Diploma, Certificate','cest'),
    58     ('Sandwich','sandwich'),
    59     ('Postgraduate','pg'),
    60     ('no application','no'),
    61     )
     49    def getTitle(self, context, value):
     50        return self.semesters_dict[value]
    6251
    63 study_modes = SimpleSIRPVocabulary(
    64     ('UME Full Time','ume_ft'),
    65     ('Direct Entry Full Time','de_ft'),
    66     ('Direct Entry Part Time','de_pt'),
    67     ('Diploma Full Time','dp_ft'),
    68     ('Diploma Part Time','dp_pt'),
    69     ('Undergraduate Full Time','ug_ft'),
    70     ('Undergraduate Part Time','ug_pt'),
    71     ('Postgraduate Full Time','pg_ft'),
    72     ('Postgraduate Part Time','pg_pt'),
    73     ('Certificate Full Time','ct_ft'),
    74     ('Certificate Part Time','ct_pt'),
    75     ('Remedial','rm_ft'),
    76     ('Remedial with deficiencies','rmd_ft'),
    77     ('Post Higher Education Full Time','ph_ft'),
    78     ('Joint Matriculation Full Time','jm_ft'),
    79     ('Transfer Full Time','transfer_ft'),
    80     ('Transfer Part Time','transfer_pt'),
    81     )
     52class InstTypeSource(BasicContextualSourceFactory):
     53    """An institution type source delivers types of institutions
     54    in the portal.
     55    """
     56    def getValues(self, context):
     57        self.insttypes_dict = getUtility(ISIRPUtils).getInstTypeDict()
     58        return sorted(self.insttypes_dict.keys())
     59
     60    def getToken(self, context, value):
     61        return value
     62
     63    def getTitle(self, context, value):
     64        return self.insttypes_dict[value]
     65
     66class AppCatSource(BasicContextualSourceFactory):
     67    """A application category source delivers all application categories
     68    provided in the portal.
     69    """
     70    def getValues(self, context):
     71        self.appcats_dict = getUtility(ISIRPUtils).getAppCatDict()
     72        return sorted(self.appcats_dict.keys())
     73
     74    def getToken(self, context, value):
     75        return value
     76
     77    def getTitle(self, context, value):
     78        return self.appcats_dict[value]
     79
     80class StudyModeSource(BasicContextualSourceFactory):
     81    """A study modes source delivers all study modes provided
     82    in the portal.
     83    """
     84    def getValues(self, context):
     85        self.studymodes_dict = getUtility(ISIRPUtils).getStudyModesDict()
     86        return sorted(self.studymodes_dict.keys())
     87
     88    def getToken(self, context, value):
     89        return value
     90
     91    def getTitle(self, context, value):
     92        return self.studymodes_dict[value]
    8293
    8394class CourseSource(BasicSourceFactory):
  • main/waeup.sirp/trunk/src/waeup/sirp/utils/utils.py

    r7678 r7681  
    4343    # (e.g. object histories).
    4444    PORTAL_LANGUAGE = 'en'
     45
     46    def getInstTypeDict(self):
     47        """Provide a dictionary of study modes.
     48        """
     49        return {
     50        'faculty': 'Faculty of',
     51        'department': 'Department of',
     52        'school': 'School of',
     53        'office': 'Office for',
     54        'centre': 'Centre for',
     55        'institute': 'Institute of',
     56        'school_for': 'School for',
     57        }
     58
     59    def getStudyModesDict(self):
     60        """Provide a dictionary of study modes.
     61        """
     62        return {
     63        'rmd_ft': 'Remedial with deficiencies',
     64        'dp_pt': 'Diploma Part Time',
     65        'ct_ft': 'Certificate Full Time',
     66        'dp_ft': 'Diploma Full Time',
     67        'de_pt': 'Direct Entry Part Time',
     68        'pg_ft': 'Postgraduate Full Time',
     69        'pg_pt': 'Postgraduate Part Time',
     70        'jm_ft': 'Joint Matriculation Full Time',
     71        'ume_ft': 'UME Full Time',
     72        'de_ft': 'Direct Entry Full Time',
     73        'ph_ft': 'Post Higher Education Full Time',
     74        'transfer_pt': 'Transfer Part Time',
     75        'ug_pt': 'Undergraduate Part Time',
     76        'transfer_ft': 'Transfer Full Time',
     77        'ct_pt': 'Certificate Part Time',
     78        'ug_ft': 'Undergraduate Full Time',
     79        'rm_ft': 'Remedial'
     80        }
     81
     82    def getAppCatDict(self):
     83        """Provide a dictionary of study modes.
     84        """
     85        return {
     86        'basic': 'PUME, PDE, PCE, PRENCE',
     87        'no': 'no application',
     88        'pg': 'Postgraduate',
     89        'sandwich': 'Sandwich',
     90        'cest': 'Part-Time, Diploma, Certificate'
     91        }
     92
     93    def getSemesterDict(self):
     94        """Provide a dictionary of semester or trimester types.
     95        """
     96        return {
     97        1: 'First Semester',
     98        2: 'Second Semester',
     99        3: 'Combined',
     100        9: 'N/A'
     101        }
    45102
    46103    def sendContactForm(self,from_name,from_addr,rcpt_name,rcpt_addr,
Note: See TracChangeset for help on using the changeset viewer.