add options on "add attachment" workflow item
This commit is contained in:
parent
4f3cbb85d3
commit
dc9530c6a5
|
@ -74,8 +74,6 @@ def form_attachment(self):
|
|||
return FileStream(fd, size)
|
||||
|
||||
|
||||
|
||||
|
||||
class AttachmentEvolutionPart:
|
||||
orig_filename = None
|
||||
base_filename = None
|
||||
|
@ -118,10 +116,17 @@ class AttachmentEvolutionPart:
|
|||
return htmltext('<p><a href="attachment?f=%s">%s</a>' % (
|
||||
os.path.basename(self.filename), self.orig_filename))
|
||||
|
||||
|
||||
class AddAttachmentWorkflowStatusItem(WorkflowStatusItem):
|
||||
description = N_('Allow Addition of an Attachment')
|
||||
key = 'addattachment'
|
||||
|
||||
title = None
|
||||
display_title = True
|
||||
button_label = None
|
||||
display_button = True
|
||||
required = False
|
||||
hint = None
|
||||
by = []
|
||||
|
||||
def init(cls):
|
||||
|
@ -129,20 +134,38 @@ class AddAttachmentWorkflowStatusItem(WorkflowStatusItem):
|
|||
FormStatusPage.attachment = form_attachment
|
||||
init = classmethod(init)
|
||||
|
||||
def render_as_line(self):
|
||||
if self.by:
|
||||
return _('Allow Addition of an Attachment by %s') % render_list_of_roles(self.by)
|
||||
else:
|
||||
return _('Allow Addition of an Attachment (not completed)')
|
||||
|
||||
def fill_form(self, form, formdata, user):
|
||||
form.add(FileWidget, 'attachment', title = _('Upload File'), required = True)
|
||||
form.add_submit('button%s' % self.id, _('Upload File'))
|
||||
if self.display_title:
|
||||
title = self.title or _('Upload File')
|
||||
else:
|
||||
title = None
|
||||
form.add(FileWidget, 'attachment%s' % self.id, title=title,
|
||||
required=self.required, hint=self.hint)
|
||||
if self.display_button:
|
||||
form.add_submit('button%s' % self.id, self.button_label or _('Upload File'))
|
||||
|
||||
def submit_form(self, form, formdata, user, evo):
|
||||
if form.get_submit() == 'button%s' % self.id:
|
||||
f = form.get_widget('attachment').parse()
|
||||
if form.get_widget('attachment%s' % self.id):
|
||||
f = form.get_widget('attachment%s' % self.id).parse()
|
||||
if f is None:
|
||||
form.set_error('attachment', _('Missing file'))
|
||||
if self.required:
|
||||
form.set_error('attachment%s' % self.id, _('Missing file'))
|
||||
return
|
||||
evo.add_part(AttachmentEvolutionPart(f))
|
||||
|
||||
def fill_admin_form(self, form):
|
||||
form.add(WidgetList, 'by', title = _('By'), element_type = SingleSelectWidget,
|
||||
def get_parameters(self):
|
||||
return ('by', 'required', 'title', 'display_title', 'button_label', 'display_button', 'hint')
|
||||
|
||||
def add_parameters_widgets(self, form, parameters, prefix='', formdef=None):
|
||||
if 'by' in parameters:
|
||||
form.add(WidgetList, '%sby' % prefix, title = _('By'),
|
||||
element_type = SingleSelectWidget,
|
||||
value = self.by,
|
||||
add_element_label = _('Add Role'),
|
||||
element_kwargs = {'render_br': False,
|
||||
|
@ -151,12 +174,19 @@ class AddAttachmentWorkflowStatusItem(WorkflowStatusItem):
|
|||
('_receiver', _('Receiver')),
|
||||
(logged_users_role().id, logged_users_role().name),
|
||||
(None, '----')] + get_user_roles()})
|
||||
if 'required' in parameters:
|
||||
form.add(CheckboxWidget, '%srequired' % prefix, title = _('Required'), value = self.required)
|
||||
if 'title' in parameters:
|
||||
form.add(StringWidget, '%stitle' % prefix, size=40, title=_('Title'), value=self.title or _('Upload File'))
|
||||
if 'display_title' in parameters:
|
||||
form.add(CheckboxWidget, '%sdisplay_title' % prefix, title = _('Display Title'), value = self.display_title)
|
||||
if 'button_label' in parameters:
|
||||
form.add(StringWidget, '%sbutton_label' % prefix, title=_('Button Label'),
|
||||
value=self.button_label or _('Upload File'))
|
||||
if 'display_button' in parameters:
|
||||
form.add(CheckboxWidget, '%sdisplay_button' % prefix, title = _('Display Button'), value = self.display_button)
|
||||
if 'hint' in parameters:
|
||||
form.add(StringWidget, '%shint' % prefix, size=40, title=_('Hint'), value=self.hint)
|
||||
|
||||
|
||||
def submit_admin_form(self, form):
|
||||
for f in ('by',):
|
||||
widget = form.get_widget(f)
|
||||
if widget:
|
||||
setattr(self, f, widget.parse())
|
||||
|
||||
register_item_class(AddAttachmentWorkflowStatusItem)
|
||||
|
|
Loading…
Reference in New Issue