def _new_token(self, user_id): """ Generate a token to allow password reset for `user_id`. """ token = ''.join(random.choice(TOKEN_SYMBOL) for c in range(12)) self._get_token_map()[token] = TokenData(user_id) log.info("new password reset token in site %r for user %r: %r", physical_path(self.getSite()), user_id, token) return token
def messages_feed(context, REQUEST=None, format='rss'): """ Atom feed with forum messages under this location """ catalog = context.getSite().getCatalogTool() query = { 'meta_type': [METATYPE_NYFORUMMESSAGE, METATYPE_NYFORUMTOPIC], 'path': physical_path(context), } messages_list = [b.getObject() for b in catalog(**query)] messages_list.sort(key=operator.attrgetter('postdate'), reverse=True) if messages_list: feed_updated = messages_list[0].postdate else: feed_updated = DateTime() options = { 'messages_list': messages_list, 'feed_updated': feed_updated, } if format == 'rss': tmpl = _tmpl_feed_rss content_type = 'application/rss+xml' elif format == 'atom': tmpl = _tmpl_feed_atom content_type = 'application/atom+xml' else: raise ValueError("Unknown feed format %r" % format) if REQUEST is not None: REQUEST.RESPONSE.setHeader('Content-Type', content_type) return tmpl.__of__(context)(**options)
def manage_debug(self, REQUEST): """ Watch for problematic translation strings """ if REQUEST.REQUEST_METHOD == 'POST': form = REQUEST.form self.message_debug_list = form['debug_strings'].splitlines() log.info('%s message_debug_list = %r', physical_path(self), self.message_debug_list) self.message_debug_exception = bool(form.get('debug_exception', False)) location = self.absolute_url() + '/manage_debug' return REQUEST.RESPONSE.redirect(location) return self._manage_debug(REQUEST)
def manage_debug(self, REQUEST): """ Watch for problematic translation strings """ if REQUEST.REQUEST_METHOD == 'POST': form = REQUEST.form self.message_debug_list = form['debug_strings'].splitlines() log.info('%s message_debug_list = %r', physical_path(self), self.message_debug_list) self.message_debug_exception = bool( form.get('debug_exception', False)) location = self.absolute_url() + '/manage_debug' return REQUEST.RESPONSE.redirect(location) return self._manage_debug(REQUEST)
def sendMailToContacts(self, subject='', content='', location='', REQUEST=None): """ """ search = self.getCatalogedObjectsCheckView path = physical_path(self) if location not in ('', '/'): if not location.startswith('/'): location = '/' + location path += location contacts = search(meta_type=['Naaya Contact'], path=path) addresses = [contact.email for contact in contacts] for address in addresses: self.getEmailTool().sendEmail(content, address, self.mail_address_from, subject) if REQUEST: self.setSessionInfoTrans('Mail sent. (${date})', date=self.utGetTodayDate()) REQUEST.RESPONSE.redirect('%s/admin_contacts_html' % self.absolute_url())
def _update(self, portal): query = {'meta_type': ['Naaya TalkBack Consultation']} for brain in portal.getCatalogTool()(**query): consultation = brain.getObject() count = 0 for comment in all_comments(consultation): if comment.contributor_name is None: comment._save_contributor_name() count += 1 consultation_path = physical_path(consultation) if count > 0: self.log.info("%r: %d comments", consultation_path, count) else: self.log.info("%r: nothing to update", consultation_path) return True
def getMailRecipients(self, location='', REQUEST=None): """ """ search = self.getCatalogedObjectsCheckView path = physical_path(self) if location not in ('', '/'): if not location.startswith('/'): location = '/' + location path += location contacts = search(meta_type=['Naaya Contact'], path=path) addresses = set() for contact in contacts: email_address = contact.email.replace(' ', '').replace('[at]', '@').replace('(at)', '@') try: email_address.encode() #if is_valid_email(email_address): addresses.add(email_address) #else: # log.warn('%s is not a valid email address for contact %s at %s' % (contact.email, contact.id, contact.absolute_url())) except UnicodeEncodeError: log.warn('UnicodeEncodeError in email address %s for contact %s at %s' % (contact.email, contact.id, contact.absolute_url())) return json.dumps(list(addresses))
def _set_password(self, user_id, new_password): user = self.getSite().acl_users.getUser(user_id) assert user is not None log.info("changing password in site %r for user %r", physical_path(self.getSite()), user_id) user.__ = new_password