Ignore:
Timestamp:
18 Mar 2013, 10:56:41 (12 years ago)
Author:
Henrik Bettermann
Message:

Add web service method which gets the ids and matric numbers of students registered for a certain course in a certain session.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/students
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_webservices.py

    r10037 r10038  
    2020        study_level.level_verdict = "A"
    2121        study_level.level = 100
     22        study_level.validated_by = u"my adviser"
    2223        student['studycourse'].addStudentStudyLevel(
    2324            self.certificate, study_level)
     
    146147        self.assertEqual(self.browser.contents, RESPONSE_XML)
    147148        return
     149
     150    def test_get_students_by_course(self):
     151        self.setup_student(self.student)
     152        server = ServerProxy('http://mgr:mgrpw@localhost/app')
     153        result = server.get_students_by_course('CRS1', '2010')
     154        self.assertEqual(result, None)
     155        result = server.get_students_by_course('CRS1', '2012')
     156        self.assertEqual(result, ['K1000000|234|my adviser'])
     157        result = server.get_students_by_course('CRS1')
     158        self.assertEqual(result, ['K1000000|234|my adviser'])
     159        return
  • main/waeup.kofa/trunk/src/waeup/kofa/students/webservices.py

    r10036 r10038  
    1818
    1919import grok
    20 from zope.component import getUtility
     20from zope.component import getUtility, queryUtility
    2121from zope.catalog.interfaces import ICatalog
    2222from waeup.kofa.interfaces import IUniversity
     
    6262    @grok.require('waeup.xmlrpc')
    6363    def get_courses_by_session(self, student_id=None, session=None):
    64         """Get the course tickets registered by a student in a certain session.
     64        """What COURSES are registered by student X in session Y?
    6565
    6666        """
     
    8888            return None
    8989        return coursetickets
     90
     91    @grok.require('waeup.xmlrpc')
     92    def get_students_by_course(self, course=None, session=None):
     93        """What STUDENTS registered (student id / matric no)
     94        for course Z in session Y?
     95
     96        (a) Authorized by course adviser.
     97        (b) Not authorized by course adviser.
     98        """
     99        try:
     100            session = int(session)
     101        except (TypeError, ValueError):
     102            pass
     103        sessionsearch = True
     104        if session in (None, ''):
     105            sessionsearch = False
     106        cat = queryUtility(ICatalog, name='coursetickets_catalog')
     107        if sessionsearch:
     108            coursetickets = cat.searchResults(
     109                session=(session, session),
     110                code=(course, course))
     111        else:
     112            coursetickets = cat.searchResults(
     113                code=(course, course))
     114        if not coursetickets:
     115            return None
     116        hitlist = []
     117        for ticket in coursetickets:
     118            hitlist.append('%s|%s|%s' % (
     119                ticket.student.student_id,
     120                ticket.student.matric_number,
     121                ticket.__parent__.validated_by))
     122        return list(set(hitlist))
Note: See TracChangeset for help on using the changeset viewer.