Changeset 7838 for main/waeup.kofa/trunk


Ignore:
Timestamp:
11 Mar 2012, 16:03:54 (13 years ago)
Author:
Henrik Bettermann
Message:

Uli, what's better: catching exceptions or using BasicContextualSourceFactory? instead of BasicSourceFactory?? This revision is meant to demonstrate the two alternative ways constructing sources. The first one does always work.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/university/vocabularies.py

    r7819 r7838  
    3737    )
    3838
    39 class SemesterSource(BasicContextualSourceFactory):
     39class SemesterSource(BasicSourceFactory):
    4040    """An institution type source delivers semester or term descriptors.
    4141    """
    42     def getValues(self, context):
    43         semesters_dict = getUtility(IKofaUtils).getSemesterDict()
    44         return semesters_dict.keys()
    45 
    46     def getToken(self, context, value):
     42    def getValues(self):
     43        try:
     44            # We have to 'try', don't know why (henrik)
     45            # Alternatively, we can use BasicContextualSourceFactory,
     46            # see sources below
     47            from waeup.kofa.interfaces import IKofaUtils
     48            return getUtility(IKofaUtils).getSemesterDict().keys()
     49        except:
     50            return [9]
     51       
     52    def getToken(self, value):
    4753        return str(value)
    4854
    49     def getTitle(self, context, value):
    50         semesters_dict = getUtility(IKofaUtils).getSemesterDict()
    51         return semesters_dict[value]
     55    def getTitle(self, value):
     56        try:
     57            from waeup.kofa.interfaces import IKofaUtils
     58            semesters_dict = getUtility(IKofaUtils).getSemesterDict()
     59            return semesters_dict[value]
     60        except:
     61            value
    5262
    5363class InstTypeSource(BasicContextualSourceFactory):
Note: See TracChangeset for help on using the changeset viewer.