def __call__(self): # get the surf theme objects themes = self.load_objects_from_rdf() self.default_language = get_default_language() self.available_languages = get_available_languages_iso() self.available_languages_title = get_available_languages_title() # map the properties self.mapping = { 'dct_title': 'skos_prefLabel', 'skos_inScheme': 'skos_inScheme', 'dc_identifier': 'dc_identifier', } self.count = 0 for theme in themes: self.update(theme) msg = _('Imported ${count} concepts items.', mapping={ 'count': self.count, }) msg = translate(msg, context=self.request) portal.show_message(message=msg, request=self.request) url = '/'.join([ portal.get().absolute_url(), FOLDER_CONCEPTS, ]) self.request.response.redirect(url) return u''
def __call__(self): catalog = getToolByName(self.context, 'portal_catalog') if 'submit' in self.request.form: counter = 0 for cityid in self.request.form['city']: for b in catalog.searchResults(id=[cityid.lower()]): city = b.getObject() city._reset_secret_key() notify(ResetTokenEvent(city)) # send_newtoken_email(city) counter += 1 show_message("{0} Email(s) sent".format(counter), request=self.request, type='info') return self.request.response.redirect(self.context.absolute_url()) cat = self.context.portal_catalog q = {'portal_type': 'eea.climateadapt.city_profile'} self.res = [brain.getObject() for brain in cat.searchResults(**q)] return self.index()
def update(self, theme): params = {} for key, value in self.mapping.items(): attribute = getattr(theme, value) # deal wth more than one attribute, e.g. different languages # in Literals if isinstance(attribute.first, rdflib.term.Literal): att_data = {} for literal in attribute: lang = getattr(literal, 'language', self.default_language) lang = str(lang) if lang in self.available_languages: lang = self.available_languages[lang] att_data[lang] = str(literal) if not att_data: att_data = str(attribute.first) else: if not attribute.first: att_data = None else: att_data = str(attribute.first) params[key] = att_data # Use subject as rdfabout att_data = str(getattr(theme, 'subject')) params['rdfs_isDefinedBy'] = att_data params = self.get_foaf_depiction(params, att_data) # Todo : Check for collisions. Probably not by title but by # rdfs_isDefinedBy if not params['dct_title']: params['dct_title'] = params['dc_identifier'] # create a skos:concept object try: if isinstance(params['dc_identifier'], dict): id = params['dc_identifier'][self.default_language] else: id = params['dc_identifier'] if isinstance(params['dct_title'], dict): title = params['dct_title'][self.default_language] else: title = params['dct_title'] content.create(container=self.context, type=CT_SKOS_CONCEPT, id=id, title=title, **params) except Exception as e: # noqa: B902 portal.show_message(message=str(e), request=self.request) return else: self.count += 1
def update(self): filter = self.request.get('filter') or None if not filter: return recipients = self.send_mail(filter) message = _(u"E-mail envoyé à") message = '%s: %s' % (message, ', '.join(recipients)) show_message(message, self.request, type='info')
def __call__(self): data = self.get_data() tmpl_field = self.context.getField('pdf_body_pt') compiled_tmpl = tmpl_field.get(self.context, **data) if isinstance(compiled_tmpl, Message): # we got an error... show_message(self.err_msg) return else: fname = self.context.getId() return self._render_pdf(compiled_tmpl, fname=fname)
def handleApply(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return if 'captcha' in data: # Verify the user input against the captcha captcha = CaptchaValidator(self.context, self.request, None, IContactFooterForm['captcha'], None) try: valid = captcha.validate(data['captcha']) except WrongCaptchaCode: show_message(message=u"Invalid Captcha.", request=self.request, type='error') return if valid: mail_host = api.portal.get_tool(name='MailHost') info = { 'name': data.get('name'), 'mail': data.get('email'), 'url': self.context.absolute_url() } text = """ Climate Adapt Website You are receiving this mail because %(name)s %(mail)s is sending feedback about the site you administer at %(url)s. """ % info mime_msg = MIMEText(data.get('message') + text) mime_msg['Subject'] = data.get('subject') mime_msg['From'] = data.get('email') mime_msg['To'] = str(api.portal.getSite().email_from_address) self.description = u"Email Sent." IStatusMessage(self.request).addStatusMessage("Email SENT", 'info') return mail_host.send(mime_msg.as_string()) else: self.description = u"Please complete the Captcha."
def handleApply(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return action = data['workflow_action'] msg = data['message'].strip() IAnnotations(self.request)[ANNOT_KEY] = msg notify(WorkflowMessageEvent(self.context)) transition(obj=self.context, transition=action, comment=msg) self.status = msg = u"Message will be further processed." show_message(message=msg, request=self.request, type='info') return self.request.response.redirect(self.context.absolute_url())
def __call__(self): if not self.request.method == 'POST': return if not self.context.can_reset_token(): raise Unauthorized("You are not allowed to send token email") email = self.context.official_email if email: #send_newtoken_email(self.context) notify(ResetTokenEvent(self.context)) show_message("Email Sent to {0}".format(email), request=self.request, type="info") else: show_message("Official email is not set", request=self.request, type="error") return self.request.response.redirect(self.context.absolute_url())
def __call__(self): if not self.request.method == 'POST': return if not self.context.can_reset_token(): raise Unauthorized("You are not allowed to send token email") email = self.context.official_email if email: # send_newtoken_email(self.context) notify(ResetTokenEvent(self.context)) show_message("Email Sent to {0}".format(email), request=self.request, type="info") else: show_message("Official email is not set", request=self.request, type="error") return self.request.response.redirect(self.context.absolute_url())
def handleApply(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return msg = u"""Registration process completed. You will receive an email message with details on how to proceed further.""" if data.has_key('captcha'): # Verify the user input against the captcha captcha = CaptchaValidator(self.context, self.request, None, IRegisterCityForm['captcha'], None) try: valid = captcha.validate(data['captcha']) except WrongCaptchaCode: show_message(message=u"Invalid Captcha.", request=self.request, type='error') return if valid: name = data.get('name') email = data.get('email') obj = CityProfileRegister(name=name, email=email) obj = obj.__of__(self.context) notify(CityProfileRegisterEvent(obj)) show_message(message=msg, request=self.request, type='info') else: show_message(message=u"Please complete the Captcha.", request=self.request, type='error')
def handleApply(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return if 'captcha' in data: # Verify the user input against the captcha captcha = CaptchaValidator(self.context, self.request, None, IContactForm['captcha'], None) try: valid = captcha.validate(data['captcha']) except WrongCaptchaCode: show_message(message=u"Invalid Captcha.", request=self.request, type='error') return if valid: mail_host = api.portal.get_tool(name='MailHost') # emailto = str(api.portal.getSite().email_from_address) mime_msg = MIMEText(data.get('message')) mime_msg['Subject'] = data.get('feedback') mime_msg['From'] = data.get('email') # mime_msg['To'] = ','.join(b for b in CONTACT_MAIL_LIST) # mime_msg['To'] = CONTACT_MAIL_LIST for m in CONTACT_MAIL_LIST: mime_msg['To'] = m self.description = u"Email Sent." IStatusMessage(self.request).addStatusMessage( "Email SENT", 'info') return mail_host.send(mime_msg.as_string()) else: self.description = u"Please complete the Captcha."
def __call__(self): # get the surf license objects objects = self.load_objects_from_rdf() # Import the licenses into dexterity objects good_count, ignored_count = self.import_objects(objects) # Todo : Logging or response to user msg = _("""Imported ${good_count} ${object_title} items. Ignored ${ignored_count} ${object_title} items.""", mapping={ 'object_title': self.object_title, 'good_count': good_count, 'ignored_count': ignored_count, }) msg = translate(msg, context=self.request) portal.show_message(message=msg, request=self.request) url = '/'.join([ portal.get().absolute_url(), self.target_folder, ]) self.request.response.redirect(url) return u''
def __call__(self): catalog = getToolByName(self.context, 'portal_catalog') if 'submit' in self.request.form: counter = 0 for cityid in self.request.form['city']: for b in catalog.searchResults(id=[cityid.lower()]): city = b.getObject() city._reset_secret_key() notify(ResetTokenEvent(city)) #send_newtoken_email(city) counter += 1 show_message("{0} Email(s) sent".format(counter), request=self.request, type='info') return self.request.response.redirect(self.context.absolute_url()) cat = self.context.portal_catalog q = { 'portal_type': 'eea.climateadapt.city_profile' } self.res = [brain.getObject() for brain in cat.searchResults(**q)] return self.index()
def handleApply(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return captcha = getMultiAdapter( (aq_inner(self.context), self.request), name='recaptcha' ) msg = u"""Registration process completed. You will receive an email message with details on how to proceed further.""" if captcha.verify(): name = data.get('name') email = data.get('email') obj = CityProfileRegister(name=name, email=email) obj = obj.__of__(self.context) notify(CityProfileRegisterEvent(obj)) show_message(message=msg, request=self.request, type='info') else: show_message(message=u"Please complete the Captcha.", request=self.request, type='error')
def test_show_message_constraints(self): """Test the constraints for show_message.""" from plone.api.exc import MissingParameterError # When no parameters are given an error is raised with self.assertRaises(MissingParameterError): portal.show_message() # message and request are required with self.assertRaises(MissingParameterError): portal.show_message(request=self.layer['request']) with self.assertRaises(MissingParameterError): portal.show_message(message='Beer is brewing.')
def test_show_message(self): from Products.statusmessages.interfaces import IStatusMessage request = self.layer['request'] portal.show_message(message='Blueberries!', request=request) messages = IStatusMessage(request) show = messages.show() self.assertEquals(len(show), 1) self.assertTrue('Blueberries!' in show[0].message) portal.show_message(message='One', request=request) portal.show_message(message='Two', request=request) messages = IStatusMessage(request) show = messages.show() self.assertEqual(len(show), 2) self.assertEqual(show[0].message, 'One') self.assertEqual(show[1].message, 'Two')
def test_show_message(self): """Test to see if message appears.""" from Products.statusmessages.interfaces import IStatusMessage request = self.layer['request'] portal.show_message(message='Blueberries!', request=request) messages = IStatusMessage(request) show = messages.show() self.assertEqual(len(show), 1) self.assertIn('Blueberries!', show[0].message) portal.show_message(message='One', request=request) portal.show_message(message='Two', request=request) messages = IStatusMessage(request) show = messages.show() self.assertEqual(len(show), 2) self.assertEqual(show[0].message, 'One') self.assertEqual(show[1].message, 'Two')
def test_show_message(self): """Test to see if message appears.""" from Products.statusmessages.interfaces import IStatusMessage request = self.layer["request"] portal.show_message(message="Blueberries!", request=request) messages = IStatusMessage(request) show = messages.show() self.assertEqual(len(show), 1) self.assertIn("Blueberries!", show[0].message) portal.show_message(message="One", request=request) portal.show_message(message="Two", request=request) messages = IStatusMessage(request) show = messages.show() self.assertEqual(len(show), 2) self.assertEqual(show[0].message, "One") self.assertEqual(show[1].message, "Two")
def _display_message(self, message, type): portal.show_message( message, self.request, type=type, )