Ignore:
Timestamp:
16 Aug 2010, 11:15:35 (14 years ago)
Author:
uli
Message:

Add helper to find an accesscode entry.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/jambtables/util.py

    r5443 r5445  
    4545    # XXX: Maybe we have to mark reg_no as used here?
    4646    return (applicant_data, entries[0])
     47
     48def 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.