Ignore:
Timestamp:
16 Feb 2015, 11:27:24 (10 years ago)
Author:
Henrik Bettermann
Message:

Improve department and certificate movers. Add utility view for moving certificates.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/university
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/university/certificate.py

    r10685 r12620  
    120120        return
    121121
    122     def moveCertificate(self, fac, dep):
     122    def moveCertificate(self, facname, depname, newcode):
    123123        self.moved = True
    124124        cert = self
    125         del self.__parent__[cert.code]
    126         grok.getSite()['faculties'][fac][dep].certificates[cert.code] = cert
    127         self.__parent__._p_changed = True
     125        oldcode = cert.code
     126        cert.code = newcode
     127        del self.__parent__[oldcode]
     128        newdep = grok.getSite()['faculties'][facname][depname]
     129        newdep.certificates[newcode] = cert
     130        #self.__parent__._p_changed = True
    128131        cat = getUtility(ICatalog, name='students_catalog')
    129         results = cat.searchResults(certcode=(cert.code, cert.code))
     132        results = cat.searchResults(certcode=(oldcode, oldcode))
    130133        for student in results:
    131134            notify(grok.ObjectModifiedEvent(student))
    132135            student.__parent__.logger.info(
    133136                '%s - Certificate moved' % student.__name__)
    134 
    135137        return
    136138
  • main/waeup.kofa/trunk/src/waeup/kofa/university/department.py

    r12609 r12620  
    102102        """
    103103        self.moved = True
    104         fac = grok.getSite()['faculties'][facname]
     104        newfac = grok.getSite()['faculties'][facname]
    105105        oldcode = self.code
    106         fac[depname] = self
    107         del self.__parent__[oldcode]
    108         fac[depname].code = depname
     106        oldfac = self.__parent__
     107        newfac[depname] = self
     108        del oldfac[oldcode]
     109        newfac[depname].code = depname
    109110        #self.__parent__._p_changed = True
    110111        cat = getUtility(ICatalog, name='students_catalog')
  • main/waeup.kofa/trunk/src/waeup/kofa/university/tests/test_move.py

    r12614 r12620  
    2222from zope.catalog.interfaces import ICatalog
    2323from zope.component import queryUtility
     24from waeup.kofa.university.faculty import Faculty
    2425from waeup.kofa.university.department import Department
    2526from waeup.kofa.students.tests.test_browser import StudentsFullSetup
     
    2829
    2930    def test_move_department(self):
     31        self.app['faculties']['fac2'] = Faculty(code=u'fac2')
    3032        self.assertEqual(
    3133            self.app['faculties']['fac1']['dep1'].certificates['CERT1'],
     
    3638        # We move the depart using the UtilityView
    3739        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    38         self.browser.open('http://localhost/app/faculties/fac1/dep1/move_department?fac=fac1&dep=newdep')
     40        self.browser.open('http://localhost/app/faculties/fac1/dep1/move_department?fac=fac2&dep=newdep')
    3941
    4042        # New department is created and old department is removed
    4143        self.assertEqual(
    42             [key for key in self.app['faculties']['fac1']], ['newdep'])
     44            [key for key in self.app['faculties']['fac2']], ['newdep'])
    4345
    4446        # All subobjects have been moved too
    4547        self.assertEqual(
    46             self.app['faculties']['fac1']['newdep'].courses['COURSE1'],
     48            self.app['faculties']['fac2']['newdep'].courses['COURSE1'],
    4749            self.course)
    4850        self.assertEqual(
    49             self.app['faculties']['fac1']['newdep'].certificates['CERT1'],
     51            self.app['faculties']['fac2']['newdep'].certificates['CERT1'],
    5052            self.certificate)
    5153        self.assertEqual(
    52             [key for key in self.app['faculties']['fac1'][
     54            [key for key in self.app['faculties']['fac2'][
    5355                'newdep'].certificates['CERT1'].keys()],
    5456            [u'COURSE1_100'])
     
    6769        assert len(results) == 1
    6870        assert results[0] is self.course
     71
    6972        # We can still find the certificatecourse in the catalog
    7073        cat = queryUtility(ICatalog, name='certcourses_catalog')
     
    7275        results = [x for x in results]
    7376        assert len(results) == 1
    74         assert results[0] is self.app['faculties']['fac1'][
     77        assert results[0] is self.app['faculties']['fac2'][
    7578            'newdep'].certificates['CERT1']['COURSE1_100']
    7679
     
    9194            self.app['datacenter'].storage, 'logs', 'main.log')
    9295        logcontent = open(logfile).read()
    93         self.assertTrue('INFO - zope.mgr - Department dep1 moved to fac1/newdep'
     96        self.assertTrue('INFO - zope.mgr - Department dep1 moved to fac2/newdep'
    9497            in logcontent)
    9598
    9699
    97100    def test_move_certificate(self):
     101        self.app['faculties']['fac2'] = Faculty(code=u'fac2')
     102        self.app['faculties']['fac2']['dep2'] = Department(code=u'dep2')
    98103        self.assertEqual(
    99104            self.app['faculties']['fac1']['dep1'].certificates['CERT1'],
    100105            self.certificate)
    101         self.app['faculties']['fac1']['dep2'] = Department(code=u'dep2')
    102         self.certificate.moveCertificate('fac1', 'dep2')
     106
     107        #self.certificate.moveCertificate('fac2', 'dep2', 'NEWCODE')
     108
     109        # We move the depart using the UtilityView
     110        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     111        self.browser.open('http://localhost/app/faculties/fac1/dep1/certificates/CERT1/move_certificate?fac=fac2&dep=dep2&cert=NEWCODE')
     112
    103113        self.assertEqual(
    104             self.app['faculties']['fac1']['dep2'].certificates['CERT1'],
     114            self.app['faculties']['fac2']['dep2'].certificates['NEWCODE'],
    105115            self.certificate)
    106116        self.assertEqual(
    107             [key for key in self.app['faculties']['fac1'][
    108                 'dep2'].certificates['CERT1'].keys()],
    109             [u'COURSE1_100'])
     117            [key for key in self.app['faculties']['fac2'][
     118                'dep2'].certificates['NEWCODE'].keys()], [u'COURSE1_100'])
    110119        self.assertEqual(
    111120            self.student['studycourse'].certificate,
    112121            self.certificate)
    113122
    114         # We can still find the certificate in the catalog
     123        # We can find the moved certificate in the catalog
    115124        cat = queryUtility(ICatalog, name='certificates_catalog')
    116         results = cat.searchResults(code=('CERT1','CERT1'))
     125        results = cat.searchResults(code=('NEWCODE','NEWCODE'))
    117126        results = [x for x in results] # Turn results generator into list
    118127        assert len(results) == 1
     
    124133        results = [x for x in results] # Turn results generator into list
    125134        assert len(results) == 1
    126         assert results[0] is self.app['faculties']['fac1'][
    127                 'dep2'].certificates['CERT1']['COURSE1_100']
     135        assert results[0] is self.app['faculties']['fac2'][
     136                'dep2'].certificates['NEWCODE']['COURSE1_100']
    128137
    129138        # We can find the student studying in the new department
     
    133142        assert len(results) == 1
    134143        assert results[0] is self.app['students'][self.student_id]
     144
     145        # We can find the student studying the new course ...
     146        cat = queryUtility(ICatalog, name='students_catalog')
     147        results = cat.searchResults(certcode=('NEWCODE','NEWCODE'))
     148        results = [x for x in results] # Turn results generator into list
     149        assert len(results) == 1
     150        assert results[0] is self.app['students'][self.student_id]
     151        # ... but not the old course
     152        results = cat.searchResults(certcode=('CERT1','CERT1'))
     153        assert len(results) == 0
     154
    135155        logfile = os.path.join(
    136156            self.app['datacenter'].storage, 'logs', 'students.log')
    137157        logcontent = open(logfile).read()
    138         self.assertTrue('INFO - system - K1000000 - Certificate moved'
     158        self.assertTrue('INFO - zope.mgr - K1000000 - Certificate moved'
    139159            in logcontent)
     160        logfile = os.path.join(
     161            self.app['datacenter'].storage, 'logs', 'main.log')
     162        logcontent = open(logfile).read()
     163        self.assertTrue('INFO - zope.mgr - Certificate CERT1 moved to fac2/dep2/NEWCODE'
     164            in logcontent)
Note: See TracChangeset for help on using the changeset viewer.