source: main/waeup.sirp/trunk/src/waeup/sirp/jambtables/util.py @ 5451

Last change on this file since 5451 was 5451, checked in by uli, 14 years ago

Rename argument and explain better, what's going on here.

File size: 2.2 KB
Line 
1##
2## util.py
3## Login : <uli@pu.smp.net>
4## Started on  Thu Jul 29 09:39:51 2010 Uli Fouquet
5## $Id$
6##
7## Copyright (C) 2010 Uli Fouquet
8## This program is free software; you can redistribute it and/or modify
9## it under the terms of the GNU General Public License as published by
10## the Free Software Foundation; either version 2 of the License, or
11## (at your option) any later version.
12##
13## This program is distributed in the hope that it will be useful,
14## but WITHOUT ANY WARRANTY; without even the implied warranty of
15## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16## GNU General Public License for more details.
17##
18## You should have received a copy of the GNU General Public License
19## along with this program; if not, write to the Free Software
20## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21##
22"""Little helpers for applicant specific stuff.
23"""
24import grok
25
26def get_applicant_data(reg_no, ac):
27    """Validate credentials and return applicant data.
28   
29    Returns tuple ``(<APPLICANT_ENTRY>, <ACCESSCODE>) on
30    successful validation and ``None`` else.
31
32    We expect a JAMB registration number and an access code in format
33    like ``PREFIX-XXX-YYYYYYYY`` where ``PREFIX`` is something like
34    ``APP`` or ``PUDE``, ``XXX`` the access code series and
35    ``YYYYYYYYYY`` the real accesscode number.
36    """
37    site = grok.getSite()
38    if reg_no not in site['applications'].keys():
39        return None
40    applicant_data = site['applications'][reg_no]
41    entries = site['accesscodes'].search(ac, 'pin')
42    if len(entries) != 1:
43        # XXX: If entries > 1 then we have a problem!
44        return None
45    # XXX: Maybe we have to mark reg_no as used here?
46    return (applicant_data, entries[0])
47
48def application_exists(identifier):
49    """Check whether an application for the given identifier already
50       exists.
51
52       `identifier` can be an access code or a JAMB registration
53       number. For JAMB screened applicants we use the JAMB
54       registration number as key, for other applicants we use the
55       access code.
56    """
57    site = grok.getSite()
58    if identifier in site['applications'].keys():
59        return True
60    return False
Note: See TracBrowser for help on using the repository browser.