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

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

Add web service method which gets the course tickets registered by a student in a certain session.

  • Property svn:keywords set to Id
File size: 3.0 KB
Line 
1## $Id: webservices.py 10036 2013-03-18 09:51:12Z 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
61
62    @grok.require('waeup.xmlrpc')
63    def get_courses_by_session(self, student_id=None, session=None):
64        """Get the course tickets registered by a student in a certain session.
65
66        """
67        if student_id is None:
68            return None
69        student = self.context['students'].get(student_id, None)
70        if student is None:
71            return  None
72        try:
73            session = int(session)
74        except (TypeError, ValueError):
75            pass
76        sessionsearch = True
77        if session in (None, ''):
78            sessionsearch = False
79        studycourse = student['studycourse']
80        coursetickets = {}
81        for level in studycourse.values():
82            if sessionsearch and level.level_session != session:
83                continue
84            for ct in level.values():
85                coursetickets.update(
86                    {"%s|%s" % (level.level, ct.code): ct.title})
87        if not coursetickets:
88            return None
89        return coursetickets
Note: See TracBrowser for help on using the repository browser.