74 |
74 |
return FileStream(fd, size)
|
75 |
75 |
|
76 |
76 |
|
77 |
|
|
78 |
|
|
79 |
77 |
class AttachmentEvolutionPart:
|
80 |
78 |
orig_filename = None
|
81 |
79 |
base_filename = None
|
... | ... | |
118 |
116 |
return htmltext('<p><a href="attachment?f=%s">%s</a>' % (
|
119 |
117 |
os.path.basename(self.filename), self.orig_filename))
|
120 |
118 |
|
|
119 |
|
121 |
120 |
class AddAttachmentWorkflowStatusItem(WorkflowStatusItem):
|
122 |
121 |
description = N_('Allow Addition of an Attachment')
|
123 |
122 |
key = 'addattachment'
|
124 |
123 |
|
|
124 |
title = None
|
|
125 |
display_title = True
|
|
126 |
button_label = None
|
|
127 |
display_button = True
|
|
128 |
required = False
|
|
129 |
hint = None
|
125 |
130 |
by = []
|
126 |
131 |
|
127 |
132 |
def init(cls):
|
... | ... | |
129 |
134 |
FormStatusPage.attachment = form_attachment
|
130 |
135 |
init = classmethod(init)
|
131 |
136 |
|
|
137 |
def render_as_line(self):
|
|
138 |
if self.by:
|
|
139 |
return _('Allow Addition of an Attachment by %s') % render_list_of_roles(self.by)
|
|
140 |
else:
|
|
141 |
return _('Allow Addition of an Attachment (not completed)')
|
|
142 |
|
132 |
143 |
def fill_form(self, form, formdata, user):
|
133 |
|
form.add(FileWidget, 'attachment', title = _('Upload File'), required = True)
|
134 |
|
form.add_submit('button%s' % self.id, _('Upload File'))
|
|
144 |
if self.display_title:
|
|
145 |
title = self.title or _('Upload File')
|
|
146 |
else:
|
|
147 |
title = None
|
|
148 |
form.add(FileWidget, 'attachment%s' % self.id, title=title,
|
|
149 |
required=self.required, hint=self.hint)
|
|
150 |
if self.display_button:
|
|
151 |
form.add_submit('button%s' % self.id, self.button_label or _('Upload File'))
|
135 |
152 |
|
136 |
153 |
def submit_form(self, form, formdata, user, evo):
|
137 |
|
if form.get_submit() == 'button%s' % self.id:
|
138 |
|
f = form.get_widget('attachment').parse()
|
|
154 |
if form.get_widget('attachment%s' % self.id):
|
|
155 |
f = form.get_widget('attachment%s' % self.id).parse()
|
139 |
156 |
if f is None:
|
140 |
|
form.set_error('attachment', _('Missing file'))
|
|
157 |
if self.required:
|
|
158 |
form.set_error('attachment', _('Missing file'))
|
141 |
159 |
return
|
142 |
160 |
evo.add_part(AttachmentEvolutionPart(f))
|
143 |
161 |
|
144 |
|
def fill_admin_form(self, form):
|
145 |
|
form.add(WidgetList, 'by', title = _('By'), element_type = SingleSelectWidget,
|
|
162 |
def get_parameters(self):
|
|
163 |
return ('by', 'required', 'title', 'display_title', 'button_label', 'display_button', 'hint')
|
|
164 |
|
|
165 |
def add_parameters_widgets(self, form, parameters, prefix='', formdef=None):
|
|
166 |
if 'by' in parameters:
|
|
167 |
form.add(WidgetList, '%sby' % prefix, title = _('By'),
|
|
168 |
element_type = SingleSelectWidget,
|
146 |
169 |
value = self.by,
|
147 |
170 |
add_element_label = _('Add Role'),
|
148 |
171 |
element_kwargs = {'render_br': False,
|
... | ... | |
151 |
174 |
('_receiver', _('Receiver')),
|
152 |
175 |
(logged_users_role().id, logged_users_role().name),
|
153 |
176 |
(None, '----')] + get_user_roles()})
|
|
177 |
if 'required' in parameters:
|
|
178 |
form.add(CheckboxWidget, '%srequired' % prefix, title = _('Required'), value = self.required)
|
|
179 |
if 'title' in parameters:
|
|
180 |
form.add(StringWidget, '%stitle' % prefix, size=40, title=_('Title'), value=self.title or _('Upload File'))
|
|
181 |
if 'display_title' in parameters:
|
|
182 |
form.add(CheckboxWidget, '%sdisplay_title' % prefix, title = _('Display Title'), value = self.display_title)
|
|
183 |
if 'button_label' in parameters:
|
|
184 |
form.add(StringWidget, '%sbutton_label' % prefix, title=_('Button Label'),
|
|
185 |
value=self.button_label or _('Upload File'))
|
|
186 |
if 'display_button' in parameters:
|
|
187 |
form.add(CheckboxWidget, '%sdisplay_button' % prefix, title = _('Display Button'), value = self.display_button)
|
|
188 |
if 'hint' in parameters:
|
|
189 |
form.add(StringWidget, '%shint' % prefix, size=40, title=_('Hint'), value=self.hint)
|
154 |
190 |
|
155 |
191 |
|
156 |
|
def submit_admin_form(self, form):
|
157 |
|
for f in ('by',):
|
158 |
|
widget = form.get_widget(f)
|
159 |
|
if widget:
|
160 |
|
setattr(self, f, widget.parse())
|
161 |
|
|
162 |
192 |
register_item_class(AddAttachmentWorkflowStatusItem)
|