Ignore:
Timestamp:
21 Sep 2013, 09:12:09 (11 years ago)
Author:
Henrik Bettermann
Message:

Using attrs_to_fields, which we didn't use in the beginning, makes a lot of problems. Many tests have to be changed and also the batch processor has to be adjusted. Thus it seems to be easier to use to update all department objects with the KofaPluggable? utility.

File:
1 edited

Legend:

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

    r10634 r10635  
    2323from zope.interface import implementedBy
    2424from zope.component import getUtility
     25from zope.schema import getFields
    2526from waeup.kofa.university.faculty import longtitle
    2627from waeup.kofa.university.coursescontainer import CoursesContainer
    2728from waeup.kofa.university.certificatescontainer import CertificatesContainer
    2829from waeup.kofa.utils.batching import VirtualExportJobContainer
    29 from waeup.kofa.interfaces import IKofaUtils
     30from waeup.kofa.interfaces import IKofaUtils, IKofaPluggable
    3031from waeup.kofa.utils.helpers import attrs_to_fields
    3132from waeup.kofa.university.interfaces import IDepartment, IDepartmentAdd
     
    7172        self.certificates.__parent__ = self
    7273        self.certificates.__name__ = 'certificates'
     74        self.score_editing_disabled = False
    7375
    7476    def traverse(self, name):
     
    9092        return longtitle(self)
    9193
    92 # Set all attributes of Department required in IDepartment as field
    93 # properties. Doing this, we do not have to set initial attributes
    94 # ourselves and as a bonus we get free validation when an attribute is
    95 # set.
    96 Department = attrs_to_fields(Department)
    97 
    9894class DepartmentFactory(grok.GlobalUtility):
    9995    """A factory for department containers.
     
    111107        """
    112108        return implementedBy(Department)
     109
     110class DepartmentsPlugin(grok.GlobalUtility):
     111    """A plugin that updates courses.
     112    """
     113
     114    grok.implements(IKofaPluggable)
     115    grok.name('departments')
     116
     117    deprecated_attributes = []
     118
     119    def setup(self, site, name, logger):
     120        return
     121
     122    def update(self, site, name, logger):
     123        items = getFields(IDepartment).items()
     124        for faculty in site['faculties'].values():
     125            for department in faculty.values():
     126                # Add new attributes
     127                for i in items:
     128                    if not hasattr(department,i[0]):
     129                        setattr(department,i[0],i[1].missing_value)
     130                        logger.info(
     131                            'DepartmentsPlugin: %s attribute %s added.' % (
     132                            department.code,i[0]))
     133                # Remove deprecated attributes
     134                for i in self.deprecated_attributes:
     135                    try:
     136                        delattr(department,i)
     137                        logger.info(
     138                            'DepartmentsPlugin: %s attribute %s deleted.' % (
     139                            department.code,i))
     140                    except AttributeError:
     141                        pass
     142        return
Note: See TracChangeset for help on using the changeset viewer.