Exemple #1
0
  def getVariationCategoryItemList(self, base_category_list=(), base=1,
                                   display_id='logical_path',
                                   current_category=None,**kw):
    """
      Returns the list of possible variations
      XXX Copied and modified from VariatedMixin
      Result is left display.
    """
    variation_category_item_list = []
    category_list = self.getVariationCategoryList()
    if category_list:
      variation_dict = defaultdict(lambda: ([], []))
      resolveCategory = self.getPortalObject().portal_categories.resolveCategory
      for category in category_list:
        resource = resolveCategory(category)
        variation_dict[category.split('/', 1)[0]] \
          [resource.getPortalType() == 'Category'].append(resource)

      kw = dict(is_right_display=0, display_none_category=0, base=base,
                current_category=current_category, **kw)
      render_category_list = Renderer(display_id=display_id, **kw).render
      kw['display_id'] = 'title'
      for base_category, (object_list,
                          category_list) in variation_dict.iteritems():
        if base_category_list and base_category not in base_category_list:
          continue
        variation_category_item_list += render_category_list(category_list)
        variation_category_item_list += Renderer(base_category=base_category,
                                                 **kw).render(object_list)
    return variation_category_item_list
Exemple #2
0
  def getVariationCategoryItemList(self, base_category_list=(), base=1,
      display_id='logical_path', display_base_category=1,
      current_category=None, omit_optional_variation=0,
      omit_option_base_category=None, **kw):
    """
      Returns the list of possible variations
    """
    #XXX backwards compatibility
    if omit_option_base_category is not None:
      warn("Please use omit_optional_variation instead of"\
          " omit_option_base_category.", DeprecationWarning)
      omit_optional_variation = omit_option_base_category

    variation_category_item_list = []
    if current_category is not None:
      variation_category_item_list.append((current_category,current_category))

    if base_category_list is ():
      base_category_list = self.getVariationBaseCategoryList()
      if omit_optional_variation == 1:
        base_category_list = [x for x in base_category_list if x not in
                              self.getPortalOptionBaseCategoryList()]
    # Prepare 2 rendering
    portal_categories = self.portal_categories
    for base_category in base_category_list:
      variation_category_list = self._getVariationCategoryList(
                                       base_category_list=[base_category])
      
      category_list = []
      object_list = []
      for variation_category_path in variation_category_list:
        try:
          variation_category = portal_categories.resolveCategory(
                                    variation_category_path)
          var_cat_portal_type = variation_category.getPortalType()
        except AttributeError:
          variation_category_item_list.append((variation_category_path,
                                               variation_category_path))
        else:
          if var_cat_portal_type != 'Category':
            object_list.append(variation_category)
          else:
            category_list.append(variation_category)
      # Render categories
      variation_category_item_list.extend(Renderer(
                             display_base_category=display_base_category,
                             display_none_category=0, base=base,
                             current_category=current_category,
                             display_id=display_id, **kw).\
                                               render(category_list))
      # Render the others
      variation_category_item_list.extend(Renderer(
                             base_category=base_category,
                             display_base_category=display_base_category,
                             display_none_category=0, base=base,
                             current_category=current_category,
                             display_id='title', **kw).\
                                               render(object_list))
    return variation_category_item_list
Exemple #3
0
    def getVariationBaseCategoryItemList(self,
                                         display_id='title_or_id',
                                         omit_optional_variation=0,
                                         omit_option_base_category=None,
                                         omit_individual_variation=0):
        """
        Returns base category of the resource
        as a list of tuples (title, id). This is mostly
        useful in ERP5Form instances to generate selection
        menus.
      """
        #XXX backwards compatibility
        if omit_option_base_category is not None:
            warn("Please use omit_optional_variation instead of"\
                " omit_option_base_category.", DeprecationWarning)
            omit_optional_variation = omit_option_base_category

        variation_base_category_list = self.getVariationBaseCategoryList(
            omit_optional_variation=omit_optional_variation,
            omit_individual_variation=omit_individual_variation)
        result = []
        for base_category in variation_base_category_list:
            bc = self.portal_categories.resolveCategory(base_category)
            result.extend(
                Renderer(display_base_category=0,
                         display_none_category=0,
                         base=1,
                         display_id=display_id).render([bc]))
        return result
