コード例 #1
0
    def add(self, wid, position, section='default', **kwargs):
        """ Add criterion
        """
        widget = self.widget(wid)
        if not widget:
            raise NameError("Widget type '%s' is undefined" % wid)

        properties = {}
        criteria = self.criteria
        taken_ids = [criterion.getId() for criterion in criteria]
        properties['_taken_ids_'] = taken_ids
        properties.update(kwargs)

        criterion = Criterion(widget=wid, position=position,
                              section=section, **properties)
        criteria.append(criterion)
        return criterion.getId()
コード例 #2
0
    def add(self, wid, position, section='default', **kwargs):
        """ Add criterion
        """
        widget = self.widget(wid)
        if not widget:
            raise NameError("Widget type '%s' is undefined" % wid)

        properties = {}
        criteria = self.criteria
        taken_ids = [criterion.getId() for criterion in criteria]
        properties['_taken_ids_'] = taken_ids
        if '_cid_' in kwargs:
            properties['_cid_'] = kwargs.pop('_cid_')
        criterion = Criterion(widget=wid,
                              position=position,
                              section=section,
                              **properties)

        # insert the new criterion at the right place in criteria
        voc = getUtility(IVocabularyFactory,
                         'eea.faceted.vocabularies.WidgetPositions')
        # we need to take into account position and section
        positions = []
        for term in voc(self.context):
            positions.append('{0}_default'.format(term.value))
            positions.append('{0}_advanced'.format(term.value))
        # will be inserted at the end by default
        insert_index = len(criteria)
        crit_pos_sect = '{0}_{1}'.format(position, section)
        for index, stored_criterion in enumerate(criteria):
            stored_crit_pos_sect = '{0}_{1}'.format(stored_criterion.position,
                                                    stored_criterion.section)
            if (positions.index(crit_pos_sect) <
                    positions.index(stored_crit_pos_sect)):
                insert_index = index
                break
        criteria.insert(insert_index, criterion)

        cid = criterion.getId()
        if kwargs:
            self.edit(cid, **kwargs)
        return cid
コード例 #3
0
    def add(self, wid, position, section='default', **kwargs):
        """ Add criterion
        """
        widget = self.widget(wid)
        if not widget:
            raise NameError("Widget type '%s' is undefined" % wid)

        properties = {}
        criteria = self.criteria
        taken_ids = [criterion.getId() for criterion in criteria]
        properties['_taken_ids_'] = taken_ids
        if '_cid_' in kwargs:
            properties['_cid_'] = kwargs.pop('_cid_')
        criterion = Criterion(widget=wid, position=position,
                              section=section, **properties)

        # insert the new criterion at the right place in criteria
        voc = getUtility(IVocabularyFactory,
                         'eea.faceted.vocabularies.WidgetPositions')
        # we need to take into account position and section
        positions = []
        for term in voc(self.context):
            positions.append('{0}_default'.format(term.value))
            positions.append('{0}_advanced'.format(term.value))
        # will be inserted at the end by default
        insert_index = len(criteria)
        crit_pos_sect = '{0}_{1}'.format(position, section)
        for index, stored_criterion in enumerate(criteria):
            stored_crit_pos_sect = '{0}_{1}'.format(stored_criterion.position,
                                                    stored_criterion.section)
            if (positions.index(crit_pos_sect) <
               positions.index(stored_crit_pos_sect)):
                insert_index = index
                break
        criteria.insert(insert_index, criterion)

        cid = criterion.getId()
        if kwargs:
            self.edit(cid, **kwargs)
        return cid