def _clone_email_templates(self, new_event): attrs = get_simple_column_attrs(AbstractEmailTemplate) - {'rules'} for old_tpl in self.old_event.abstract_email_templates: tpl = AbstractEmailTemplate() tpl.populate_from_attrs(old_tpl, attrs) tpl.rules = filter(None, map(self._clone_email_template_rule, old_tpl.rules)) new_event.abstract_email_templates.append(tpl)
def _migrate_email_templates(self): assert bool(dict(self.amgr._notifTpls.iteritems())) == bool( self.amgr._notifTplsOrder) pos = 1 for old_tpl in self.amgr._notifTplsOrder: title = convert_to_unicode(old_tpl._name) body = self._convert_email_template(old_tpl._tplBody) subject = self._convert_email_template( old_tpl._tplSubject) or 'Your Abstract Submission' reply_to_address = strict_sanitize_email(old_tpl._fromAddr, self.default_email) extra_cc_emails = sorted( set( filter(None, map(strict_sanitize_email, old_tpl._ccAddrList)))) include_submitter = any( x.__class__.__name__ == 'NotifTplToAddrSubmitter' for x in old_tpl._toAddrs) include_authors = any( x.__class__.__name__ == 'NotifTplToAddrPrimaryAuthors' for x in old_tpl._toAddrs) if not body: self.print_warning( '%[yellow!]Template "{}" has no body'.format(title)) continue tpl = AbstractEmailTemplate(title=title, position=pos, reply_to_address=reply_to_address, subject=subject, body=body, extra_cc_emails=extra_cc_emails, include_submitter=include_submitter, include_authors=include_authors, include_coauthors=bool( getattr(old_tpl, '_CAasCCAddr', False))) pos += 1 self.print_info('%[white!]Email Template:%[reset] {}'.format( tpl.title)) self.event.abstract_email_templates.append(tpl) self.email_template_map[old_tpl] = tpl rules = [] for old_cond in old_tpl._conditions: # state try: state = self.CONDITION_MAP[old_cond.__class__.__name__] except KeyError: self.print_error( '%[red!]Invalid condition type: {}'.format( old_cond.__class__.__name__)) continue if state == AbstractState.rejected: track = contrib_type = any else: # track if getattr(old_cond, '_track', '--any--') == '--any--': track = any elif getattr(old_cond, '_track', '--any--') == '--none--': track = None else: try: track = self.event_ns.track_map.get( old_cond._track) except KeyError: self.print_warning( '%[yellow!]Invalid track: {}'.format( old_cond._track)) continue # contrib type if hasattr(old_cond, '_contrib_type_id'): contrib_type_id = old_cond._contrib_type_id if contrib_type_id == '--any--': contrib_type = any elif contrib_type_id == '--none--': contrib_type = None else: contrib_type = self.event.contribution_types.filter_by( id=contrib_type_id).one() elif not hasattr(old_cond, '_contribType'): contrib_type = any self.print_warning( '%[yellow]No contrib type data, using any [{}]'. format(old_cond.__dict__)) else: contrib_type = None self.print_error( '%[red!]Legacy contribution type not found: {}'. format(old_cond._contribType)) _any_str = '%[green]any%[reset]' self.print_success( '%[white!]Condition:%[reset] {} | {} | {}'.format( state.name, track if track is not any else _any_str, contrib_type if contrib_type is not any else _any_str)) rule = {'state': [state.value]} if track is not any: rule['track'] = [track.id if track else None] if contrib_type is not any: rule['contribution_type'] = [ contrib_type.id if contrib_type else None ] rules.append(rule) if not rules: self.print_warning( '%[yellow]Template "{}" has no rules'.format(tpl.title), always=False) tpl.rules = rules # submission notification reply_to_address = strict_sanitize_email(self.conf._supportInfo._email, self.default_email) try: old_sn = self.amgr._submissionNotification except AttributeError: emails = [] else: emails = old_sn._toList + old_sn._ccList tpl = AbstractEmailTemplate( title='Abstract submitted', position=pos, reply_to_address=reply_to_address, subject='Abstract Submission confirmation (#{abstract_id})', body=self.SUBMISSION_NOTIFICATION_BODY, extra_cc_emails=sorted( set(filter(None, map(strict_sanitize_email, emails)))), include_submitter=True, rules=[{ 'state': [AbstractState.submitted.value] }]) self.event.abstract_email_templates.append(tpl)
def _migrate_email_templates(self): assert bool(dict(self.amgr._notifTpls.iteritems())) == bool(self.amgr._notifTplsOrder) pos = 1 for old_tpl in self.amgr._notifTplsOrder: title = convert_to_unicode(old_tpl._name) body = self._convert_email_template(old_tpl._tplBody) subject = self._convert_email_template(old_tpl._tplSubject) or 'Your Abstract Submission' reply_to_address = strict_sanitize_email(old_tpl._fromAddr, self.importer.default_email) extra_cc_emails = sorted(set(filter(None, map(strict_sanitize_email, old_tpl._ccAddrList)))) include_submitter = any(x.__class__.__name__ == 'NotifTplToAddrSubmitter' for x in old_tpl._toAddrs) include_authors = any(x.__class__.__name__ == 'NotifTplToAddrPrimaryAuthors' for x in old_tpl._toAddrs) if not body: self.importer.print_warning(cformat('%{yellow!}Template "{}" has no body').format(title), event_id=self.event.id) continue tpl = AbstractEmailTemplate(title=title, position=pos, reply_to_address=reply_to_address, subject=subject, body=body, extra_cc_emails=extra_cc_emails, include_submitter=include_submitter, include_authors=include_authors, include_coauthors=bool(getattr(old_tpl, '_CAasCCAddr', False))) pos += 1 self.importer.print_info(cformat('%{white!}Email Template:%{reset} {}').format(tpl.title)) self.event.abstract_email_templates.append(tpl) self.email_template_map[old_tpl] = tpl rules = [] for old_cond in old_tpl._conditions: # state try: state = self.CONDITION_MAP[old_cond.__class__.__name__] except KeyError: self.importer.print_error(cformat('%{red!}Invalid condition type: {}') .format(old_cond.__class__.__name__), event_id=self.event.id) continue if state == AbstractState.rejected: track = contrib_type = any else: # track if getattr(old_cond, '_track', '--any--') == '--any--': track = any elif getattr(old_cond, '_track', '--any--') == '--none--': track = None else: try: track = self.track_map[old_cond._track] except KeyError: self.importer.print_warning(cformat('%{yellow!}Invalid track: {}').format(old_cond._track), event_id=self.event.id) continue # contrib type if hasattr(old_cond, '_contrib_type_id'): contrib_type_id = old_cond._contrib_type_id if contrib_type_id == '--any--': contrib_type = any elif contrib_type_id == '--none--': contrib_type = None else: contrib_type = self.event.contribution_types.filter_by(id=contrib_type_id).one() elif not hasattr(old_cond, '_contribType'): contrib_type = any self.importer.print_warning(cformat('%{yellow}No contrib type data, using any [{}]') .format(old_cond.__dict__), event_id=self.event.id) else: contrib_type = None self.importer.print_error(cformat('%{red!}Legacy contribution type found: {}') .format(old_cond._contribType), event_id=self.event.id) _any_str = cformat('%{green}any%{reset}') self.importer.print_success(cformat('%{white!}Condition:%{reset} {} | {} | {}') .format(state.name, track if track is not any else _any_str, contrib_type if contrib_type is not any else _any_str), event_id=self.event.id) rule = {'state': [state.value]} if track is not any: rule['track'] = [track.id if track else None] if contrib_type is not any: rule['contribution_type'] = [contrib_type.id if contrib_type else None] rules.append(rule) if not rules: self.importer.print_warning(cformat('%{yellow}Template "{}" has no rules').format(tpl.title), event_id=self.event.id, always=False) tpl.rules = rules # submission notification reply_to_address = strict_sanitize_email(self.conf._supportInfo._email, self.importer.default_email) try: old_sn = self.amgr._submissionNotification except AttributeError: emails = [] else: emails = old_sn._toList + old_sn._ccList tpl = AbstractEmailTemplate(title='Abstract submitted', position=pos, reply_to_address=reply_to_address, subject='Abstract Submission confirmation (#{abstract_id})', body=self.SUBMISSION_NOTIFICATION_BODY, extra_cc_emails=sorted(set(filter(None, map(strict_sanitize_email, emails)))), include_submitter=True, rules=[{'state': [AbstractState.submitted.value]}]) self.event.abstract_email_templates.append(tpl)