Ignore:
Timestamp:
25 Nov 2011, 20:54:14 (13 years ago)
Author:
Henrik Bettermann
Message:

Add indexes faccode, depcode and certcode to students_catalog.

Location:
main/waeup.sirp/trunk/src/waeup/sirp/students
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/students/catalog.py

    r7191 r7203  
    3939    matric_number = index.Field(attribute='matric_number')
    4040    state = index.Field(attribute='state')
    41     certificate = index.Field(attribute='certificate')
     41    certcode = index.Field(attribute='certcode')
     42    depcode = index.Field(attribute='depcode')
     43    faccode = index.Field(attribute='faccode')
    4244    current_session = index.Field(attribute='current_session')
    4345
  • main/waeup.sirp/trunk/src/waeup/sirp/students/interfaces.py

    r7191 r7203  
    123123    state = Attribute('Returns the registration state of a student')
    124124    password = Attribute('Encrypted password of a student')
    125     certificate = Attribute('The certificate of any chosen study course')
     125    certcode = Attribute('The certificate code of any chosen study course')
     126    depcode = Attribute('The department code of any chosen study course')
     127    faccode = Attribute('The faculty code of any chosen study course')
    126128    current_session = Attribute('The current session of the student')
    127129
  • main/waeup.sirp/trunk/src/waeup/sirp/students/student.py

    r7191 r7203  
    7676
    7777    @property
    78     def certificate(self):
     78    def certcode(self):
    7979        cert = getattr(self.get('studycourse', None), 'certificate', None)
    80         return cert
     80        if cert is not None:
     81            return cert.code
     82        return
     83
     84    @property
     85    def faccode(self):
     86        cert = getattr(self.get('studycourse', None), 'certificate', None)
     87        if cert is not None:
     88            return cert.__parent__.__parent__.__parent__.code
     89        return
     90
     91    @property
     92    def depcode(self):
     93        cert = getattr(self.get('studycourse', None), 'certificate', None)
     94        if cert is not None:
     95            return cert.__parent__.__parent__.code
     96        return
    8197
    8298    @property
  • main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py

    r7201 r7203  
    257257                           self.browser.contents)
    258258
     259        # We can find a student with a certain student_id
    259260        self.browser.open(self.container_path)
    260261        self.browser.getControl("Search").click()
     
    265266        self.assertTrue('Anna Tester' in self.browser.contents)
    266267
     268        # We can find a student with a certain fullname
    267269        self.browser.open(self.manage_container_path)
    268270        self.browser.getControl("Search").click()
  • main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_catalog.py

    r7193 r7203  
    1616## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    1717##
     18import grok
    1819import shutil
    1920import tempfile
     21from zope.event import notify
    2022from zope.catalog.interfaces import ICatalog
    21 from zope.component import queryUtility
     23from zope.component import queryUtility, createObject
    2224from zope.component.hooks import setSite
    2325from waeup.sirp.app import University
    2426from waeup.sirp.testing import FunctionalLayer, FunctionalTestCase
    2527from waeup.sirp.students.student import Student
     28from waeup.sirp.university.faculty import Faculty
     29from waeup.sirp.university.department import Department
    2630
    2731class CatalogTestSetup(FunctionalTestCase):
     
    4347        self.app = self.getRootFolder()['app']
    4448        setSite(self.app)
     49        self.certificate = createObject('waeup.Certificate')
     50        self.certificate.code = u'CERT1'
     51        self.app['faculties']['fac1'] = Faculty(code=u'fac1')
     52        self.app['faculties']['fac1']['dep1'] = Department(code=u'dep1')
     53        self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
     54            self.certificate)
    4555
    46         # Create students
     56        # Create student with studycourse subobject
    4757        student = Student()
    4858        student.fullname = u'Bob Tester'
    49         student.student_id = u'A123456'
    50         self.app['students'][student.student_id] = student
     59        self.app['students'].addStudent(student)
     60        self.student_id = student.student_id
     61        self.student = self.app['students'][self.student_id]
     62        self.student['studycourse'].certificate = self.certificate
     63        # Update the catalog
     64        notify(grok.ObjectModifiedEvent(self.student))
    5165        return
    5266
     
    6882        # We can find a certain student id
    6983        cat = queryUtility(ICatalog, name='students_catalog')
    70         results = cat.searchResults(student_id=('A123456', 'A123456'))
     84        results = cat.searchResults(student_id=(self.student_id, self.student_id))
    7185        results = [x for x in results] # Turn results generator into list
    7286        assert len(results) == 1
    73         assert results[0] is self.app['students']['A123456']
     87        assert results[0] is self.app['students'][self.student_id]
    7488
    7589    def test_search_by_name(self):
     
    7993        results = [x for x in results] # Turn results generator into list
    8094        assert len(results) == 1
    81         assert results[0] is self.app['students']['A123456']
     95        assert results[0] is self.app['students'][self.student_id]
     96
     97    def test_search_by_department(self):
     98        # We can find a student studying in a certain department
     99        cat = queryUtility(ICatalog, name='students_catalog')
     100        results = cat.searchResults(depcode=('dep1','dep1'))
     101        results = [x for x in results] # Turn results generator into list
     102        assert len(results) == 1
     103        assert results[0] is self.app['students'][self.student_id]
     104
     105    def test_search_by_faculty(self):
     106        # We can find a student studying in a certain faculty
     107        cat = queryUtility(ICatalog, name='students_catalog')
     108        results = cat.searchResults(faccode=('fac1','fac1'))
     109        results = [x for x in results] # Turn results generator into list
     110        assert len(results) == 1
     111        assert results[0] is self.app['students'][self.student_id]
Note: See TracChangeset for help on using the changeset viewer.