class ICookieBannerSettings(Interface): """Settings for the Cookie Consent banner """ accept_on_click = schema.Bool( title=_(u'Accept policy on every click'), description=_( 'help_accept_on_click', default= u'If checked, any click on links on any page will be interpreted as the ' # noqa u'user accepted the cookie policy.'), required=False, default=False, ) cookie_consent_configuration = schema.Tuple( title=_(u'Cookie consent configuration'), description=_( 'help_cookie_consent_configuration', default= u'For every involved language, provide a configuration of the cookie consent banner.\n' # noqa u'The first defined policy configuration will be the default ones ' # noqa u'(the ones used when not language specific configuration is found).' ), # noqa value_type=CookieBannerEntryPersistentObject( ICookieBannerEntry, title=_(u'Cookie consent banner configuration')), # noqa required=False, default=(), missing_value=(), )
class IOptOutEntrySubitem(Interface): """A single translation entry for a OutOut configuration See IOptOutEntry """ lang = schema.Choice( title=_(u'Language'), defaultFactory=default_language, missing_value=u'', required=True, vocabulary=u'rer.cookieconsent.vocabularies.AvailableLanguages', ) app_title = schema.TextLine( title=_(u'Application name'), description=_( 'app_title_help', default=u'This will be the title used in the opt-out configuration dashboard.', ), # noqa default=u'', missing_value=u'', required=False, ) app_description = schema.Text( title=_(u'Application description'), description=_( 'app_description_help', default=u'A long description that must explain what this opt-out will do if activated.\n' # noqa u'You can also use HTML here.', ), default=u'', missing_value=u'', required=False, )
class ICookieBannerEntry(Interface): """Single entry for the Cookie Consent banner configuration """ lang = schema.Choice( title=_(u'Language'), defaultFactory=default_language, missing_value=u'', required=True, vocabulary=u'rer.cookieconsent.vocabularies.AvailableLanguages') text = schema.Text( title=_(u'Cookie consent banner content'), description=_( 'text_help', default= u'Provide the text to be put inside the cookie consent banner.\n' # noqa u'You can use HTML here but you can avoid it.\n' # noqa u'Use the "$privacy_link" marker to insert an HTML link to the Privacy Policy (see below).\n' # noqa u'If you want full controls over the HTML generated you can use the "$privacy_link_url" marker ' # noqa u'(URL of the link) and "$privacy_link_text" (text of the link).\n' # noqa u'In the same way you can use "$dashboard_link", "$dashboard_link_url" and "$dashboard_text" ' # noqa u'to provide links to the opt-out dashboard.'), # noqa default=u'', missing_value=u'', required=True, ) privacy_link_url = schema.TextLine( title=_(u'URL of the Privacy Policy'), description=_( 'privacy_link_url_help', default= u'An URL, or a absolute path, to a page where user can read the full ' # noqa u'Privacy Policy of your site.\n' # noqa u'Examples: "http://externalsite.com/privacy.html", "/internal/document".' ), # noqa required=False, ) privacy_link_text = schema.TextLine( title=_(u'Text of the Privacy Policy link'), description=_( 'privacy_link_text_help', default= u'The text to be used when generating the URL specified in the ' # noqa u'URL of the Privacy Policy".\n' u'If not provided, the full URL is used.'), required=False, ) dashboard_link_text = schema.TextLine( title=_(u'Text of the link to opt-out dashboard'), description=_( 'dashboard_link_text', default= u'The text to be used when generating the URL to the opt-out dashboard' ), # noqa required=False, )
class IOptOutEntry(Interface): """Single entry for an Opt-Out application configuration """ app_id = schema.ASCIILine( title=_(u'Application ID'), description=_( 'app_id_help', default=u'A unique identifier for the application influenced bt this opt-out', ), # noqa default='', missing_value='', required=True, ) cookies = schema.Tuple( title=_(u'Cookies'), description=_( 'cookies_help', default=u'A list of cookies names prefixes.\n' u'This opt-out will generate a cookie in the form PREFIX-optout for every defined prefix.', ), # noqa required=True, value_type=schema.ASCIILine(), ) default_value = schema.Choice( title=_(u'Cookie(s) initial value'), description=_( 'default_value_help', default=u'When a user access for the first time the site, all of the opt-out cookies are set.\n' # noqa u'You must select the default value for those cookies.', ), # noqa required=True, default='true', vocabulary=trueFalseVocabulary, ) texts = schema.Tuple( title=_(u'Opt-out entry titles and descriptions'), description=_( 'help_optout_texts', default=u'For every involved language provide title and description that will be used ' # noqa u'for generate an translated opt-out dashboard.\n' u'In the case a specific translation is missing, the first in the list will be ' # noqa u'used as default.\n' u'If this field is not filler, a translation for "APPID_optout_title" ' # noqa u'and "APPID_optout_description" will be used.', ), value_type=OptOutEntrySubitemPersistentObject( IOptOutEntrySubitem, title=_(u'Opt-out title and description') ), required=False, default=(), missing_value=(), )
def __call__(self, *args, **kwargs): if 'form.submitted' in self.request.form: self._save_changes() IStatusMessage(self.request).addStatusMessage(_(u"Changes saved"), "info") self.request.response.redirect("%s/@@%s" % (self.context.absolute_url(), self.__name__),) return self.index()
def __call__(self, *args, **kwargs): if 'form.submitted' in self.request.form: self._save_changes() api.portal.show_message(message=_(u'Changes saved'), type='info', request=self.request) self.request.response.redirect('{0}/@@{1}'.format( self.context.absolute_url(), self.__name__)) return self.index()
def handleSave(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return self.cleanHTML(data) self.applyChanges(data) IStatusMessage(self.request).addStatusMessage(_(u"Changes saved"), "info") self.context.REQUEST.RESPONSE.redirect("@@%s" % self.__name__)
class IOptOutSettings(Interface): """Settings for the Optout""" optout_configuration = schema.Tuple( title=_(u'Opt-out configurations'), description=_( 'help_optout_configuration', default=u'When the user accepted the general cookie policy he can still accept/decline ' # noqa u'a single kind of cookie(s) from a 3rd part application.\n' # noqa u'From this panel you can configure opt-out cookies for those applications.\n' # noqa u'PLEASE NOTE: this product will only handle and generate cookies, is duty of ' # noqa u'others products to use those cookies in the correct manner.', ), # noqa value_type=OptOutEntryPersistentObject( IOptOutEntry, title=_(u'Opt-out configuration') ), required=False, default=(), missing_value=(), )
def __call__(self, *args, **kwargs): if 'form.submitted' in self.request.form: self._save_changes() api.portal.show_message( message=translate(_(u'Changes saved'), context=self.request), type='info', request=self.request) next = self.request.form.get('came_from', None) if next and api.portal.get_tool('portal_url').isURLInPortal(next): pass else: next = self.context.absolute_url() self.request.response.redirect(next) return self.index()
class FormOptOut(group.Group): label = _(u"Opt-out dashboard") fields = field.Fields(IOptOutSettings)
def _i18n_alternative(self, app_id, id): oo_i18n_id = u"%s_optout_%s" % (app_id, id) oo_item = translate(_(oo_i18n_id), context=self.request) if unicode(oo_item)==oo_i18n_id: return app_id return oo_item
def _i18n_alternative(self, app_id, id): oo_i18n_id = u'{0}_optout_{1}'.format(app_id, id) oo_item = translate(_(oo_i18n_id), context=self.request) if six.text_type(oo_item) == oo_i18n_id: return app_id return oo_item
def handleCancel(self, action): IStatusMessage(self.request).addStatusMessage(_(u"Changes cancelled"), "info") self.request.response.redirect( "%s/%s" % (self.context.absolute_url(), self.control_panel_view))
class CookieConsentSettingsEditForm(controlpanel.RegistryEditForm): """Media settings form. """ schema = ICookieConsentSettings #fields = field.Fields(ICookieBannerSettings) groups = (FormCookieConsentBanner, FormOptOut) id = "CookieConsentSettingsEditForm" label = _(u"Cookie consent configuration") description = _(u"Configuration of the cookie consent in the site") def cleanHTML(self, data): """ clean text in the given data, so the user can't insert dangerous html (for example cross-site scripting) """ pt = api.portal.get_tool('portal_transforms') for configuration in data['cookie_consent_configuration']: text = configuration.text if not text: continue safe_text = pt.convert('safe_html', text) configuration.text = safe_text.getData() @button.buttonAndHandler(pmf('Save'), name='save') def handleSave(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return self.cleanHTML(data) self.applyChanges(data) IStatusMessage(self.request).addStatusMessage(_(u"Changes saved"), "info") self.context.REQUEST.RESPONSE.redirect("@@%s" % self.__name__) @button.buttonAndHandler(pmf('Cancel'), name='cancel') def handleCancel(self, action): IStatusMessage(self.request).addStatusMessage(_(u"Changes cancelled"), "info") self.request.response.redirect( "%s/%s" % (self.context.absolute_url(), self.control_panel_view)) # def updateWidgets(self): # super(CookieConsentSettingsEditForm, self).updateWidgets() # for main_widget in self.widgets['cookie_consent_configuration'].widgets: # for main_widget in self.groups[0].fields['cookie_consent_configuration'].widgets: # widgets = main_widget.subform.widgets # fix_widget_style(error_widgets['text']) # widgets['privacy_link_url'].style = u'width: 100%' # widgets['privacy_link_text'].style = u'width: 100%' def update(self): super(CookieConsentSettingsEditForm, self).update() for fieldset in self.groups: widgets = fieldset.widgets if 'cookie_consent_configuration' in widgets: for main_widget in widgets[ 'cookie_consent_configuration'].widgets: widgets = main_widget.subform.widgets fix_widget_style(widgets['text']) widgets['privacy_link_url'].style = u"width: 100%" widgets['privacy_link_text'].size = 40 widgets['dashboard_link_text'].size = 40 if 'optout_configuration' in widgets: for main_widget in widgets['optout_configuration'].widgets: widgets = main_widget.subform.widgets for subwidget in widgets['texts'].widgets: widgets = subwidget.subform.widgets fix_widget_style(widgets['app_description']) widgets['app_title'].style = u"width: 100%"
def handleCancel(self, action): IStatusMessage(self.request).addStatusMessage(_(u"Changes cancelled"), "info") self.request.response.redirect("%s/%s" % (self.context.absolute_url(), self.control_panel_view))
class FormCookieConsentBanner(group.Group): label = _(u"Cookie consent banner") fields = field.Fields(ICookieBannerSettings)