source: main/waeup.kofa/trunk/src/waeup/kofa/students/webservices.py @ 10035

Last change on this file since 10035 was 10033, checked in by Henrik Bettermann, 12 years ago

Add module for student related XMLRPC web services and move get_student_id method.

  • Property svn:keywords set to Id
File size: 2.0 KB
Line 
1## $Id: webservices.py 10033 2013-03-17 14:45:18Z henrik $
2##
3## Copyright (C) 2012 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18
19import grok
20from zope.component import getUtility
21from zope.catalog.interfaces import ICatalog
22from waeup.kofa.interfaces import IUniversity
23
24
25#class XMLRPCPermission(grok.Permission):
26#    """Permission for using XMLRPC functions.
27#    """
28#    grok.name('waeup.xmlrpc')
29
30#class XMLRPCUsers2(grok.Role):
31#    """Usergroup 2
32#    """
33#    grok.name('waeup.xmlrpcusers2')
34#    grok.title('XMLRPC Users Group 2')
35#    grok.permissions('waeup.xmlrpc',)
36
37class StudentsXMLRPC(grok.XMLRPC):
38    """Student related XMLRPC webservices.
39
40    Please note, that XMLRPC does not support real keyword arguments
41    but positional arguments only.
42    """
43
44    grok.context(IUniversity)
45
46    @grok.require('waeup.xmlrpc')
47    def get_student_id(self, reg_number=None):
48        """Get the id of a student with registration number `reg_number`.
49
50        Returns the student id as string if successful, ``None`` else.
51        """
52        if reg_number is not None:
53            cat = getUtility(ICatalog, name='students_catalog')
54            result = list(
55                cat.searchResults(reg_number=(reg_number, reg_number),
56                                  _limit=1))
57            if not len(result):
58                return None
59            return result[0].student_id
60        return None
Note: See TracBrowser for help on using the repository browser.