Changeset 12610 for main


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

Add utility view to move department via UI.

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

    r12609 r12610  
    3333        department = self.app['faculties']['fac1']['dep1']
    3434        faculty = self.app['faculties']['fac1']
    35         department.moveDepartment('fac1', 'newdep')
     35
     36        # We move the depart using the UtilityView
     37        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     38        self.browser.open('http://localhost/app/faculties/fac1/dep1/move_department?fac=fac1&dep=newdep')
    3639
    3740        # New department is created and old department is removed
    3841        self.assertEqual(
    39             [key for key in self.app['faculties']['fac1']],
    40             ['newdep'])
     42            [key for key in self.app['faculties']['fac1']], ['newdep'])
    4143
    4244        # All subobjects have been moved too
     
    7981        assert len(results) == 1
    8082        assert results[0] is self.app['students'][self.student_id]
     83
     84        # Messages are found in two log files
    8185        logfile = os.path.join(
    8286            self.app['datacenter'].storage, 'logs', 'students.log')
    8387        logcontent = open(logfile).read()
    84         self.assertTrue('INFO - system - K1000000 - Department moved'
     88        self.assertTrue('INFO - zope.mgr - K1000000 - Department moved'
     89            in logcontent)
     90        logfile = os.path.join(
     91            self.app['datacenter'].storage, 'logs', 'main.log')
     92        logcontent = open(logfile).read()
     93        self.assertTrue('INFO - zope.mgr - Department dep1 moved to fac1/newdep'
    8594            in logcontent)
    8695
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/browser.py

    r9127 r12610  
    2424from waeup.kofa.browser.layout import UtilityView
    2525from waeup.kofa.interfaces import IObjectHistory
    26 
    2726from waeup.kofa.interfaces import IUniversity
     27from waeup.kofa.university.interfaces import IDepartment
    2828
    2929def replaceStudentMessages(old, new):
     
    199199        self.redirect(self.url(self.context, '@@index'))
    200200        return
     201
     202
     203class MoveDepartment(UtilityView, grok.View):
     204    """ View to move a department.
     205
     206    """
     207    grok.context(IDepartment)
     208    grok.name('move_department')
     209    grok.require('waeup.managePortal')
     210
     211    def update(self,fac=None, dep=None):
     212        if None in (fac, dep):
     213            self.flash('Syntax: /move_department?fac=[new faculty code]&dep=[new department code]')
     214            return
     215        oldcode = self.context.code
     216        try:
     217            self.context.moveDepartment(fac, dep)
     218        except:
     219            self.flash('Error')
     220            return
     221        grok.getSite().logger.info(
     222            "Department %s moved to %s/%s" % (oldcode, fac, dep))
     223        self.flash('Finished')
     224        return
     225
     226    def render(self):
     227        self.redirect(self.url(self.context, '@@index'))
     228        return
Note: See TracChangeset for help on using the changeset viewer.