changeset 1069:2dab7692eae7

pages (files/list): comments handling + size parameters: comments are now handled if comments_url is set. 2 new parameters allows some customization: data['size'] is the size hint to retrieve thumbnails data['retrieve_comments'] indicate if comments must be fetched if the count is > 0.
author Goffi <goffi@goffi.org>
date Sun, 18 Mar 2018 11:36:46 +0100
parents 5e809a49971c
children 46622cb54e6c
files src/pages/files/list/page_meta.py src/pages/files/view/page_meta.py
diffstat 2 files changed, 26 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/pages/files/list/page_meta.py	Sun Mar 18 11:34:01 2018 +0100
+++ b/src/pages/files/list/page_meta.py	Sun Mar 18 11:36:46 2018 +0100
@@ -5,13 +5,15 @@
 from sat.core.i18n import _
 from twisted.internet import defer
 from libervia.server import session_iface
+from libervia.server import pages_tools
 from sat.core.log import getLogger
+from sat.tools.common import uri
 import json
 import os
-log = getLogger('pages/file')
+log = getLogger('pages/files/list')
 """files handling pages"""
 
-name = u'files'
+name = u'files_list'
 access = C.PAGES_ACCESS_PROFILE
 template = u"file/overview.html"
 
@@ -21,6 +23,7 @@
 @defer.inlineCallbacks
 def prepare_render(self, request):
     data = self.getRData(request)
+    thumb_limit = data.get('thumb_limit', 300)
     template_data = request.template_data
     service, path_elts = data[u'service'], data[u'path']
     path = u'/'.join(path_elts)
@@ -39,6 +42,8 @@
             page = self
         elif file_data[u'type'] == C.FILE_TYPE_FILE:
             page = self.getPageByName('files_view')
+
+            ## thumbnails ##
             try:
                 thumbnails = file_data[u'extra']['thumbnails']
                 if not thumbnails:
@@ -49,7 +54,7 @@
                 thumbnails.sort(key = lambda t: t['size'])
                 thumb = thumbnails[0]
                 for thumb_data in thumbnails:
-                    if thumb_data['size'][0] > 300:
+                    if thumb_data['size'][0] > thumb_limit:
                         break
                     thumb = thumb_data
                 if u'url' in thumb:
@@ -66,6 +71,23 @@
         else:
             raise ValueError(u'unexpected file type: {file_type}'.format(file_type=file_data[u'type']))
         file_data[u'url'] = page.getURL(service.full(), *dir_path)
+
+        ## comments ##
+        comments_url = file_data.get(u'comments_url')
+        if comments_url:
+            parsed_url = uri.parseXMPPUri(comments_url)
+            comments_service = file_data[u'comments_service'] = parsed_url['path']
+            comments_node = file_data[u'comments_node'] = parsed_url['node']
+            try:
+                comments_count = file_data[u'comments_count'] = int(file_data['comments_count'])
+            except KeyError:
+                comments_count = None
+            if comments_count and data.get('retrieve_comments', False):
+                file_data[u'comments'] = yield pages_tools.retrieveComments(self,
+                                                                            comments_service,
+                                                                            comments_node,
+                                                                            profile=profile)
+
     template_data[u'files_data'] = files_data
     template_data[u'path'] = path
     if path_elts:
--- a/src/pages/files/view/page_meta.py	Sun Mar 18 11:34:01 2018 +0100
+++ b/src/pages/files/view/page_meta.py	Sun Mar 18 11:36:46 2018 +0100
@@ -10,7 +10,7 @@
 import os
 import os.path
 from sat.core.log import getLogger
-log = getLogger('pages/file')
+log = getLogger('pages/files/view')
 """files handling pages"""
 
 name = u'files_view'