Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

improved the html stuff

svn path=/plone.formwidget.multifile/trunk/; revision=39492
  • Loading branch information...
commit 5be97f01bc9dce6596f163437c5b95c8d5b5042e 1 parent d7230cf
Jonas Baumann jone authored
8 plone/formwidget/multifile/display.pt
... ... @@ -0,0 +1,8 @@
  1 +<div class="multi-file">
  2 +
  3 + <ul class="multi-file-files">
  4 + <li tal:repeat="html view/get_data"
  5 + tal:replace="structure html" />
  6 + </ul>
  7 +
  8 +</div>
33 plone/formwidget/multifile/file_template.pt
... ... @@ -0,0 +1,33 @@
  1 +<tal:i18n i18n:domain="plone.formwidget.multifile">
  2 +
  3 + <li class="multi-file-file">
  4 +
  5 + <img tal:condition="options/icon" src="" alt=""
  6 + tal:attributes="src options/icon"/>
  7 +
  8 + <a tal:omit-tag="not:options/download_url"
  9 + tal:attributes="href options/download_url"
  10 + ><span tal:condition="options/filename"
  11 + tal:content="options/filename"
  12 + class="filename"/>
  13 + </a>
  14 +
  15 + <span class="discreet" tal:condition="options/size">
  16 + &mdash;
  17 + <tal:size replace="options/size" /> KB
  18 + </span>
  19 +
  20 + <tal:EDITABLE tal:condition="options/editable">
  21 + <span class="discreet">
  22 + &mdash;
  23 + <a href="" class="multi-file-remove-file"
  24 + i18n:translate="link_remove_file">remove</a>
  25 + </span>
  26 +
  27 + <input type="hidden"
  28 + tal:attributes="name string:${options/widget/name}:list;
  29 + value options/value" />
  30 + </tal:EDITABLE>
  31 +
  32 + </li>
  33 +</tal:i18n>
23 plone/formwidget/multifile/input.pt
@@ -25,27 +25,8 @@
25 25 tal:omit-tag="not:view/editing"></div>
26 26
27 27 <ul class="multi-file-files">
28   - <li tal:repeat="item view/get_value" class="multi-file-file">
29   - <img tal:condition="icon" src="" alt=""
30   - tal:define="icon item/icon"
31   - tal:attributes="src string:${view/better_context/portal_url}/$icon"/>
32   - <a tal:omit-tag="not:item/download_url"
33   - tal:attributes="href item/download_url">
34   - <span tal:condition="item/filename|nothing"
35   - tal:content="item/filename" />
36   - </a>
37   - <span class="discreet" tal:condition="item/size|nothing">
38   - &mdash;
39   - <tal:size replace="item/size" /> KB
40   - <tal:editing tal:condition="view/editing">
41   - &mdash;
42   - <a href="" class="multi-file-remove-file">remove</a>
43   - </tal:editing>
44   - </span>
45   - <input type="hidden"
46   - tal:attributes="name string:${view/name}:list;
47   - value item/value" />
48   - </li>
  28 + <li tal:repeat="html view/get_data"
  29 + tal:replace="structure html" />
49 30 </ul>
50 31 </div>
51 32
62 plone/formwidget/multifile/widget.py
@@ -66,6 +66,8 @@ class MultiFileWidget(MultiWidget):
66 66 klass = u'multi-file-widget'
67 67
68 68 input_template = ViewPageTemplateFile('input.pt')
  69 + display_template = ViewPageTemplateFile('display.pt')
  70 + file_template = ViewPageTemplateFile('file_template.pt')
69 71
70 72 @property
71 73 def better_context(self):
@@ -73,12 +75,15 @@ def better_context(self):
73 75
74 76 def render(self):
75 77 self.update()
76   - return self.input_template(self)
  78 + if self.mode == 'input':
  79 + return self.input_template(self)
  80 + else:
  81 + return self.display_template(self)
77 82
78 83 def editing(self):
79 84 return self.mode == 'input'
80 85
81   - def get_value(self):
  86 + def get_data(self):
82 87 """
83 88 """
84 89 if self.value:
@@ -92,27 +97,43 @@ def get_value(self):
92 97 converted_value = converter.toFieldValue(self.value)
93 98 for i, key_or_file in enumerate(self.value):
94 99 if isinstance(key_or_file, unicode):
95   - key = key_or_file
96 100 file_ = converted_value[i]
97   - download_url = None
  101 + yield self.render_file(file_, value=key_or_file)
98 102
99 103 else:
100   - key = 'index:%i' % i
101   - file_ = key_or_file
102   - view_name = self.name[len(self.form.prefix):]
103   - view_name = view_name[len(self.form.widgets.prefix):]
104   - download_url = '%s/++widget++%s/%i/@@download/%s' % (
105   - self.request.getURL(),
106   - view_name,
107   - i,
108   - file_.filename
109   - )
110   -
111   - yield {'value': key,
112   - 'icon': get_icon_for(self.better_context, file_),
113   - 'filename': file_.filename,
114   - 'size': round(file_.getSize() / 1024.0),
115   - 'download_url': download_url}
  104 + yield self.render_file(key_or_file, index=i)
  105 +
  106 + def render_file(self, file_, value=None, index=None, context=None):
  107 + """Renders the <li> for one file.
  108 + """
  109 + if context == None:
  110 + context = self.better_context
  111 +
  112 + if value == None and index == None:
  113 + raise ValueError('Either value or index expected')
  114 +
  115 + if value == None:
  116 + value = 'index:%i' % index
  117 + view_name = self.name[len(self.form.prefix):]
  118 + view_name = view_name[len(self.form.widgets.prefix):]
  119 + download_url = '%s/++widget++%s/%i/@@download/%s' % (
  120 + self.request.getURL(),
  121 + view_name,
  122 + index,
  123 + file_.filename
  124 + )
  125 +
  126 + options = {'value': value,
  127 + 'icon': '/'.join((context.portal_url(),
  128 + get_icon_for(context, file_))),
  129 + 'filename': file_.filename,
  130 + 'size': int(round(file_.getSize() / 1024)),
  131 + 'download_url': download_url,
  132 + 'widget': self,
  133 + 'editable': self.mode == 'input',
  134 + }
  135 +
  136 + return self.file_template(**options)
116 137
117 138
118 139 def update(self):
@@ -192,6 +213,7 @@ def __call__(self):
192 213 file_ = self.request.form['Filedata']
193 214 # in some cases the context is the view, so lets walk up
194 215 # and search the real context
  216 +
195 217 context = self.context
196 218 while IBrowserView.providedBy(context):
197 219 context = aq_parent(aq_inner(context))

0 comments on commit 5be97f0

Please sign in to comment.
Something went wrong with that request. Please try again.