def handle_subscribe(self, action): if self.data.use_captcha: captcha = getMultiAdapter((aq_inner(self.data), self.request), name="recaptcha") if not captcha.verify(): raise WidgetActionExecutionError( "captcha", Invalid( _("Please check the captcha to prove you're a human")), ) data, errors = self.extractData() if errors: return email = data.get("email") account_id, list_id = self.data.newsletter_list.split("|") sendinblue = getUtility(ISendinblueAPI) success = sendinblue.subscribe(account_id, list_id, email) if success: api.portal.show_message( _("You are successfully subscribed to the newsletter !"), request=self.request, type="info", ) else: api.portal.show_message( _("An error occured while triyng to subscribe to the newsletter" ), request=self.request, type="error", ) url = self.request.ACTUAL_URL self.request.response.redirect(url)
class ISendinbluePortlet(IPortletDataProvider): header = schema.TextLine( title=_("Portlet header"), description=_("Title of the rendered portlet"), required=True, ) description = schema.TextLine( title=_("Portlet description"), description=_("Description of the rendered portlet"), required=False, ) newsletter_list = schema.Choice( title=_("List"), description=_("Select list to enable subscriptions to"), required=True, vocabulary="collective.sendinblue.vocabularies.AvailableLists", ) archive_url = schema.TextLine( title=_("Archive link"), description=_("Link to a page where you store previous newsletters"), required=False, ) use_captcha = schema.Bool( title=_("Use captcha"), description=_( "Use a captcha to protect your subscription form against robots"), default=True, )
class INewsletterRedirectionSubscribe(Interface): email = schema.Email( title=_("Email address"), description=_("help_email", default="Please enter your email address."), required=True, )
class INewsletterSubscribe(Interface): email = schema.Email( title=_("Email address"), description=_("help_email", default="Please enter your email address."), required=True, ) captcha = schema.TextLine(title="Captcha", description="", required=False)
class PortletSubscribeForm(Form): fields = field.Fields(INewsletterSubscribe) ignoreContext = True fields["captcha"].widgetFactory = ReCaptchaFieldWidget fields["email"].widgetFactory = ParameterizedWidget( None, placeholder=_("Email address"), ) def __init__(self, context, request, data=None): super(PortletSubscribeForm, self).__init__(context, request) self.data = data def update(self): if not self.data.use_captcha: self.fields = self.fields.omit("captcha") super(PortletSubscribeForm, self).update() @button.buttonAndHandler(_("Subscribe"), name="subscribe") def handle_subscribe(self, action): if self.data.use_captcha: captcha = getMultiAdapter((aq_inner(self.data), self.request), name="recaptcha") if not captcha.verify(): raise WidgetActionExecutionError( "captcha", Invalid( _("Please check the captcha to prove you're a human")), ) data, errors = self.extractData() if errors: return email = data.get("email") account_id, list_id = self.data.newsletter_list.split("|") sendinblue = getUtility(ISendinblueAPI) success = sendinblue.subscribe(account_id, list_id, email) if success: api.portal.show_message( _("You are successfully subscribed to the newsletter !"), request=self.request, type="info", ) else: api.portal.show_message( _("An error occured while triyng to subscribe to the newsletter" ), request=self.request, type="error", ) url = self.request.ACTUAL_URL self.request.response.redirect(url)
class EditForm(base.EditForm): schema = ISendinbluePortlet label = _("Edit Sendinblue Portlet") description = _( "This portlet displays a subscription form for a Sendinblue newsletter." ) def update(self): sendinblue = getUtility(ISendinblueAPI) sendinblue.updateCache() super(EditForm, self).update()
class SendinblueSettingsEditForm(controlpanel.RegistryEditForm): schema = ISendinblueSettings label = _("Sendinblue settings") description = _("Sendinblue integration for Plone") def update(self): self.updateCache() super(SendinblueSettingsEditForm, self).update() def updateCache(self): sendinblue = getUtility(ISendinblueAPI) sendinblue.updateCache()
class EditForm(base.EditForm): schema = IRedirectionSendinbluePortlet label = _("Edit redirect Sendinblue Portlet") description = _( "This portlet displays a redirect form to a Sendinblue list subscribe form." ) def update(self): sendinblue = getUtility(ISendinblueAPI) sendinblue.updateCache() super(EditForm, self).update()
class IRedirectionSendinbluePortlet(IPortletDataProvider): header = schema.TextLine( title=_("Portlet header"), description=_("Title of the rendered portlet"), required=True, ) description = schema.TextLine( title=_("Portlet description"), description=_("Description of the rendered portlet"), required=False, ) url = schema.TextLine( title=_("Base url to redirect to"), description=_("Base url of the registration form to redirect to"), required=True, ) text = RichText( title=_("Text"), description=_("Others informations and descriptions"), required=False, )
class ISendinblueSettings(Interface): """ Global sendinblue settings. This describes records stored in the configuration registry and obtainable via plone.registry. """ api_keys = schema.List( title=_("Sendinblue API Key(s)"), description=_( "help_api_keys", default="Enter in your Sendinblue key here. If you have several" + " Sendinblue accounts, you can enter one key per line." + " Log into https://account.sendinblue.com/advanced/api" + " and copy the API Key to this field.", ), value_type=schema.TextLine(title=_("API Key")), default=[], required=True, )
class AddForm(base.AddForm): schema = IRedirectionSendinbluePortlet label = _("Add redirect Sendinblue Portlet") description = _( "This portlet displays a redirect form to a Sendinblue list subscribe form." ) def update(self): sendinblue = getUtility(ISendinblueAPI) sendinblue.updateCache() super(AddForm, self).update() def create(self, data): return Assignment( header=data.get("header", ""), description=data.get("description", ""), text=data.get("text", ""), url=data.get("url", ""), )
class PortletSubscribeForm(Form): fields = field.Fields(INewsletterRedirectionSubscribe) ignoreContext = True fields["email"].widgetFactory = ParameterizedWidget( None, placeholder=_("Email address"), ) def __init__(self, context, request, data=None): super(PortletSubscribeForm, self).__init__(context, request) self.data = data @button.buttonAndHandler(_("Subscribe"), name="subscribe") def handle_subscribe(self, action): data, errors = self.extractData() if errors: return email = data.get("email") url = self.data.url self.request.response.redirect("{}{}".format(url, email))
class AddForm(base.AddForm): schema = ISendinbluePortlet label = _("Add Sendinblue Portlet") description = _( "This portlet displays a subscription form for a Sendinblue newsletter." ) def update(self): sendinblue = getUtility(ISendinblueAPI) sendinblue.updateCache() super(AddForm, self).update() def create(self, data): return Assignment( header=data.get("header", ""), description=data.get("description", ""), newsletter_list=data.get("newsletter_list", ""), archive_url=data.get("archive_url", ""), use_captcha=data.get("use_captcha", True), )