def edit(self, cid, **kwargs):
        """ See IFacetedCriterionHandler
        """
        criteria = ICriteria(self.context)
        widget = criteria.widget(cid=cid)
        criterion = criteria.get(cid)
        if kwargs.pop('__new__', False):
            criterion = criterion.__class__(cid='c0')
        widget = widget(self.context, self.request, criterion)

        wid = kwargs.pop('widget', None)
        properties = self.extractData(widget, **kwargs)
        if wid:
            properties['widget'] = wid

        update = {}
        for prop, value in properties.items():
            form_key = 'faceted.%s.%s' % (cid, prop)
            if form_key not in kwargs and value is None:
                continue
            update[prop] = value

        if update:
            criteria.edit(cid, **update)
            if widget.hidden:
                notify(FacetedGlobalSettingsChangedEvent(self.context))
            elif set(['hidden', 'operator']).intersection(update.keys()):
                notify(FacetedGlobalSettingsChangedEvent(self.context))

        return self._redirect('Changes saved')
    def query(self, cid, **kwargs):
        """ Count catalog items
        """
        # Cleanup query
        kwargs.pop('sort_on', None)
        kwargs.pop('sort_order', None)

        kwargs.pop(cid, None)
        self.request.form.pop(cid, None)
        # jQuery >= 1.4 adds type to params keys
        # $.param({ a: [2,3,4] }) // "a[]=2&a[]=3&a[]=4"
        # Let's fix this
        kwargs.pop(cid + '[]', None)
        self.request.form.pop(cid + '[]', None)

        criteria = ICriteria(self.context)
        criterion = criteria.get(cid)

        start = time.time()
        # Query catalog
        handler = getMultiAdapter((self.context, self.request),
                                  name=u'faceted_query')

        if criterion.get('index', '') == 'Language':
            kwargs['_language_count_'] = True
        brains = handler.query(batch=False, sort=False, **kwargs)

        # Get index
        widget = criteria.widget(cid=cid)(self.context, self.request, criterion)
        res = widget.count(brains)
        logger.debug('Benchmark %s: %s', cid, time.time() - start)
        return res
示例#3
0
    def _updateFacetedFilters(self):
        """Update vocabulary used for "Taken over by".
           Make sure the default for contacts 'c5' widget is not a list."""
        logger.info(
            "Updating faceted filter \"Taken over by\" for every MeetingConfigs..."
        )
        for cfg in self.tool.objectValues('MeetingConfig'):
            obj = cfg.searches.searches_items
            # update vocabulary for relevant filters
            criteria = ICriteria(obj)
            criteria.edit(
                'c12', **{
                    'vocabulary':
                    'Products.PloneMeeting.vocabularies.creatorswithnobodyforfacetedfiltervocabulary'
                })
            criteria.edit(
                'c27', **{
                    'vocabulary':
                    'Products.PloneMeeting.vocabularies.associatedgroupsvocabulary'
                })
        logger.info('Done.')

        logger.info("Updating faceted filter \"Defined in\" for 'c5' "
                    "criterion of contacts/orgs-searches...")
        obj = self.portal.contacts.get('orgs-searches')
        # as default is not correct (a string instead a list, we can not use edit or it fails to validate)
        criteria = ICriteria(obj)
        criterion = criteria.get('c5')
        criterion.default = u'collective.contact.plonegroup.interfaces.IPloneGroupContact'
        logger.info('Done.')
    def edit(self, cid, **kwargs):
        """ See IFacetedCriterionHandler
        """
        criteria = ICriteria(self.context)
        widget = criteria.widget(cid=cid)
        criterion = criteria.get(cid)
        if kwargs.pop('__new__', False):
            criterion = criterion.__class__(cid='c0')
        widget = widget(self.context, self.request, criterion)

        wid = kwargs.pop('widget', None)
        properties = self.extractData(widget, **kwargs)
        if wid:
            properties['widget'] = wid

        update = {}
        for prop, value in properties.items():
            form_key =  'faceted.%s.%s' % (cid, prop)
            if form_key not in kwargs and value is None:
                continue
            update[prop] = value

        if update:
            criteria.edit(cid, **update)
            if widget.hidden:
                notify(FacetedGlobalSettingsChangedEvent(self.context))
            elif set(['hidden', 'operator']).intersection(update.keys()):
                notify(FacetedGlobalSettingsChangedEvent(self.context))

        return self._redirect('Changes saved')
