def create_message(self, subject, from_, to, content, cc=None, bcc=None, type='plain', mpart_type='mixed', attachments=()): """Sends an e-mail using the mail section configuration of the application. Parameters: * `subject` -- the subject of the mail, * `from_` -- the sender, * `to` -- the receiver or list of receivers, * `content` -- the content of the mail, * `cc` -- the eventual CC or list of CC, * `bcc` -- the eventual BCC or list of BCC, * `type` -- the eventual type of the email, either `'plain'` or `'html'`. * `mpart_type` -- the eventual custom ``MIMEMultipart`` type ('mixed' or 'related') (defaults to mixed) * `attachments` -- the eventual list of attachments to add """ # converts recipients to list and provide an empty list for None to = [to] if is_string(to) else to cc = [cc] if is_string(cc) else (cc or []) bcc = [bcc] if is_string(bcc) else (bcc or []) # always adds the hidden recipients if self.hidden_recipients: bcc += self.hidden_recipients # creates the message envelop msg = MIMEMultipart(mpart_type) msg['Subject'] = subject msg['Date'] = formatdate(localtime=True) if self.reply_to: msg['From'] = self.reply_to msg['Reply-to'] = from_ else: msg['From'] = from_ msg['To'] = COMMASPACE.join(to) if cc: msg['Cc'] = COMMASPACE.join(cc) # attaches the mail content if isinstance(content, unicode): content = content.encode('UTF-8') msg.attach(MIMEText(content, type, _charset='UTF-8')) # eventually completes the message with attachments for attachment in attachments: self.add_file_attachment(msg, *attachment) # log the email logger = log.get_logger('.' + __name__) logger.debug('Sending mail: from=%r, to=%r, cc=%r, bcc=%r, subject=%r', from_, to, cc, bcc, subject) logger.debug('Mail content:\n' + content) return msg
def __init__(self, user, with_cancel=False): super(PasswordEditor, self).__init__(None) self.uid = user if is_string(user) else user.uid self.password = editor.Property('').validate(self.validate_password) self.password_confirm = editor.Property('').validate( self.validate_password_confirm) self.with_cancel = with_cancel
def __init__(self, user): super(UserFIEditor, self).__init__(None) self.uid = user if is_string(user) else user.uid self.user_repository = UserRepository() fi_uid = self.user.fi.uid if self.user.fi else '' self.fi_uid = editor.Property(fi_uid).validate( validators.non_empty_string)
def validate_file(data, max_size=None, msg=_L(u'Size must be less than %d KB')): """ Validate a 'file' input data against the max size in KB """ # check against the first roundtrip with the client if data is None or is_string(data): return None if data.done == -1: raise ValueError(_L(u'Transfer was interrupted')) # gets the file size (it's a StringIO) data.file.seek(0, 2) # 0 from EOF filesize = data.file.tell() data.file.seek(0) if max_size is not None and filesize > max_size * 1024: raise ValueError(msg % max_size) filedata = data.file.read() filename = ntpath.basename(unicode(data.filename)) return {'filename': filename, 'filedata': filedata, 'content_type': unicode(data.type)}
def render_group_composition_item(self, r, item, style): if is_string(item): r << r.cell(item, colspan=4, style=style + r.Style.Wrap + r.Border.RightMedium) else: corporation, direction, service, site = item r << r.cell(corporation, style=style) r << r.cell(direction, style=style) r << r.cell(service, style=style) r << r.cell(site, style=style + r.Border.RightMedium)
def __init__(self, parent, user, query, label="All Ideas", batch_size=10): self.parent = parent # FIXME: WTF? event_management._register_listener(self, self) self.user_uid = user if is_string(user) else user.uid self._query = query self.pager = component.Component(None) self.state_id = None self.show_proxy_ideas = False
def __init__(self, v, strip=True, rstrip=False, lstrip=False, chars=None, msg=_L(u'Must be a string')): # fix a nagare bug where StringValidator accepts None but fail in the not_empty check if v is not None and not is_string(v): # we accept None or a string raise ValueError(msg) if v is None: # strip will crash if the given value is None... strip = False super(ExtendedStringValidator, self).__init__(remove_invalid_chars(v), strip, rstrip, lstrip, chars)
def __init__(self, user): super(ProfileEditor, self).__init__(None) self.uid = user if is_string(user) else user.uid # editable fields self.description = editor.Property(self.user.description or '') self.competencies = editor.Property(self.user.competencies or '') self.hobbies = editor.Property(self.user.hobbies or '') self.expertises = editor.Property(self.user.expertises or '') self.specialty = editor.Property(self.user.specialty or '') self.work_phone = editor.Property(self.user.work_phone or '') self.mobile_phone = editor.Property(self.user.mobile_phone or '')
def _validate_thumbnail(self, f): if is_string(f): return None if f.done == -1: raise ValueError(_(u'Transfer was interrupted')) # finds out the filename (I.E. 4 returns the on-disk path) self.thumbnail_filename = f.filename.split('\\')[-1] try: return tools.create_thumbnail(f.file, 870, 271) except IOError as e: errno, strerror = e log.exception('thumbnail reception error: %s', strerror) raise IOError(errno, _(u'Reception error'))
def __init__(self, parent, user, selected_tab=None, online_shop=None): self.parent = parent event_management._register_listener(parent, self) self.uid = user if is_string(user) else user.uid self.user_repository = UserRepository() self.user_comp = User(parent, self.uid) self.tabs = self._create_tabs() selected_tab = selected_tab if selected_tab in self.tabs else 'profile' self.selected_tab = var.Var(selected_tab) # inner components displayed in the tabs or the header # FIXME: all these should be wrapped into a component.Component self.fi_editor = UserFIEditor(self.uid) event_management._register_listener(self, self.fi_editor) self.avatar_editor = AvatarEditor(self.uid) event_management._register_listener(self, self.avatar_editor) self.password_editor = PasswordEditor(self.user) event_management._register_listener(self, self.password_editor) self.profile_editor = ProfileEditor(self.user) event_management._register_listener(self, self.profile_editor) self.settings_editor = component.Component(SettingsEditor(self.user)) event_management._register_listener(self, self.settings_editor()) self.idea_pager = self._create_pager() # FIXME: the pager should not depend on the parent # event_management._register_listener(self, self.idea_pager) self.online_shop = online_shop(self) self.tab_labels = { 'profile': _("My Profile") if self.is_mine else _("Her Profile"), 'settings': _("My Settings") if self.is_mine else _("Her Settings"), 'tracked_ideas': (_("My Tracked Ideas") if self.is_mine else _("Her Tracked Ideas")) + " (%d)" % self.new_events_count(), 'ideas': (_("My Ideas") if self.is_mine else _("Her Ideas")) + " (%d)" % self.ideas_count, 'points': (_("My Points") if self.is_mine else _("Her Points")) + " (%d)" % self.user.acquired_points, # 'rank': self.user.status_level_label, } self.menu_items = [(self.tab_labels[name], name, None, '', None) for name in self.tabs] self.menu = component.Component(Menu(self.menu_items), model='tab_renderer') self.menu.on_answer(self.select_tab) if selected_tab: index_tab = self.tabs.index(selected_tab) else: index_tab = 0 self.select_tab(index_tab)
def __init__(self, user): super(HomeSettingsEditor, self).__init__(None) self.uid = user if is_string(user) else user.uid home_settings = self.user.home_settings self.show_progressing_ideas = editor.Property( home_settings.show_progressing_ideas) self.show_tracked_ideas = editor.Property( home_settings.show_tracked_ideas) self.show_challenges_ideas = editor.Property( home_settings.show_challenges_ideas) selected_domains = [domain.id for domain in home_settings.domains] self.domains_choice = editor.Property(selected_domains) self.keyword_filter = editor.Property( home_settings.keyword_filter).validate(validator.StringValidator) self.period_filter = editor.Property(home_settings.period_filter) self.users_filter = editor.Property( ', '.join([u.email for u in home_settings.users_filter])).validate( validator.StringValidator)
def __init__(self, user): super(HomeSettingsEditor, self).__init__(None) self.uid = user if is_string(user) else user.uid home_settings = self.user.home_settings self.show_progressing_ideas = editor.Property( home_settings.show_progressing_ideas) self.show_tracked_ideas = editor.Property( home_settings.show_tracked_ideas) self.show_challenges_ideas = editor.Property( home_settings.show_challenges_ideas) selected_domains = [domain.id for domain in home_settings.domains] self.domains_choice = editor.Property(selected_domains) self.keyword_filter = editor.Property( home_settings.keyword_filter).validate(validator.StringValidator) self.period_filter = editor.Property(home_settings.period_filter) self.users_filter = editor.Property(', '.join([ u.email for u in home_settings.users_filter ])).validate(validator.StringValidator)
def __init__(self, user, expiration_delay=timedelta(days=1)): self.uid = user if is_string(user) else user.uid self.token_generator = TokenGenerator(self._encryption_key(), expiration_delay)
def validate_img(self, photo): if is_string(photo): return None return photo.file.read()
def __init__(self, user): super(AvatarEditor, self).__init__(None) self.uid = user if is_string(user) else user.uid self.photo = editor.Property(self.user.photo).validate( self.validate_img)
def __init__(self, user): super(MailSettingsEditor, self).__init__(None) self.uid = user if is_string(user) else user.uid self.mail_delivery_frequency = editor.Property( self.user.mail_delivery_frequency)
def _uid(self, user=None): if user is None: user = get_current_user() assert user return user if is_string(user) else user.uid
def __init__(self, parent, user): event_management._register_listener(parent, self) self.uid = user if is_string(user) else user.uid self.user_repository = UserRepository() self.pager = None