don't show download box nor download link for images, by default hide name attribute even if not specified in the interface
authorsylvain.thenault@logilab.fr
Wed, 25 Feb 2009 15:55:39 +0100
changeset 957 b1f68f725fe9
parent 956 ae7044a06efb
child 958 6053622aae81
don't show download box nor download link for images, by default hide name attribute even if not specified in the interface
web/views/idownloadable.py
--- a/web/views/idownloadable.py	Wed Feb 25 15:54:55 2009 +0100
+++ b/web/views/idownloadable.py	Wed Feb 25 15:55:39 2009 +0100
@@ -35,9 +35,19 @@
     
 class DownloadBox(EntityBoxTemplate):
     id = 'download_box'
-    __selectors__ = (one_line_rset, implement_interface, match_context_prop)
+    # XXX primary_view selector ?
+    __selectors__ = (one_line_rset, implement_interface, match_context_prop, score_entity_selector)
     accepts_interfaces = (IDownloadable,)
     order = 10
+
+    @classmethod
+    def score_entity(cls, entity):
+        mt = entity.download_content_type()
+        # no download box for images
+        if mt and mt.startswith('image/'):
+            return 0
+        return 1
+    
     def cell_call(self, row, col, title=None, label=None, **kwargs):
         entity = self.entity(row, col)
         download_box(self.w, entity, title, label)
@@ -90,8 +100,9 @@
                                                                                 
 class IDownloadablePrimaryView(baseviews.PrimaryView):
     __selectors__ = (implement_interface,)
-    #skip_attrs = ('eid', 'data',) # XXX
     accepts_interfaces = (IDownloadable,)
+    # XXX File/Image attributes but this is not specified in the IDownloadable interface
+    skip_attrs = baseviews.PrimaryView.skip_attrs + ('data', 'name')
 
     def render_entity_title(self, entity):
         self.w(u'<h1>%s %s</h1>'
@@ -100,12 +111,12 @@
     
     def render_entity_attributes(self, entity, siderelations):
         super(IDownloadablePrimaryView, self).render_entity_attributes(entity, siderelations)
-        self.wview('downloadlink', entity.rset, title=self.req._('download'), row=entity.row)
         self.w(u'<div class="content">')
         contenttype = entity.download_content_type()
         if contenttype.startswith('image/'):
             self.wview('image', entity.rset, row=entity.row)
         else:
+            self.wview('downloadlink', entity.rset, title=self.req._('download'), row=entity.row)
             try:
                 if ENGINE.has_input(contenttype):
                     self.w(entity.printable_value('data'))