Example #1
0
    def _initLocalCategoriesSettings(self, node):
        def _convert(type, value):
            if type == 'string':
                return unicode(value)
            if type == 'integer':
                return int(value)
            return value

        for child in node.childNodes:
            if child.nodeName == 'categories':
                category_container = ICategoryContainer(getSite())
                current_categories = [
                    cat.name
                    for cat in category_container._get_local_categories()
                ]
                for category_node in child.getElementsByTagName('category'):
                    category_name = category_node.getAttribute('name')
                    attributes = {'name': category_name}
                    for attr_node in category_node.getElementsByTagName(
                            'attr'):
                        attr_name = attr_node.getAttribute('name')
                        attr_type = attr_node.getAttribute('type')
                        attributes[str(attr_name)] = _convert(
                            attr_type, attr_node.firstChild.data)
                    # XXX: should we always add or better to update already existing?
                    # (should we purge at import?)
                    if category_name in current_categories:
                        category_container.modify(
                            RatingsCategoryFactory(**attributes))
                    else:
                        category_container.add(
                            RatingsCategoryFactory(**attributes))
Example #2
0
    def _initLocalCategoriesSettings(self, node):
        def _convert(type, value):
            if type=='string':
                return unicode(value)
            if type=='integer':
                return int(value)
            return value

        for child in node.childNodes:
            if child.nodeName=='categories':
                category_container=ICategoryContainer(getSite())
                current_categories=[cat.name for cat in
                                        category_container._get_local_categories()]
                for category_node in child.getElementsByTagName('category'):
                    category_name=category_node.getAttribute('name')
                    attributes={'name': category_name}
                    for attr_node in category_node.getElementsByTagName('attr'):
                        attr_name = attr_node.getAttribute('name')
                        attr_type = attr_node.getAttribute('type')
                        attributes[str(attr_name)]=_convert(attr_type,
                                                       attr_node.firstChild.data)
                    # XXX: should we always add or better to update already existing?
                    # (should we purge at import?)
                    if category_name in current_categories:
                        category_container.modify(RatingsCategoryFactory(**attributes))
                    else:
                        category_container.add(RatingsCategoryFactory(**attributes))