Changeset 12609 for main


Ignore:
Timestamp:
13 Feb 2015, 06:31:37 (10 years ago)
Author:
Henrik Bettermann
Message:

Add department mover.

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

Legend:

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

    r12590 r12609  
    2626
    2727class MoveObjectsInFaculties(StudentsFullSetup):
     28
     29    def test_move_department(self):
     30        self.assertEqual(
     31            self.app['faculties']['fac1']['dep1'].certificates['CERT1'],
     32            self.certificate)
     33        department = self.app['faculties']['fac1']['dep1']
     34        faculty = self.app['faculties']['fac1']
     35        department.moveDepartment('fac1', 'newdep')
     36
     37        # New department is created and old department is removed
     38        self.assertEqual(
     39            [key for key in self.app['faculties']['fac1']],
     40            ['newdep'])
     41
     42        # All subobjects have been moved too
     43        self.assertEqual(
     44            self.app['faculties']['fac1']['newdep'].courses['COURSE1'],
     45            self.course)
     46        self.assertEqual(
     47            self.app['faculties']['fac1']['newdep'].certificates['CERT1'],
     48            self.certificate)
     49        self.assertEqual(
     50            [key for key in self.app['faculties']['fac1'][
     51                'newdep'].certificates['CERT1'].keys()],
     52            [u'COURSE1_100'])
     53
     54        # We can still find the certificate in the catalog
     55        cat = queryUtility(ICatalog, name='certificates_catalog')
     56        results = cat.searchResults(code=('CERT1','CERT1'))
     57        results = [x for x in results]
     58        assert len(results) == 1
     59        assert results[0] is self.certificate
     60
     61        # We can still find the course in the catalog
     62        cat = queryUtility(ICatalog, name='courses_catalog')
     63        results = cat.searchResults(code=('COURSE1','COURSE1'))
     64        results = [x for x in results] #
     65        assert len(results) == 1
     66        assert results[0] is self.course
     67        # We can still find the certificatecourse in the catalog
     68        cat = queryUtility(ICatalog, name='certcourses_catalog')
     69        results = cat.searchResults(course_code=('COURSE1','COURSE1'))
     70        results = [x for x in results]
     71        assert len(results) == 1
     72        assert results[0] is self.app['faculties']['fac1'][
     73            'newdep'].certificates['CERT1']['COURSE1_100']
     74
     75        # We can find the student studying in the new department
     76        cat = queryUtility(ICatalog, name='students_catalog')
     77        results = cat.searchResults(depcode=('newdep','newdep'))
     78        results = [x for x in results] # Turn results generator into list
     79        assert len(results) == 1
     80        assert results[0] is self.app['students'][self.student_id]
     81        logfile = os.path.join(
     82            self.app['datacenter'].storage, 'logs', 'students.log')
     83        logcontent = open(logfile).read()
     84        self.assertTrue('INFO - system - K1000000 - Department moved'
     85            in logcontent)
     86
    2887
    2988    def test_move_certificate(self):
     
    70129        self.assertTrue('INFO - system - K1000000 - Certificate moved'
    71130            in logcontent)
    72 
  • main/waeup.kofa/trunk/src/waeup/kofa/university/department.py

    r11891 r12609  
    2020import grok
    2121import zope.location.location
     22from zope.event import notify
     23from zope.catalog.interfaces import ICatalog
    2224from zope.component.interfaces import IFactory
    2325from zope.interface import implementedBy
     
    9496        return longtitle(self)
    9597
     98    def moveDepartment(self, facname, depname):
     99        """ Move department to new department named depname in
     100        faculty named facname.
     101
     102        """
     103        self.moved = True
     104        fac = grok.getSite()['faculties'][facname]
     105        oldcode = self.code
     106        fac[depname] = self
     107        del self.__parent__[oldcode]
     108        fac[depname].code = depname
     109        #self.__parent__._p_changed = True
     110        cat = getUtility(ICatalog, name='students_catalog')
     111        results = cat.searchResults(depcode=(oldcode, oldcode))
     112        for student in results:
     113            notify(grok.ObjectModifiedEvent(student))
     114            student.__parent__.logger.info(
     115                '%s - Department moved' % student.__name__)
     116        return
     117
    96118class DepartmentFactory(grok.GlobalUtility):
    97119    """A factory for department containers.
Note: See TracChangeset for help on using the changeset viewer.