class NewsletterControlPanelForm(controlpanel.RegistryEditForm): """ """ schema = INewsletterSettings label = _('control_panel_newsletter_label', default=u'Newsletter') description = _('control_panel_newsletter_desc', default=u'Newsletter-relevant settings.')
def getMenuItems(self, context, request): menu = super(TranslateMenu, self).getMenuItems(context, request) url = context.absolute_url() is_neutral_content = ( ILanguage(context).get_language() == LANGUAGE_INDEPENDENT or is_language_independent(context) ) if not is_neutral_content and not INavigationRoot.providedBy(context): if ITranslatable.providedBy(context) and getSecurityManager().checkPermission('Manage portal', context): menu.append({ "title": _( u"title_mirror_content", default=u"Mirror this object to other languages" ), "description": _( u"description_mirror_content", default=u"" ), "action": url + "/mirror_content", "selected": False, "icon": None, "extra": { "id": "_mirror_content", "separator": None, "class": "" }, "submenu": None, }) return menu
class INewsletterSettings(Interface): """Settings for newsletter. """ mailing_list_address = schema.TextLine( title=_("mailing_list_address", default=u"Mailing list address"), description=_( "mailing_list_address_description", default= u"When the mailing list address is [email protected], this entry should be [email protected]. This only works for mailman as system." ), default=None, required=True)
def handle_mirror_content(self, action): self.submitted = True data, errors = self.extractData() if errors: return False languages = data['languages'] keep_workflow_states = data['keep_workflow_states'] self.output = None context = self.context portal = api.portal.get() # Relative from LRF object relative_path = context.getPhysicalPath( )[len(portal.getPhysicalPath()) + 1:] # Check precondition for l in languages: l = str(l) # Check for container container_path = '/'.join((l, ) + relative_path[:-1]) if portal.unrestrictedTraverse(container_path, 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)
class IMirrorContent(Interface): """ """ languages = List( title=_(u'Languages'), description=_( u'Choose the languages you wish to translate this content object.' ), value_type=Choice(source=available_languages_provider), required=True, missing_value=[]) keep_workflow_states = Bool( title=_(u'Keep workflow states?'), description= _(u'If checked, copied contents will also have the same state of the original content. Otherwise, it will be in the initial state (e.g. private).' ), default=True, )
def handle_unsubscribe(self, action): data, errors = self.extractData() if errors: return False self.send_mail( message=u'unsubscribe address=' + data['email'], send_to_address=self.mailing_list_address, ) IStatusMessage(self.request).addStatusMessage( _( 'status_message_newsletter_unsubscribed', u'A request for unsubscribing the newsletter has been sent. Please check your emails to confirm this action.' ), 'info') self.request.response.redirect(self.request.URL)
def send_mail(self, message, send_to_address, subject=None): registry = getUtility(IRegistry) mail_settings = registry.forInterface(IMailSchema, prefix='plone') from_address = mail_settings.email_from_address registry = getUtility(IRegistry) encoding = registry.get('plone.email_charset', 'utf-8') host = api.portal.get_tool('MailHost') message = MIMEText(message, 'plain', encoding) try: # This actually sends out the mail host.send(message, send_to_address, from_address, subject=subject, charset=encoding) except (SMTPException, RuntimeError), e: log.error(e) plone_utils = api.portal.get_tool('plone_utils') exception = plone_utils.exceptionString() message = _(u'Unable to send mail: ${exception}', mapping={u'exception': exception}) IStatusMessage(self.request).add(message, type=u'error')
class NewsletterForm(form.Form): """ """ fields = field.Fields(INewsletterForm) ignoreContext = True label = _('newsletter_form_label', default=u"Newsletter") description = _( 'newsletter_form_description', u"Please enter your email address to (un-)subscribe to LLA-Newsletter." ) @property def mailing_list_address(self): registry = getUtility(IRegistry) newsletter_settings = registry.forInterface(INewsletterSettings) return newsletter_settings.mailing_list_address @button.buttonAndHandler(_('newsletter_subscribe', default=u'Subscribe')) def handle_subscribe(self, action): data, errors = self.extractData() if errors: return False self.send_mail( message=u'subscribe address=' + data['email'], send_to_address=self.mailing_list_address, ) IStatusMessage(self.request).addStatusMessage( _( 'status_message_newsletter_subscribed', u'A request for subscribing the newsletter has been sent. Please check your emails to confirm this action.' ), 'info') self.request.response.redirect(self.request.URL) @button.buttonAndHandler( _('newsletter_unsubscribe', default=u'Unsubscribe')) def handle_unsubscribe(self, action): data, errors = self.extractData() if errors: return False self.send_mail( message=u'unsubscribe address=' + data['email'], send_to_address=self.mailing_list_address, ) IStatusMessage(self.request).addStatusMessage( _( 'status_message_newsletter_unsubscribed', u'A request for unsubscribing the newsletter has been sent. Please check your emails to confirm this action.' ), 'info') self.request.response.redirect(self.request.URL) def send_mail(self, message, send_to_address, subject=None): registry = getUtility(IRegistry) mail_settings = registry.forInterface(IMailSchema, prefix='plone') from_address = mail_settings.email_from_address registry = getUtility(IRegistry) encoding = registry.get('plone.email_charset', 'utf-8') host = api.portal.get_tool('MailHost') message = MIMEText(message, 'plain', encoding) try: # This actually sends out the mail host.send(message, send_to_address, from_address, subject=subject, charset=encoding) except (SMTPException, RuntimeError), e: log.error(e) plone_utils = api.portal.get_tool('plone_utils') exception = plone_utils.exceptionString() message = _(u'Unable to send mail: ${exception}', mapping={u'exception': exception}) IStatusMessage(self.request).add(message, type=u'error')
class INewsletterForm(Interface): """ """ email = Email(title=_('newsletter_email_address', default=u'Your email address'), )
class MirrorContentForm(form.Form): """Form to mirror content from place within a language folder to a different one. """ fields = field.Fields(IMirrorContent) ignoreContext = True label = _('mirror_content_form_label', default=u"Mirror this object to other languages.") description = _( 'mirror_content_form_description', u"With this form you can replicate the current object and its children from this language folder into another language folders. You still have to make sure, that the container path is present in the destination location." ) output = None submitted = False @property def already_translated(self): tm = ITranslationManager(self.context) return tm.get_translations() ## @brief Definition of the button and handler for removing protection @button.buttonAndHandler( _('button_mirror_content', default=u'Mirror content')) def handle_mirror_content(self, action): self.submitted = True data, errors = self.extractData() if errors: return False languages = data['languages'] keep_workflow_states = data['keep_workflow_states'] self.output = None context = self.context portal = api.portal.get() # Relative from LRF object relative_path = context.getPhysicalPath( )[len(portal.getPhysicalPath()) + 1:] # Check precondition for l in languages: l = str(l) # Check for container container_path = '/'.join((l, ) + relative_path[:-1]) if portal.unrestrictedTraverse(container_path, 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)