Пример #1
0
    def get_preview_content(self):
        site_root = self.get_site_root()
        languages = site_root.get_property("website_languages")
        content = self._get_preview_content(languages)
        # Reduce content size
        if type(content) is dict:
            for key in content.keys():
                content[key] = reduce_string(content[key], 10000, 255)
        elif isinstance(content, (str, unicode)):
            content = reduce_string(content)

        return content
Пример #2
0
 def render_for_product(self, resource, context):
     reviews = resource.get_resource('reviews', soft=True)
     if reviews is None:
         return {
             'nb_reviews': 0,
             'last_review': None,
             'note': None,
             'link': context.get_link(self),
             'here_abspath': str(context.resource.get_abspath()),
             'product_abspath': resource.get_abspath(),
             'viewboxes': {}
         }
     # XXX Should be in catalog for performances
     abspath = reviews.get_canonical_path()
     queries = [
         PhraseQuery('parent_path', str(abspath)),
         PhraseQuery('workflow_state', 'public'),
         PhraseQuery('format', 'shop_module_a_review')
     ]
     search = context.root.search(AndQuery(*queries))
     brains = list(search.get_documents(sort_by='mtime', reverse=True))
     nb_reviews = len(brains)
     if brains:
         last_review = brains[0]
         last_review = reduce_string(
             brains[0].shop_module_review_description, 200, 200)
     else:
         last_review = None
     note = 0
     for brain in brains:
         note += brain.shop_module_review_note
     # Get viewboxes
     viewboxes = []
     for brain in brains[:5]:
         review = context.root.get_resource(brain.abspath)
         viewbox = Review_Viewbox().GET(review, context)
         viewboxes.append(viewbox)
     return {
         'nb_reviews': nb_reviews,
         'last_review': last_review,
         'link': context.get_link(self),
         'viewboxes': viewboxes,
         'here_abspath': str(context.resource.get_abspath()),
         'product_abspath': resource.get_abspath(),
         'note': note / nb_reviews if nb_reviews else None
     }
Пример #3
0
 def render_for_product(self, resource, context):
     reviews = resource.get_resource('reviews', soft=True)
     if reviews is None:
         return {'nb_reviews': 0,
                 'last_review': None,
                 'note': None,
                 'link': context.get_link(self),
                 'here_abspath': str(context.resource.get_abspath()),
                 'product_abspath': resource.get_abspath(),
                 'viewboxes': {}}
     # XXX Should be in catalog for performances
     abspath = reviews.get_canonical_path()
     queries = [PhraseQuery('parent_path', str(abspath)),
                PhraseQuery('workflow_state', 'public'),
                PhraseQuery('format', 'shop_module_a_review')]
     search = context.root.search(AndQuery(*queries))
     brains = list(search.get_documents(sort_by='mtime', reverse=True))
     nb_reviews = len(brains)
     if brains:
         last_review = brains[0]
         last_review = reduce_string(brains[0].shop_module_review_description,
                                     200, 200)
     else:
         last_review = None
     note = 0
     for brain in brains:
         note += brain.shop_module_review_note
     # Get viewboxes
     viewboxes = []
     for brain in brains[:5]:
         review = context.root.get_resource(brain.abspath)
         viewbox = Review_Viewbox().GET(review, context)
         viewboxes.append(viewbox)
     return {'nb_reviews': nb_reviews,
             'last_review': last_review,
             'link': context.get_link(self),
             'viewboxes': viewboxes,
             'here_abspath': str(context.resource.get_abspath()),
             'product_abspath': resource.get_abspath(),
             'note': note / nb_reviews if nb_reviews else None}
Пример #4
0
 def get_breadcrumb_short_name(self, resource):
     if isinstance(resource, DBResource):
         if resource.has_property('breadcrumb_title'):
             return resource.get_property('breadcrumb_title')
         return reduce_string(resource.get_title(), 15, 30)
     return ''
Пример #5
0
 def __getitem__(self, key):
     title = self.here.get_property('title')
     key = int(key)
     return reduce_string(title, key, key)