src/pyams_content/shared/view/merge.py
changeset 791 29c778c100e0
parent 787 93f9a8b859fc
child 796 2ef3bacda742
equal deleted inserted replaced
790:bc6e355911d1 791:29c778c100e0
     7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
     7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
     8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
    10 # FOR A PARTICULAR PURPOSE.
    10 # FOR A PARTICULAR PURPOSE.
    11 #
    11 #
       
    12 from pyams_utils.list import random_iter
    12 
    13 
    13 __docformat__ = 'restructuredtext'
    14 __docformat__ = 'restructuredtext'
    14 
    15 
    15 
    16 
    16 # import standard library
    17 # import standard library
    60 
    61 
    61     @classmethod
    62     @classmethod
    62     def get_results(cls, views, context):
    63     def get_results(cls, views, context):
    63         results = (view.get_results(context) for view in views)
    64         results = (view.get_results(context) for view in views)
    64         yield from chain(*results)
    65         yield from chain(*results)
       
    66 
       
    67 
       
    68 @utility_config(name='random', provides=IViewsMerger)
       
    69 class ViewsRandomMergeMode(object):
       
    70     """Views random merge mode"""
       
    71 
       
    72     label = _("Extract items randomly")
       
    73 
       
    74     @classmethod
       
    75     def get_results(cls, views, context):
       
    76         results = (view.get_results(context) for view in views)
       
    77         results = list(chain(*results))
       
    78         shuffle(results)
       
    79         yield from iter(results)
    65 
    80 
    66 
    81 
    67 @utility_config(name='zip', provides=IViewsMerger)
    82 @utility_config(name='zip', provides=IViewsMerger)
    68 class ViewsZipMergeMode(object):
    83 class ViewsZipMergeMode(object):
    69     """Views zip merge mode"""
    84     """Views zip merge mode"""