Index: main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_webservices.py
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_webservices.py	(revision 16391)
+++ main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_webservices.py	(revision 16392)
@@ -5,5 +5,5 @@
 from cStringIO import StringIO
 from zope.app.testing.xmlrpc import ServerProxy
-from zope.component import getUtility
+from zope.component import getUtility, createObject
 from waeup.kofa.interfaces import (
     IExtFileStore, IFileStoreNameChooser, IKofaUtils)
@@ -16,5 +16,4 @@
 
 class XMLRPCTests(StudentsFullSetup):
-    # check XMLRPC services for university portal
 
     layer = FunctionalLayer
@@ -34,6 +33,6 @@
         ticket.code = u'CRS1'
         ticket.title = u'Course 1'
-        ticket.fcode = u'FAC1'
-        ticket.dcode = u'DEP1'
+        ticket.fcode = u'fac1'
+        ticket.dcode = u'dep1'
         ticket.credits = 100
         ticket.passmark = 100
@@ -224,10 +223,26 @@
 
     def test_get_students_by_department(self):
-        self.setup_student(self.student)
-        server = ServerProxy('http://mgr:mgrpw@localhost/app')
-        result = server.get_students_by_department('fac1','dep1', '2012')
-        self.assertEqual(result, [['COURSE1', 100, 2012, 'K1000000', '234', 'Anna Tester']])
+        self.course2 = createObject('waeup.Course')
+        self.course2.code = 'COURSE2'
+        self.app['faculties']['fac1']['dep1'].courses.addCourse(
+            self.course2)
+        self.setup_student(self.student)
+        ticket = CourseTicket()
+        ticket.code = u'COURSE2'
+        ticket.title = u'Course 2'
+        ticket.fcode = u'fac1'
+        ticket.dcode = u'fac1'
+        self.student['studycourse']['100'][ticket.code] = ticket
+        server = ServerProxy('http://mgr:mgrpw@localhost/app')
+        result = server.get_students_by_department('fac1','dep1', '2011')
+        self.assertEqual(result, {})
+        result = server.get_students_by_department('fac1','dep1', '2012', '200')
+        self.assertEqual(result, {})
+        result = server.get_students_by_department('fac1','dep1', '2012', '100')
+        self.assertEqual(
+            result, {'K1000000': ['234', 'Anna Tester', ['COURSE1', 'COURSE2']]})
         result = server.get_students_by_department('fac1','dep1')
-        self.assertEqual(result, [['COURSE1', 100, 2012, 'K1000000', '234', 'Anna Tester']])
+        self.assertEqual(
+            result, {'K1000000': ['234', 'Anna Tester', ['COURSE1', 'COURSE2']]})
         result = server.get_students_by_department('fac1','dep2')
         self.assertEqual(result, None)
@@ -248,14 +263,17 @@
 <params>
 <param>
+<value><struct>
+<member>
+<name>K1000000</name>
 <value><array><data>
+<value><string>234</string></value>
+<value><string>Anna Tester</string></value>
 <value><array><data>
 <value><string>COURSE1</string></value>
-<value><int>100</int></value>
-<value><int>2012</int></value>
-<value><string>K1000000</string></value>
-<value><string>234</string></value>
-<value><string>Anna Tester</string></value>
+<value><string>COURSE2</string></value>
 </data></array></value>
 </data></array></value>
+</member>
+</struct></value>
 </param>
 </params>
Index: main/waeup.kofa/trunk/src/waeup/kofa/students/webservices.py
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/students/webservices.py	(revision 16391)
+++ main/waeup.kofa/trunk/src/waeup/kofa/students/webservices.py	(revision 16392)
@@ -155,14 +155,18 @@
 
     @grok.require('waeup.xmlrpc')
-    def get_students_by_department(self, faccode=None, depcode=None, session=None):
-        """A webservice to pull student's registered courses in a department.
+    def get_students_by_department(self, faccode=None, depcode=None,
+                                   session=None, level=None):
+        """A webservice to pull student's registered courses in a
+        department
         """
         try:
             session = int(session)
+            level = int(level)
         except (TypeError, ValueError):
             pass
-        sessionsearch = True
         if session in (None, ''):
-            sessionsearch = False
+            session= None
+        if level in (None, ''):
+            level= None
         try:
             department =self.context['faculties'][faccode][depcode]
@@ -171,23 +175,20 @@
         courses = department.courses.keys()
         cat = queryUtility(ICatalog, name='coursetickets_catalog')
-        hitlist = []
+        hitdict = {}
         for course in courses:
-            if sessionsearch:
-                coursetickets = cat.searchResults(
-                    session=(session, session),
-                    code=(course, course))
-            else:
-                coursetickets = cat.searchResults(
-                    code=(course, course))
+            coursetickets = cat.searchResults(
+                session=(session, session),
+                level=(level, level),
+                code=(course, course))
             for c_ticket in coursetickets:
-                hitlist.append((
-                    c_ticket.code,
-                    c_ticket.level,
-                    c_ticket.level_session,
-                    c_ticket.student.student_id,
-                    c_ticket.student.matric_number,
-                    c_ticket.student.display_fullname,
-                    ))
-        return list(set(hitlist))
+                if not c_ticket.student.student_id in hitdict.keys():
+                    hitdict[c_ticket.student.student_id] = (
+                        c_ticket.student.matric_number,
+                        c_ticket.student.display_fullname,
+                        [c_ticket.code,])
+                else:
+                    hitdict[c_ticket.student.student_id][2].append(
+                        c_ticket.code,)
+        return hitdict
 
     @grok.require('waeup.xmlrpc')
