Example #1
0
def uninstallVarious(context):
    """Remove all persistent configuration from the site manager"""
    if context.readDataFile('ratings-uninstall.txt') is None:
        return
    site = context.getSite()
    setSite(site)
    cat_manager = ICategoryContainer(site)
    for cat in cat_manager._get_local_categories():
        cat_manager.remove(cat)
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))
Example #3
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 #4
0
 def _extractLocalCategories(self):
     node = self._doc.createElement('categories')
     attr_names = IRatingCategoryInfo.names()
     for category in ICategoryContainer(getSite())._get_local_categories():
         child = self._doc.createElement('category')
         child.setAttribute('name', category.name)
         for attr in attr_names:
             value = getattr(category, attr, None)
             if value is not None:
                 sub = self._doc.createElement('attr')
                 sub.setAttribute('name', attr)
                 if isinstance(attr, (str, unicode)):
                     sub.setAttribute('type', 'string')
                 if isinstance(attr, int):
                     sub.setAttribute('type', 'integer')
                 subchild = self._doc.createTextNode(unicode(value))
                 sub.appendChild(subchild)
                 child.appendChild(sub)
         node.appendChild(child)
     return node
Example #5
0
 def _purgeTypeRatingsSettings(self):
     self.context._mapping.clear()
     category_container = ICategoryContainer(getSite())
     for cat in category_container.local_categories:
         category_container.remove(cat)
Example #6
0
 def _purgeTypeRatingsSettings(self):
     self.context._mapping.clear()
     category_container=ICategoryContainer(getSite())
     for cat in category_container.local_categories:
         category_container.remove(cat)