Ignore:
Timestamp:
28 Oct 2019, 22:37:30 (5 years ago)
Author:
Henrik Bettermann
Message:

Add bed_id to BedIndexes? catalog. Plugins must be updated.

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

Legend:

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

    r15422 r15708  
    8888        """
    8989        for name in ['faculties', 'departments', 'certificates',
    90                      'certcourses', 'courses',
     90                     'certcourses', 'courses', 'hostels',
    9191                     'site-pluggable-auth']:
    9292            getUtility(IKofaPluggable, name=name).update(
  • main/waeup.kofa/trunk/src/waeup/kofa/hostels/catalog.py

    r13316 r15708  
    3232    bed_type = index.Field(attribute='bed_type')
    3333    owner = index.Field(attribute='owner')
     34    bed_id = index.Field(attribute='bed_id')
  • main/waeup.kofa/trunk/src/waeup/kofa/hostels/hostel.py

    r15633 r15708  
    2222from zope.event import notify
    2323from zope.component import getUtility, createObject
    24 from zope.component.interfaces import IFactory
     24from zope.component.interfaces import IFactory, ComponentLookupError
     25from zope.catalog.interfaces import ICatalog
     26from zope.catalog.field import FieldIndex
    2527from datetime import datetime
    2628from waeup.kofa.utils.helpers import attrs_to_fields
     
    2830from waeup.kofa.hostels.interfaces import IHostel, IBed
    2931from waeup.kofa.students.interfaces import IBedTicket
    30 from waeup.kofa.interfaces import IKofaUtils
     32from waeup.kofa.interfaces import IKofaUtils, IKofaPluggable
    3133from waeup.kofa.interfaces import MessageFactory as _
    3234from waeup.kofa.utils.helpers import now
     
    325327        return implementedBy(Bed)
    326328
     329class HostelsPlugin(grok.GlobalUtility):
     330    """A plugin to update beds_catalog
     331    """
     332    grok.implements(IKofaPluggable)
     333    grok.name('hostels')
     334    log_prefix = 'HostelsPlugin'
     335
     336    def setup(self, site, name, logger):
     337        return
     338
     339    def update(self, site, name, logger):
     340        site_name = getattr(site, '__name__', '<Unnamed Site>')
     341        nothing_to_do = True
     342        # Add bed_id index
     343        try:
     344            cat = getUtility(ICatalog, name='beds_catalog')
     345            if 'bed_id' not in cat.keys():
     346                nothing_to_do = False
     347                cat[u'bed_id'] = FieldIndex(field_name=u'bed_id')
     348                cat.updateIndexes()
     349                logger.info(
     350                    '%s: bed_id index added to beds_catalog.'
     351                    % self.log_prefix)
     352        except ComponentLookupError: # in unit tests
     353            pass
     354        if nothing_to_do:
     355            logger.info(
     356                '%s: Updating site at %s: Nothing to do.' % (
     357                    self.log_prefix, site_name,)
     358                )
     359        return
     360
    327361
    328362@grok.subscribe(IBedTicket, grok.IObjectRemovedEvent)
Note: See TracChangeset for help on using the changeset viewer.