Index: /main/waeup.kofa/trunk/src/waeup/kofa/students/reports/level_report.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/students/reports/level_report.py	(revision 10552)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/students/reports/level_report.py	(revision 10552)
@@ -0,0 +1,62 @@
+## $Id$
+##
+## Copyright (C) 2012 Uli Fouquet & Henrik Bettermann
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##
+import grok
+from zope.catalog.interfaces import ICatalog
+from zope.component import queryUtility, getUtility
+from zope.interface import implementer, Interface, Attribute
+from waeup.kofa.interfaces import (
+    IKofaUtils,
+    academic_sessions_vocab, registration_states_vocab)
+from waeup.kofa.interfaces import MessageFactory as _
+from waeup.kofa.reports import IReport
+
+class ILevelReport(IReport):
+
+    session = Attribute('Session to report')
+    level = Attribute('Level to report')
+    faculty = Attribute('Faculty to report')
+    department = Attribute('Department to report')
+    creation_dt_string = Attribute('Human readable report creation datetime')
+
+def get_students_by(faccode, depcode, session, level):
+    """Get students in a certain department who registered courses
+    in a certain session at a certain level.
+
+    Returns a list of student data tuples.
+    """
+    site = grok.getSite()
+    faccodes = tuple(sorted([x for x in site['faculties'].keys()],
+                             key=lambda x: x.lower()))
+    cat = queryUtility(ICatalog, name="students_catalog")
+    result = cat.searchResults(
+        depcode = (depcode, depcode), faccode = (faccode, faccode)
+        )
+    table = []
+    for stud in result:
+        if not stud['studycourse'].has_key(str(level)):
+            continue
+        level_obj = stud['studycourse'][str(level)]
+        if level_obj.level_session != session:
+            continue
+        line = (stud.student_id,
+                stud.matric_number,
+                stud.display_fullname,
+                level_obj.total_credits,
+                level_obj.gpa)
+        table.append(line)
+    return table
Index: /main/waeup.kofa/trunk/src/waeup/kofa/students/reports/tests/test_level_report.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/students/reports/tests/test_level_report.py	(revision 10552)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/students/reports/tests/test_level_report.py	(revision 10552)
@@ -0,0 +1,22 @@
+import os
+from zc.async.testing import wait_for_result
+from zope.interface.verify import verifyClass, verifyObject
+from zope.component import getUtility
+from waeup.kofa.interfaces import IJobManager
+from waeup.kofa.students.reports.level_report import (
+    get_students_by)
+from waeup.kofa.students.tests.test_catalog import CatalogTestSetup
+from waeup.kofa.students.tests.test_browser import StudentsFullSetup
+from waeup.kofa.testing import FunctionalLayer
+from waeup.kofa.tests.test_async import FunctionalAsyncTestCase
+
+class LevelReportTests(CatalogTestSetup):
+
+    layer = FunctionalLayer
+
+    def test_get_students_by(self):
+        # we can get a table with one student
+        result = get_students_by('fac1', 'dep1', 2010, 100)
+        self.assertEqual(result,
+            [(u'K1000000', u'1234', u'Bob Tester', 30, 5.0)])
+        return
Index: /main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_catalog.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_catalog.py	(revision 10551)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_catalog.py	(revision 10552)
@@ -67,4 +67,5 @@
         student.firstname = u'Bob'
         student.lastname = u'Tester'
+        student.matric_number = u'1234'
         self.app['students'].addStudent(student)
         self.student_id = student.student_id
@@ -81,4 +82,6 @@
         ticket = CourseTicket()
         ticket.code = 'Course1'
+        ticket.credits = 30
+        ticket.score = 88
         self.student['studycourse']['100']['Course1'] = ticket
         payment = createObject(u'waeup.StudentOnlinePayment')