Exemple #4
0
    def getVariationCategoryItemList(self,
                                     base_category_list=(),
                                     base=1,
                                     display_id='title',
                                     current_category=None,
                                     **kw):
        """
        Returns the list of possible variations
        XXX Copied and modified from VariatedMixin
        Result is left display.
      """
        variation_category_item_list = []
        if base_category_list == ():
            base_category_list = self.getVariationBaseCategoryList()

        category_renderer = Renderer(is_right_display=0,
                                     display_none_category=0,
                                     base=base,
                                     current_category=current_category,
                                     display_id='logical_path',
                                     **kw)

        for base_category in base_category_list:
            variation_category_list = self.getVariationCategoryList(
                base_category_list=[base_category])

            category_list = []
            object_list = []
            for variation_category in variation_category_list:
                resource = self.portal_categories.resolveCategory(
                    variation_category)
                if resource.getPortalType() == 'Category':
                    category_list.append(resource)
                else:
                    object_list.append(resource)

            variation_category_item_list.extend(category_renderer.\
                                                  render(category_list))

            variation_category_item_list.extend(Renderer(
                                   is_right_display=0,
                                   base_category=base_category,
                                   display_none_category=0, base=base,
                                   current_category=current_category,
                                   display_id=display_id,**kw).\
                                                     render(object_list))
        return variation_category_item_list
Exemple #5
0
    def getCategoryChildItemList(self, recursive=1, base=0,
                                       cache=DEFAULT_CACHE_FACTORY,
                                       current_category_list=None, **kw):
      """
      Returns a list of tuples by parsing recursively all categories in a
      given list of base categories. Each tuple contains::

        (c.relative_url, c.display_id())

      base -- if set to 1, relative_url will start with the base category id
              if set to 0 and if base_category is a single id, relative_url
              are relative to the base_category (and thus  doesn't start
              with the base category id)

              if set to string, use string as base

      display_id -- method called to build the couple

      recursive -- if set to 0 do not apply recursively

      current_category_list -- allows to provide list of categories which is not part of the
                          default ItemList. Very useful for displaying values in a popup
                          menu which can no longer be selected. It is required to give
                          url including base category.

      All parameters supported by getCategoryChildValueList and Render are
      supported here.
      """
      def _renderCategoryChildItemList(recursive=1, base=0, **kw):
        value_list = self.getCategoryChildValueList(recursive=recursive, **kw)
        return Renderer(base=base, **kw).render(value_list)

      if cache:
        _renderCategoryChildItemList = CachingMethod(
          _renderCategoryChildItemList,
          (
            'Category_getCategoryChildItemList',
            self.getPortalObject().Localizer.get_selected_language(),
            self.getPath(),
            getSecurityManager().getUser().getId() if 'checked_permission' in kw else None,
          ),
          cache_factory=cache,
        )
      item_list = _renderCategoryChildItemList(recursive=recursive, base=base, **kw)

      if current_category_list:
        kw['display_none_category'] = False
        current_category_item_list = Renderer(base=base, **kw).render(
          [self.portal_categories.resolveCategory(c) for c in current_category_list])
        item_set = {tuple(x) for x in item_list}
        additional_item_list = []
        for current_category_item in current_category_item_list:
          if not(tuple(current_category_item) in item_set):
            additional_item_list.append(current_category_item)
        if additional_item_list:
          item_list = item_list + additional_item_list
      return item_list
Exemple #6
0
    def getVariationCategoryItemList(self,
                                     base_category_list=(),
                                     base=1,
                                     display_id='logical_path',
                                     current_category=None,
                                     **kw):
        """
      Returns the list of possible variations
      XXX Copied and modified from VariatedMixin
      Result is left display.
    """
        variation_category_item_list = []
        if base_category_list == ():
            base_category_list = self.getVariationRangeBaseCategoryList()

        for base_category in base_category_list:
            variation_category_list = self.getVariationCategoryList(
                base_category_list=[base_category])

            resource_list = [self.portal_categories.resolveCategory(x) for x in\
                             variation_category_list]
            category_list = [x for x in resource_list \
                             if x.getPortalType() == 'Category']
            variation_category_item_list.extend(Renderer(
                                   is_right_display=0,
                                   display_none_category=0, base=base,
                                   current_category=current_category,
                                   display_id=display_id, **kw).\
                                                     render(category_list))
            object_list = [x for x in resource_list \
                             if x.getPortalType() != 'Category']
            variation_category_item_list.extend(Renderer(
                                   is_right_display=0,
                                   base_category=base_category,
                                   display_none_category=0, base=base,
                                   current_category=current_category,
                                   display_id='title', **kw).\
                                                     render(object_list))
        return variation_category_item_list