示例#5
0
    def query(self, cid, **kwargs):
        """ Count catalog items
        """
        # Cleanup query
        kwargs.pop('sort_on', None)
        kwargs.pop('sort_order', None)
        kwargs.pop(cid, None)
        self.request.form.pop(cid, None)

        criteria = ICriteria(self.context)
        criterion = criteria.get(cid)

        # Query catalog
        handler = getMultiAdapter((self.context, self.request),
                                  name=u'faceted_query')

        if criterion.get('index', '') == 'Language':
            kwargs['_language_count_'] = True
        brains = handler.query(batch=False, sort=False, **kwargs)

        # Get index
        widget = criteria.widget(cid=cid)(self.context, self.request,
                                          criterion)
        vocabulary = dict((key, value)
                          for key, value, count in widget.vocabulary(oll=True)
                          if key not in ("", "all"))

        # Count
        count = getattr(widget, 'count', lambda brains, sequence: {})
        res = count(brains, sequence=vocabulary.keys())
        res.pop("", 0)
        oll = res.pop('all', 0)

        res = res.items()
        res.sort(key=operator.itemgetter(1), reverse=True)

        maxitems = widget.maxitems
        if maxitems:
            res = res[:maxitems]
        res.sort(key=operator.itemgetter(0), cmp=compare)

        # Return a of list of three items tuples (key, label, count)
        res = [(key, vocabulary.get(key, key), value) for key, value in res]

        res.insert(0, ('all', 'All', oll))
        for item in res:
            yield item
    def __call__(self, **kwargs):
        if self.request:
            kwargs.update(self.request.form)

        # Calling self.index() will set cache headers for varnish
        self.index()

        cid = kwargs.pop('cid', None)
        if not cid:
            return {}

        res = self.query(cid, **kwargs)

        criteria = ICriteria(self.context)
        criterion = criteria.get(cid)
        widget = criteria.widget(cid=cid)(self.context, self.request, criterion)
        return widget(vocabulary=res)
    def query(self, cid, **kwargs):
        """ Count catalog items
        """
        # Cleanup query
        kwargs.pop('sort_on', None)
        kwargs.pop('sort_order', None)
        kwargs.pop(cid, None)
        self.request.form.pop(cid, None)

        criteria = ICriteria(self.context)
        criterion = criteria.get(cid)

        # Query catalog
        handler = getMultiAdapter((self.context, self.request),
                                  name=u'faceted_query')

        if criterion.get('index', '') == 'Language':
            kwargs['_language_count_'] = True
        brains = handler.query(batch=False, sort=False, **kwargs)

        # Get index
        widget = criteria.widget(cid=cid)(self.context, self.request, criterion)
        vocabulary = dict((key, value) for key, value, count
                    in widget.vocabulary(oll=True) if key not in ("", "all"))

        # Count
        count = getattr(widget, 'count', lambda brains, sequence: {})
        res = count(brains, sequence=vocabulary.keys())
        res.pop("", 0)
        oll = res.pop('all', 0)

        res = res.items()
        res.sort(key=operator.itemgetter(1), reverse=True)

        maxitems = widget.maxitems
        if maxitems:
            res = res[:maxitems]
        res.sort(key=operator.itemgetter(0), cmp=compare)

        # Return a of list of three items tuples (key, label, count)
        res = [(key, vocabulary.get(key, key), value) for key, value in res]

        res.insert(0, ('all', 'All', oll))
        for item in res:
            yield item
示例#8
0
    def __call__(self, **kwargs):
        if self.request:
            kwargs.update(self.request.form)

        # Calling self.index() will set cache headers for varnish
        self.index()

        cid = kwargs.pop('cid', None)
        if not cid:
            return {}

        res = self.query(cid, **kwargs)

        criteria = ICriteria(self.context)
        criterion = criteria.get(cid)
        widget = criteria.widget(cid=cid)(self.context, self.request,
                                          criterion)
        return widget(vocabulary=res)
