Changeset 5447 for main


Ignore:
Timestamp:
16 Aug 2010, 12:32:26 (14 years ago)
Author:
uli
Message:

Move 'get_access_code' to the accesscodes subpackage.

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

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/__init__.py

    r5068 r5447  
    11# Make this a package.
     2from waeup.sirp.accesscodes.accesscodes import get_access_code
     3
     4# Public API of this submodule
     5__all__ = [
     6    get_access_code
     7    ]
     8
  • main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/accesscodes.py

    r5153 r5447  
    409409                    site, ))
    410410        return
     411
     412def get_access_code(access_code):
     413    """Get an access code instance.
     414
     415    An access code here is a string like ``PUDE-1-1234567890``.
     416   
     417    Returns ``None`` if the given code cannot be found.
     418
     419    This is a convenicence function that is faster than looking up a
     420    batch container for the approriate access code.
     421    """
     422    site = grok.getSite()
     423    if not isinstance(access_code, basestring):
     424        return None
     425    try:
     426        batch_id, ac_id = access_code.rsplit('-', 1)
     427    except:
     428        return None
     429    if batch_id not in site['accesscodes'].keys():
     430        return None
     431    batch = site['accesscodes'][batch_id]
     432    try:
     433        code = batch.getAccessCode(access_code)
     434    except KeyError:
     435        return None
     436    return code
  • main/waeup.sirp/trunk/src/waeup/sirp/jambtables/authentication.py

    r5446 r5447  
    3838    IApplicantPrincipalInfo, IApplicantPrincipal, IApplicantSessionCredentials,
    3939    IJAMBApplicantSessionCredentials)
    40 from waeup.sirp.jambtables.util import get_applicant_data, get_access_code
     40from waeup.sirp.jambtables.util import get_applicant_data
     41from waeup.sirp.accesscodes import get_access_code
    4142
    4243class PortalUser(grok.Role):
  • main/waeup.sirp/trunk/src/waeup/sirp/jambtables/util.py

    r5445 r5447  
    4545    # XXX: Maybe we have to mark reg_no as used here?
    4646    return (applicant_data, entries[0])
    47 
    48 def get_access_code(access_code):
    49     """Get an access code instance.
    50 
    51     Returns ``None`` if the given code cannot be found.
    52 
    53     XXX: This should be moved to `accesscodes` as public API part.
    54     """
    55     site = grok.getSite()
    56     if not isinstance(access_code, basestring):
    57         return None
    58     try:
    59         batch_id, ac_id = access_code.rsplit('-', 1)
    60     except:
    61         return None
    62     if batch_id not in site['accesscodes'].keys():
    63         return None
    64     batch = site['accesscodes'][batch_id]
    65     return batch.getAccessCode(access_code)
Note: See TracChangeset for help on using the changeset viewer.