Ignore:
Timestamp:
2 Jun 2012, 17:55:56 (12 years ago)
Author:
uli
Message:

We can speedup imports etc. by using the new contextual source, which
requires a context dependent contains() method to work faster.

File:
1 edited

Legend:

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

    r8589 r8607  
    7979
    8080class AppCatCertificateSource(CertificateSource):
    81     """An application certificate source delivers all courses which belong to
    82     a certain application_category.
    83     """
     81    """An application certificate source delivers all certificates
     82    which belong to a certain application_category.
     83
     84    This source is meant to be used with Applicants.
     85
     86    The application category must match the application category of
     87    the context parent, normally an applicants container.
     88    """
     89    def contains(self, context, value):
     90        context_appcat = getattr(getattr(
     91            context, '__parent__', None), 'application_category', None)
     92        if context_appcat is None:
     93            # If the context (applicant) has no application category,
     94            # then it might be not part of a container (yet), for
     95            # instance during imports. We consider this correct.
     96            return True
     97        if value.application_category == context_appcat:
     98            return True
     99        return False
     100
    84101    def getValues(self, context):
    85102        # appliction category not available when certificate was deleted.
     
    92109            application_category=(appcat,appcat))
    93110        result = sorted(result, key=lambda value: value.code)
     111        # XXX: What does the following mean here?
    94112        curr_course = context.course1
    95113        if curr_course is not None and curr_course not in result:
Note: See TracChangeset for help on using the changeset viewer.