示例#9
0
    def _removeGroupsOfMatter(self):
        """Remove MeetingCategory.groupsOfMatter field and related."""
        logger.info('Removing MeetingCategory.groupsOfMatter...')
        brains = self.portal.portal_catalog(meta_type='MeetingCategory')
        for brain in brains:
            cat = brain.getObject()
            if hasattr(cat, 'groupsOfMatter'):
                cat.setGroupsInCharge(cat.groupsOfMatter)
                delattr(cat, 'groupsOfMatter')
            else:
                self._already_migrated()
                return
        # remove portal_catalog index 'groupsOfMatter'
        self.removeUnusedIndexes(indexes=['groupsOfMatter'])

        # remove faceted filter
        for cfg in self.tool.objectValues('MeetingConfig'):
            # enable includeGroupsInChargeDefinedOnCategory so indexed groupsInCharge is correct
            cfg.setIncludeGroupsInChargeDefinedOnCategory(True)
            obj = cfg.searches.searches_items
            # update vocabulary for relevant filters
            criteria = ICriteria(obj)
            if criteria.get('c50'):
                criteria.delete('c50')
            # unselect 'c50' from dashboard filters and select 'c23'
            dashboardItemsListingsFilters = list(cfg.getDashboardItemsListingsFilters())
            if 'c50' in dashboardItemsListingsFilters:
                dashboardItemsListingsFilters.remove('c50')
                dashboardItemsListingsFilters.append('c23')
                cfg.setDashboardItemsListingsFilters(dashboardItemsListingsFilters)
            dashboardMeetingAvailableItemsFilters = list(cfg.getDashboardMeetingAvailableItemsFilters())
            if 'c50' in dashboardMeetingAvailableItemsFilters:
                dashboardMeetingAvailableItemsFilters.remove('c50')
                dashboardMeetingAvailableItemsFilters.append('c23')
                cfg.setDashboardMeetingAvailableItemsFilters(dashboardMeetingAvailableItemsFilters)
            dashboardMeetingLinkedItemsFilters = list(cfg.getDashboardMeetingLinkedItemsFilters())
            if 'c50' in dashboardMeetingLinkedItemsFilters:
                dashboardMeetingLinkedItemsFilters.remove('c50')
                dashboardMeetingLinkedItemsFilters.append('c23')
                cfg.setDashboardMeetingLinkedItemsFilters(dashboardMeetingLinkedItemsFilters)
        logger.info('Done.')
示例#10
0
    def query(self, cid, **kwargs):
        """ Count catalog items
        """
        # Cleanup query
        kwargs.pop('sort_on', None)
        kwargs.pop('sort_order', None)
        kwargs.pop('sort[]', None)
        kwargs.pop('sort', None)
        kwargs.pop('reversed[]', None)
        oid = '%s-operator' % cid
        operator = kwargs.pop(oid, kwargs.pop(oid + '[]', None))

        if not operator or operator != 'and':
            kwargs.pop(cid, None)
            self.request.form.pop(cid, None)
            # jQuery >= 1.4 adds type to params keys
            # $.param({ a: [2,3,4] }) // "a[]=2&a[]=3&a[]=4"
            # Let's fix this
            kwargs.pop(cid + '[]', None)
            self.request.form.pop(cid + '[]', None)

        criteria = ICriteria(self.context)
        criterion = criteria.get(cid)

        start = time.time()
        # Query catalog
        handler = getMultiAdapter((self.context, self.request),
                                  name=u'faceted_query')

        if criterion.get('index', '') == 'Language':
            kwargs['_language_count_'] = True
        kwargs['counter_query'] = True
        brains = handler.query(batch=False, sort=False, **kwargs)

        # Get index
        widget = criteria.widget(cid=cid)(self.context, self.request,
                                          criterion)
        count = getattr(widget, 'count', lambda brains: {})
        res = count(brains)
        logger.debug('Benchmark %s: %s', cid, time.time() - start)
        return res
示例#11
0
    def query(self, cid, **kwargs):
        """ Count catalog items
        """
        # Cleanup query
        kwargs.pop("sort_on", None)
        kwargs.pop("sort_order", None)
        kwargs.pop("sort[]", None)
        kwargs.pop("sort", None)
        kwargs.pop("reversed[]", None)
        oid = "%s-operator" % cid
        operator = kwargs.pop(oid, kwargs.pop(oid + "[]", None))

        if not operator or operator != "and":
            kwargs.pop(cid, None)
            self.request.form.pop(cid, None)
            # jQuery >= 1.4 adds type to params keys
            # $.param({ a: [2,3,4] }) // "a[]=2&a[]=3&a[]=4"
            # Let's fix this
            kwargs.pop(cid + "[]", None)
            self.request.form.pop(cid + "[]", None)

        criteria = ICriteria(self.context)
        criterion = criteria.get(cid)

        start = time.time()
        # Query catalog
        handler = getMultiAdapter((self.context, self.request), name=u"faceted_query")

        if criterion.get("index", "") == "Language":
            kwargs["_language_count_"] = True
        brains = handler.query(batch=False, sort=False, **kwargs)

        # Get index
        widget = criteria.widget(cid=cid)(self.context, self.request, criterion)
        count = getattr(widget, "count", lambda brains: {})
        res = count(brains)
        logger.debug("Benchmark %s: %s", cid, time.time() - start)
        return res