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 | |
---|
26 | def 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]) |
---|