Exemple #7
0
    def getVariationRangeCategoryItemList(self,
                                          base_category_list=(),
                                          base=1,
                                          root=1,
                                          display_id='title',
                                          display_base_category=1,
                                          current_category=None,
                                          omit_individual_variation=0,
                                          **kw):
        """
          Returns possible variations

          resource.getVariationRangeCategoryItemList
            => [(display, value)]

      ## Variation API (exemple) ##
        Base categories defined:
          - colour
          - morphology
          - size
        Categories defined:
          - colour/blue
          - colour/red
          - size/Man
          - size/Woman
        Resource 'resource' created with variation_base_category_list:
            (colour, morphology, size)

        resource.getVariationRangeCategoryList
        variation   | individual variation | result
        ____________________________________________________________________________________
                    |                      | (colour/blue, colour/red, size/Man, size/Woman)
        size/Man    |                      | (colour/blue, colour/red, size/Man, size/Woman)
        colour/blue |                      | (colour/blue, colour/red, size/Man, size/Woman)
                    |  colour/1            | (colour/1, size/Man, size/Woman)
                    |  morphology/2        | (colour/blue, colour/red, size/Man, size/Woman, morphology/2)
        """
        result = []
        if base_category_list is ():
            base_category_list = self.getVariationBaseCategoryList(
                omit_individual_variation=omit_individual_variation)
        elif isinstance(base_category_list, str):
            base_category_list = (base_category_list, )

        individual_variation_list = self.contentValues(
            portal_type=self.getPortalVariationTypeList(),
            sort_on=[('title', 'ascending')])
        individual_variation_list = [
            x.getObject() for x in individual_variation_list
        ]
        other_base_category_set = set(base_category_list)

        if not omit_individual_variation:
            for variation in individual_variation_list:
                for base_category in variation.getVariationBaseCategoryList():
                    if base_category_list is ()\
                        or base_category in base_category_list:
                        other_base_category_set.discard(base_category)
                        # XXX now, call Renderer a lot of time.
                        # Better implementation needed
                        result.extend(
                            Renderer(
                                base_category=base_category,
                                display_base_category=display_base_category,
                                display_none_category=0,
                                base=base,
                                current_category=current_category,
                                display_id=display_id).render([variation]))

        # Get category variation
        if other_base_category_set:
            result.extend(
                super(Resource, self).getVariationRangeCategoryItemList(
                    base_category_list=list(other_base_category_set),
                    base=base,
                    display_base_category=display_base_category,
                    **kw))
        # Return result
        return result
Exemple #8
0
    def getVariationCategoryItemList(self,
                                     base_category_list=(),
                                     omit_optional_variation=0,
                                     omit_individual_variation=1,
                                     base=1,
                                     current_category=None,
                                     display_base_category=1,
                                     display_id='title',
                                     **kw):
        """
        Returns variations of the resource.
        If omit_individual_variation==1, does not return individual
        variation.
        Else, returns them.
        Display is on left.
            => [(display, value)]

        *old parameters: base=1, current_category=None,
                         display_id='title' (default value title)
      """
        base_category_list = base_category_list or \
            self.getVariationBaseCategoryList()

        individual_bc_list = self.getIndividualVariationBaseCategoryList()
        other_bc_list = [
            x for x in base_category_list if not x in individual_bc_list
        ]

        if omit_optional_variation:
            optional_bc_list = self.getOptionalVariationBaseCategoryList()\
                or self.getPortalOptionBaseCategoryList()
            if optional_bc_list:
                other_bc_list = [
                    x for x in other_bc_list if not x in optional_bc_list
                ]

        result = super(Resource, self).getVariationCategoryItemList(
            base_category_list=other_bc_list,
            display_base_category=display_base_category,
            display_id=display_id,
            base=base,
            **kw)

        if not omit_individual_variation:
            individual_variation_list = self.contentValues(
                portal_type=self.getPortalVariationTypeList())
            individual_variation_list = [
                x.getObject() for x in individual_variation_list
            ]

            for variation in individual_variation_list:
                for base_category in variation.getVariationBaseCategoryList():
                    # backwards compatbility: if individual_bc_list is empty, allow
                    # all individual variation base categories.
                    if (base_category_list is ()
                        or base_category in base_category_list)\
                       and (not len(individual_bc_list)
                            or base_category in individual_bc_list):
                        # XXX append object, relative_url ?
                        # XXX now, call Renderer a lot of time.
                        # Better implementation needed
                        result.extend(
                            Renderer(
                                base_category=base_category,
                                display_base_category=display_base_category,
                                display_none_category=0,
                                base=base,
                                current_category=current_category,
                                display_id=display_id,
                                **kw).render([variation]))
        return result
Exemple #9
0
 def _renderCategoryChildItemList(recursive=1, base=0, **kw):
     value_list = self.getCategoryChildValueList(recursive=recursive,
                                                 **kw)
     return Renderer(base=base, **kw).render(value_list)