122 |
122 |
description = N_('Allow Addition of an Attachment')
|
123 |
123 |
key = 'addattachment'
|
124 |
124 |
|
|
125 |
title = 0
|
|
126 |
button_label = 0
|
|
127 |
required = False
|
|
128 |
hint = None
|
125 |
129 |
by = []
|
126 |
130 |
|
127 |
131 |
def init(cls):
|
... | ... | |
129 |
133 |
FormStatusPage.attachment = form_attachment
|
130 |
134 |
init = classmethod(init)
|
131 |
135 |
|
|
136 |
def render_as_line(self):
|
|
137 |
if self.by:
|
|
138 |
return _('Allow Addition of an Attachment by %s') % render_list_of_roles(self.by)
|
|
139 |
else:
|
|
140 |
return _('Allow Addition of an Attachment (not completed)')
|
|
141 |
|
132 |
142 |
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'))
|
|
143 |
if self.title == 0:
|
|
144 |
title = _('Upload File')
|
|
145 |
else:
|
|
146 |
title = self.title
|
|
147 |
form.add(FileWidget, 'attachment%s' % self.id, title=title,
|
|
148 |
required=self.required, hint=self.hint)
|
|
149 |
if self.button_label == 0:
|
|
150 |
form.add_submit('button%s' % self.id, _('Upload File'))
|
|
151 |
elif self.button_label:
|
|
152 |
form.add_submit('button%s' % self.id, self.button_label)
|
135 |
153 |
|
136 |
154 |
def submit_form(self, form, formdata, user, evo):
|
137 |
|
if form.get_submit() == 'button%s' % self.id:
|
138 |
|
f = form.get_widget('attachment').parse()
|
|
155 |
if form.get_widget('attachment%s' % self.id):
|
|
156 |
f = form.get_widget('attachment%s' % self.id).parse()
|
139 |
157 |
if f is None:
|
140 |
|
form.set_error('attachment', _('Missing file'))
|
|
158 |
if self.required:
|
|
159 |
form.set_error('attachment', _('Missing file'))
|
141 |
160 |
return
|
142 |
161 |
evo.add_part(AttachmentEvolutionPart(f))
|
143 |
162 |
|
144 |
|
def fill_admin_form(self, form):
|
145 |
|
form.add(WidgetList, 'by', title = _('By'), element_type = SingleSelectWidget,
|
|
163 |
def get_parameters(self):
|
|
164 |
return ('by', 'required', 'title', 'button_label', 'hint')
|
|
165 |
|
|
166 |
def add_parameters_widgets(self, form, parameters, prefix='', formdef=None):
|
|
167 |
if 'by' in parameters:
|
|
168 |
form.add(WidgetList, '%sby' % prefix, title = _('By'),
|
|
169 |
element_type = SingleSelectWidget,
|
146 |
170 |
value = self.by,
|
147 |
171 |
add_element_label = _('Add Role'),
|
148 |
172 |
element_kwargs = {'render_br': False,
|
... | ... | |
151 |
175 |
('_receiver', _('Receiver')),
|
152 |
176 |
(logged_users_role().id, logged_users_role().name),
|
153 |
177 |
(None, '----')] + get_user_roles()})
|
|
178 |
if 'required' in parameters:
|
|
179 |
form.add(CheckboxWidget, '%srequired' % prefix,
|
|
180 |
title = _('Required'),
|
|
181 |
value = self.required)
|
|
182 |
if 'title' in parameters:
|
|
183 |
if self.title == 0:
|
|
184 |
self.title = _('Upload File')
|
|
185 |
form.add(StringWidget, '%stitle' % prefix, size=40, title=_('Title'), value=self.title)
|
|
186 |
if 'button_label' in parameters:
|
|
187 |
if self.button_label == 0:
|
|
188 |
self.button_label = _('Upload File')
|
|
189 |
form.add(StringWidget, '%sbutton_label' % prefix, title=_('Button Label'),
|
|
190 |
hint=_('(empty to disable the button)'),
|
|
191 |
value=self.button_label)
|
|
192 |
if 'hint' in parameters:
|
|
193 |
form.add(StringWidget, '%shint' % prefix, size=40, title=_('Hint'), value=self.hint)
|
154 |
194 |
|
155 |
195 |
|
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 |
196 |
register_item_class(AddAttachmentWorkflowStatusItem)
|