Ignore:
Timestamp:
21 Mar 2013, 10:57:48 (12 years ago)
Author:
Henrik Bettermann
Message:

Also matric or reg numbers can be used as student identifiers.

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

    r10040 r10041  
    109109        self.assertEqual(result,
    110110            {'100|CRS1': 'Course 1', '100|COURSE1': 'Unnamed Course'})
     111        # Also matric_number ...
     112        result = server.get_courses_by_session('234')
     113        self.assertEqual(result,
     114            {'100|CRS1': 'Course 1', '100|COURSE1': 'Unnamed Course'})
     115        # ... or reg_number can be used.
     116        result = server.get_courses_by_session('123')
     117        self.assertEqual(result,
     118            {'100|CRS1': 'Course 1', '100|COURSE1': 'Unnamed Course'})
     119        result = server.get_courses_by_session('Nonsense')
     120        self.assertEqual(result, None)
    111121        REQUEST_XML="""\
    112122<?xml version="1.0"?>
  • main/waeup.kofa/trunk/src/waeup/kofa/students/webservices.py

    r10040 r10041  
    2222from waeup.kofa.interfaces import IUniversity
    2323
     24def get_student(students, identifier):
     25    if identifier is None:
     26        return None
     27    student = students.get(identifier, None)
     28    if student is None:
     29        cat = queryUtility(ICatalog, name='students_catalog')
     30        results = list(
     31            cat.searchResults(matric_number=(identifier, identifier)))
     32        if len(results) == 1:
     33            student = results[0]
     34        else:
     35            results = list(
     36                cat.searchResults(reg_number=(identifier, identifier)))
     37            if len(results) == 1:
     38                student = results[0]
     39    return student
    2440
    2541#class XMLRPCPermission(grok.Permission):
     
    6177
    6278    @grok.require('waeup.xmlrpc')
    63     def get_courses_by_session(self, student_id=None, session=None):
     79    def get_courses_by_session(self, identifier=None, session=None):
    6480        """What COURSES are registered by student X in session Y?
    6581
    6682        """
    67         if student_id is None:
     83        students = self.context['students']
     84        student = get_student(students, identifier)
     85        if student is None:
    6886            return None
    69         student = self.context['students'].get(student_id, None)
    70         if student is None:
    71             return  None
    7287        try:
    7388            session = int(session)
Note: See TracChangeset for help on using the changeset viewer.