Ejemplo n.º 1
0
    def addCategory(self):
        """
        """
        category_name = self.request.get("category_name", "")
        if category_name == "":
            return self._showView()
            
        shop = IShopManagement(self.context).getShop()

        putils = getToolByName(self.context, "plone_utils")        
        normalized_id = putils.normalizeString(category_name)

        if base_hasattr(shop, normalized_id) == True:
            putils.addPortalMessage(MESSAGES["CATEGORY_ALREADY_EXISTS"], "error")
            return self._showView()
        else:
            shop.invokeFactory("Category", id=normalized_id, title=category_name)
            putils.addPortalMessage(MESSAGES["ADDED_CATEGORY"])
            
        new_category = shop[normalized_id]
        
        if self.hasSelectedCategories() == True:
            catalog = getToolByName(self.context, "portal_catalog")
            brains = catalog.searchResults(UID = self.selected_categories)            
            parent_categories = [b.getObject() for b in brains]            
            new_category.setParentCategory(parent_categories)
            new_category.reindexObject()

        return self._showView()