128 |
128 |
'',
|
129 |
129 |
'edit',
|
130 |
130 |
'delete',
|
|
131 |
'duplicate',
|
131 |
132 |
'export',
|
132 |
133 |
('history', 'snapshots_dir'),
|
133 |
134 |
]
|
... | ... | |
149 |
150 |
r += htmltext('<ul id="sidebar-actions">')
|
150 |
151 |
if not self.mail_template.is_readonly():
|
151 |
152 |
r += htmltext('<li><a href="export">%s</a></li>') % _('Export')
|
|
153 |
r += htmltext('<li><a href="duplicate" rel="popup">%s</a></li>') % _('Duplicate')
|
152 |
154 |
r += htmltext('<li><a href="delete" rel="popup">%s</a></li>') % _('Delete')
|
153 |
155 |
if get_publisher().snapshot_class:
|
154 |
156 |
r += htmltext('<li><a rel="popup" href="history/save">%s</a></li>') % _('Save snapshot')
|
... | ... | |
295 |
297 |
filename='mail-template-%s.wcs' % self.mail_template.slug,
|
296 |
298 |
content_type='application/x-wcs-mail-template',
|
297 |
299 |
)
|
|
300 |
|
|
301 |
def duplicate(self):
|
|
302 |
form = Form(enctype='multipart/form-data')
|
|
303 |
name_widget = form.add(StringWidget, 'name', title=_('Name'), required=True, size=30)
|
|
304 |
form.add_submit('submit', _('Submit'))
|
|
305 |
form.add_submit('cancel', _('Cancel'))
|
|
306 |
if form.get_widget('cancel').parse():
|
|
307 |
return redirect('.')
|
|
308 |
|
|
309 |
if not form.is_submitted():
|
|
310 |
original_name = self.mail_template.name
|
|
311 |
new_name = '%s %s' % (original_name, _('(copy)'))
|
|
312 |
names = [x.name for x in MailTemplate.select()]
|
|
313 |
no = 2
|
|
314 |
while new_name in names:
|
|
315 |
new_name = _('%(name)s (copy %(no)d)') % {'name': original_name, 'no': no}
|
|
316 |
no += 1
|
|
317 |
name_widget.set_value(new_name)
|
|
318 |
|
|
319 |
if not form.is_submitted() or form.has_errors():
|
|
320 |
html_top('mail_templates', title=_('Duplicate Mail Template'))
|
|
321 |
r = TemplateIO(html=True)
|
|
322 |
get_response().breadcrumb.append(('duplicate', _('Duplicate')))
|
|
323 |
r += htmltext('<h2>%s</h2>') % _('Duplicate Mail Template')
|
|
324 |
r += form.render()
|
|
325 |
return r.getvalue()
|
|
326 |
|
|
327 |
self.mail_template.id = None
|
|
328 |
self.mail_template.slug = None
|
|
329 |
self.mail_template.name = form.get_widget('name').parse()
|
|
330 |
self.mail_template.store()
|
|
331 |
return redirect('../%s/' % self.mail_template.id)
|
298 |
|
-
|