Changeset 8767 for main


Ignore:
Timestamp:
20 Jun 2012, 11:27:11 (12 years ago)
Author:
uli
Message:

Take over fixed regnum source from students.

File:
1 edited

Legend:

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

    r8742 r8767  
    3333from waeup.kofa.payments.interfaces import IOnlinePayment
    3434from waeup.kofa.schema import PhoneNumber
    35 from waeup.kofa.students.vocabularies import GenderSource
     35from waeup.kofa.students.vocabularies import GenderSource, RegNumberSource
    3636from waeup.kofa.university.vocabularies import AppCatSource, CertificateSource
    3737
     
    4848    pass
    4949
    50 class RegNumberSource(object):
    51     implements(ISource)
     50class ApplicantRegNumberSource(RegNumberSource):
     51    """A source that accepts any reg number if not used already by a
     52    different applicant.
     53    """
    5254    cat_name = 'applicants_catalog'
    5355    field_name = 'reg_number'
    5456    validation_error = RegNumInSource
    55     def __init__(self, context):
    56         self.context = context
    57         return
    58 
    59     def __contains__(self, value):
    60         cat = queryUtility(ICatalog, self.cat_name)
    61         if cat is None:
    62             return True
    63         kw = {self.field_name: (value, value)}
    64         results = cat.searchResults(**kw)
    65         for entry in results:
    66             if entry.applicant_id != self.context.applicant_id:
    67                 # XXX: sources should simply return False.
    68                 #      But then we get some stupid error message in forms
    69                 #      when validation fails.
    70                 raise self.validation_error(value)
    71                 #return False
    72         return True
     57    comp_field = 'applicant_id'
    7358
    7459def contextual_reg_num_source(context):
    75     source = RegNumberSource(context)
     60    source = ApplicantRegNumberSource(context)
    7661    return source
    7762directlyProvides(contextual_reg_num_source, IContextSourceBinder)
Note: See TracChangeset for help on using the changeset viewer.