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 | """ |
---|
24 | import grok |
---|
25 | from waeup.sirp.accesscodes import get_access_code |
---|
26 | |
---|
27 | def get_applicant_data(reg_no, ac): |
---|
28 | """Validate credentials and return applicant data. |
---|
29 | |
---|
30 | Returns tuple ``(<APPLICANT_ENTRY>, <ACCESSCODE>) on |
---|
31 | successful validation and ``None`` else. |
---|
32 | |
---|
33 | We expect a JAMB registration number and an access code in format |
---|
34 | like ``PREFIX-XXX-YYYYYYYY`` where ``PREFIX`` is something like |
---|
35 | ``APP`` or ``PUDE``, ``XXX`` the access code series and |
---|
36 | ``YYYYYYYYYY`` the real accesscode number. |
---|
37 | """ |
---|
38 | site = grok.getSite() |
---|
39 | if reg_no is not None: |
---|
40 | applicant_data = site['applications'].get(reg_no, None) |
---|
41 | else: |
---|
42 | # Non-JAMB-screened applicants are stored by ac as key... |
---|
43 | applicant_data = site['applications'].get(ac, None) |
---|
44 | access_code = get_access_code(ac) |
---|
45 | return (applicant_data, access_code) |
---|
46 | |
---|
47 | def application_exists(identifier): |
---|
48 | """Check whether an application for the given identifier already |
---|
49 | exists. |
---|
50 | |
---|
51 | `identifier` can be an access code or a JAMB registration |
---|
52 | number. For JAMB screened applicants we use the JAMB |
---|
53 | registration number as key, for other applicants we use the |
---|
54 | access code. |
---|
55 | """ |
---|
56 | site = grok.getSite() |
---|
57 | if identifier in site['applications'].keys(): |
---|
58 | return True |
---|
59 | return False |
---|