class SearchUser(form.Form): fields = field.Fields(ISearchUser) ignoreContext = True fields['results'].widgetFactory = CustomCheckBoxFieldWidget prefix = 'search_user' template = FiveViewPageTemplateFile('search_user.pt') _parent_form = None def __init__(self, context, request, parent_form=None): super(SearchUser, self).__init__(context, request) self._parent_form = parent_form @button.buttonAndHandler(_('Search'), name='search_user') def handleSave(self, action): data, errors = self.extractData() if errors: return False @button.buttonAndHandler(_('Add'), name='addCC') def handle_addCC(self, action): data, errors = self.extractData() self._parent_form.widgets['cc'].value += '\n'+"\n".join(data['results']) del self.widgets['results'].items self.widgets['results'].value = '' if errors: return False
class SendEmail(form.Form): fields = field.Fields(IEmail) ignoreContext = True label = _(u"Send email") fields['receiver'].widgetFactory = CheckBoxFieldWidget prefix = 'send_email' template = FiveViewPageTemplateFile('main_form.pt') def update(self): super(SendEmail, self).update() self.search_user = SearchUser(self.context, self.request, self) self.search_user.update() @button.buttonAndHandler(_('Send Email'), name='send_email') def handleSave(self, action): data, errors = self.extractData() if errors: return False types = api.portal.get_tool('portal_types') type_info = types.getTypeInfo('eea.meeting.email') name_chooser = INameChooser(self.context) content_id = name_chooser.chooseName(data['subject'], self.context) obj = type_info._constructInstance(self.context, content_id) obj.title = data['subject'] obj.sender = data['sender'] obj.receiver = "\r\n".join(data['receiver']) data['receiver'] = obj.receiver obj.cc = data['cc'] obj.subject = data['subject'] obj.body = data['body'] obj.reindexObject() notify(SendEmailAddEvent(self.context, data)) msg = _(u"Email successfully sent") IStatusMessage(self.request).addStatusMessage(msg, type='info') self.request.response.redirect(self.context.getParentNode().absolute_url())
class TypesEditFormWrapper(FormWrapper): """ Render Plone frame around our form with little modifications """ form = TypeEditForm index = FiveViewPageTemplateFile("typesformwrapper.pt")
obj = brain.getObject() items.append(obj) for item in items: changed = False ppath = '/'.join(item.getPhysicalPath()) if self.replace_portlet_text( context=item, mode=data['text_replace_mode'], fields=data['text_replace_fields'], destination=data['text_replace_destination'], source=data['text_replace_source']): changed = True if changed: ilogs.append( '<li><a href="%s" target="_new">%s</a> portlets changed</li>\n' % (ppath, item.absolute_url())) if ilogs: ilogs.insert(0, u"<strong>MassChange complete</strong>") ilogs.insert(0, u"<ul>") ilogs.append('</ul>') self.logs.extend(ilogs) self.logs = '\n'.join(self.logs) masschangeportlets_form_frame = plone.z3cform.layout.wrap_form( MassChangePortletsForm, index=FiveViewPageTemplateFile("masschange_portlets.pt"))
types = api.portal.get_tool('portal_types') type_info = types.getTypeInfo('eea.meeting.email') name_chooser = INameChooser(self.context) content_id = name_chooser.chooseName(data['subject'], self.context) obj = type_info._constructInstance(self.context, content_id) obj.title = data['subject'] obj.sender = data['sender'] obj.receiver = "\r\n".join(data['receiver']) data['receiver'] = obj.receiver obj.cc = data['cc'] obj.subject = data['subject'] obj.body = data['body'] obj.reindexObject() notify(SendEmailAddEvent(self.context, data)) msg = _(u"Email successfully sent") IStatusMessage(self.request).addStatusMessage(msg, type='info') self.request.response.redirect(self.context.getParentNode().absolute_url()) SendEmailView = wrap_form(SendEmail, index=FiveViewPageTemplateFile("send_email.pt"))
ilogs.append('</ul>') self.logs.extend(ilogs) self.logs = '\n'.join(self.logs) for k in ('keywords', 'local_keywords',): component.provideAdapter( z3c.form.widget.ComputedWidgetAttribute( default_keywords, field=IMassChangeSchema[k], view=MassChangeForm), name="default") masschange_form_frame = plone.z3cform.layout.wrap_form( MassChangeForm, index=FiveViewPageTemplateFile("masschange.pt")) class DeduplicateKeywords(BrowserView): def __call__(self, *args, **kwargs): catalog = getToolByName(self.context, 'portal_catalog') keywords = catalog.uniqueValuesFor(u'Subject') normalized_keywords = {} for keyword in keywords: normalized_keyword = baseNormalize(magicstring(keyword.strip()).decode('utf-8')).strip() normalized_keywords.setdefault(normalized_keyword, []).append(keyword) pkm = getToolByName(self.context, 'portal_keyword_manager') putils = getToolByName(self.context, "plone_utils") for normalized_keyword, keywords in normalized_keywords.iteritems():
random_id = normalizer.normalize(time.time()) filename = "export_{0}.{1}".format(random_id, 'xlsx') dataset = export_file(results, header_mapping, self.request) #log.debug(filename) #log.debug(attachment) self.request.response.setHeader( 'content-type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ) self.request.response.setHeader('Content-Disposition', 'attachment; filename="%s"' % filename) self.request.response.setBody(dataset.xlsx, lock=True) return True @button.buttonAndHandler(u"Cancel") def handleCancel(self, action): api.portal.show_message( message=_( "import_message_cancel", # nopep8 default="Import canceled."), request=self.request, type="info") self.request.response.redirect(self.context.absolute_url()) # IF you want to customize form frame you need to make a custom FormWrapper view around it # (default plone.z3cform.layout.FormWrapper is supplied automatically with form.py templates) #report_form_frame = plone.z3cform.layout.wrap_form(ReportForm, index=FiveViewPageTemplateFile("templates/reporter.pt")) ImportView = wrap_form(ImportForm, index=FiveViewPageTemplateFile("import_view.pt"))
htmltext = create_userbody(data) msg_txt = MIMEText(htmltext, _subtype='html', _charset='utf-8') msgAlternative.attach(msg_txt) mail_host = ploneapi.portal.get_tool(name='MailHost') mail_host.send(mime_msg.as_string()) self.output = dict(country="foobar") self.status = _(u"Report complete") thankmessage = u"Vielen Dank für Ihre Bestellung. Diese ist bei uns eingegangen. Sie erhalten in wenigen Minuten eine\ Bestellbestätigung per E-Mail." message = ploneapi.portal.show_message(message=thankmessage, request=self.request, type='info') url = self.context.absolute_url() return self.request.response.redirect(url) @button.buttonAndHandler(u'Abbrechen') def handleCancel(self, action): data, errors = self.extractData() url = self.context.absolute_url() return self.request.response.redirect(url) # do something order_form_frame = plone.z3cform.layout.wrap_form( SendOrder, index=FiveViewPageTemplateFile("order.pt"))
default=None) is None: IStatusMessage(self.request).addStatusMessage( _('status_mirror_content_not_found', u'Did not find container ${path}.', mapping={'path': container_path}), 'warning') return False # Copy and bind for l in languages: l = str(l) container_path = '/'.join((l, ) + relative_path[:-1]) container = portal.unrestrictedTraverse(container_path) target = api.content.copy(self.context, container) recursively_bind_translation(self.context, target, l, keep_workflow_states) IStatusMessage(self.request).addStatusMessage( _('status_mirror_content_success', u'Contents successfully mirrored for ${languages}.', mapping={'languages': ', '.join(languages)}), 'info') redirect_url = "%s/@@%s" % (self.context.absolute_url(), self.__name__) self.request.response.redirect(redirect_url) ## @brief Wrapper (including a custom template to show protection information) MirrorContentFormView = wrap_form( MirrorContentForm, index=FiveViewPageTemplateFile("templates/mirror_content.pt"))
normalizer = getUtility(IIDNormalizer) random_id = normalizer.normalize(time.time()) filename = "export_{0}.{1}".format(random_id, 'csv') attachment = export_file(results, header_mapping, self.request) #log.debug(filename) #log.debug(attachment) self.request.response.setHeader('content-type', 'text/csv') self.request.response.setHeader( 'Content-Disposition', 'attachment; filename="%s"' % filename) self.request.response.setBody(attachment, lock=True) return True @button.buttonAndHandler(u"Cancel") def handleCancel(self, action): api.portal.show_message( message=_("import_message_cancel", # nopep8 default="Import canceled."), request=self.request, type="info") self.request.response.redirect(self.context.absolute_url()) # IF you want to customize form frame you need to make a custom FormWrapper view around it # (default plone.z3cform.layout.FormWrapper is supplied automatically with form.py templates) #report_form_frame = plone.z3cform.layout.wrap_form(ReportForm, index=FiveViewPageTemplateFile("templates/reporter.pt")) ImportView = wrap_form(ImportForm, index=FiveViewPageTemplateFile("import_view.pt"))