def _build_context_for_content_update( self, role: UserRoleInWorkspace, content_in_context: ContentInContext, parent_in_context: typing.Optional[ContentInContext], workspace_in_context: WorkspaceInContext, actor: User, translator: Translator, ): _ = translator.get_translation content = content_in_context.content action = content.get_last_action().id previous_revision = content.get_previous_revision() new_status = _(content.get_status().label) workspace_url = workspace_in_context.frontend_url role_label = role.role_as_label() logo_url = get_email_logo_frontend_url(self.config) # FIXME: remove/readapt assert to debug easily broken case # assert user # assert workspace # assert main_title # assert status_label # # assert status_icon_url # assert role_label # # assert content_intro # assert content_text or content_text == content.description # assert logo_url return { "user": role.user, "actor": actor, "action": action, "workspace": role.workspace, "ActionDescription": ActionDescription, "parent_in_context": parent_in_context, "content_in_context": content_in_context, "workspace_url": workspace_url, "previous_revision": previous_revision, "new_status": new_status, "role_label": role_label, "logo_url": logo_url, }
def _build_context_for_content_update( self, role: UserRoleInWorkspace, content_in_context: ContentInContext, parent_in_context: typing.Optional[ContentInContext], workspace_in_context: WorkspaceInContext, actor: User, translator: Translator ): _ = translator.get_translation content = content_in_context.content action = content.get_last_action().id # default values user = role.user workspace = role.workspace workspace_url = workspace_in_context.frontend_url main_title = content.label status_label = content.get_status().label # TODO - G.M - 11-06-2018 - [emailTemplateURL] correct value for status_icon_url # nopep8 status_icon_url = '' role_label = role.role_as_label() content_intro = '<span id="content-intro-username">{}</span> did something.'.format(actor.display_name) # nopep8 content_text = content.description call_to_action_url = content_in_context.frontend_url logo_url = get_email_logo_frontend_url(self.config) if ActionDescription.COMMENT == action: main_title = parent_in_context.label content_intro = '' call_to_action_url = parent_in_context.frontend_url elif ActionDescription.STATUS_UPDATE == action: new_status = translator.get_translation(content.get_status().label) main_title = content_in_context.label content_intro = _('I modified the status of <i>{content}</i>. The new status is <i>{new_status}</i>').format( content=content.get_label(), new_status=new_status ) content_text = '' call_to_action_url = content_in_context.frontend_url elif ActionDescription.CREATION == action: main_title = content_in_context.label content_intro = _('I added an item entitled <i>{content}</i>.').format(content=content.get_label()) # nopep8 content_text = '' elif action in (ActionDescription.REVISION, ActionDescription.EDITION): main_title = content_in_context.label content_intro = _('I updated <i>{content}</i>.').format(content=content.get_label()) # nopep8 previous_revision = content.get_previous_revision() title_diff = htmldiff(previous_revision.label, content.label) content_diff = htmldiff(previous_revision.description, content.description) if title_diff or content_diff: content_text = str('<p>{diff_intro_text}</p>\n{title_diff}\n{content_diff}').format( # nopep8 diff_intro_text=_('Here is an overview of the changes:'), title_diff=title_diff, content_diff=content_diff ) # if not content_intro and not content_text: # # Skip notification, but it's not normal # logger.error( # self, # 'A notification is being sent but no content. ' # 'Here are some debug informations: [content_id: {cid}]' # '[action: {act}][author: {actor}]'.format( # cid=content.content_id, # act=action, # actor=actor # ) # ) # raise EmptyNotificationError('Unexpected empty notification') # FIXME: remove/readapt assert to debug easily broken case assert user assert workspace assert main_title assert status_label # assert status_icon_url assert role_label # assert content_intro assert content_text or content_text == content.description assert call_to_action_url assert logo_url return { 'user': role.user, 'workspace': role.workspace, 'workspace_url': workspace_url, 'main_title': main_title, 'status_label': status_label, 'status_icon_url': status_icon_url, 'role_label': role_label, 'content_intro': content_intro, 'content_text': content_text, 'call_to_action_url': call_to_action_url, 'logo_url': logo_url, }
def _build_context_for_content_update( self, role: UserRoleInWorkspace, content_in_context: ContentInContext, parent_in_context: typing.Optional[ContentInContext], workspace_in_context: WorkspaceInContext, actor: User, translator: Translator ): _ = translator.get_translation content = content_in_context.content action = content.get_last_action().id # default values user = role.user workspace = role.workspace workspace_url = workspace_in_context.frontend_url main_title = content.label status_label = content.get_status().label # TODO - G.M - 11-06-2018 - [emailTemplateURL] correct value for status_icon_url # nopep8 status_icon_url = '' role_label = role.role_as_label() content_intro = '<span id="content-intro-username">{}</span> did something.'.format(actor.display_name) # nopep8 content_text = content.description call_to_action_text = 'See more' call_to_action_url = content_in_context.frontend_url logo_url = get_email_logo_frontend_url(self.config) if ActionDescription.CREATION == action: call_to_action_text = _('View online') content_intro = _('<span id="content-intro-username">{}</span> create a content:').format(actor.display_name) # nopep8 if content_type_list.Thread.slug == content.type: if content.get_last_comment_from(actor): content_text = content.get_last_comment_from(actor).description # nopep8 call_to_action_text = _('Answer') content_intro = _('<span id="content-intro-username">{}</span> started a thread entitled:').format(actor.display_name) content_text = '<p id="content-body-intro">{}</p>'.format(content.label) + content_text # nopep8 elif content_type_list.File.slug == content.type: content_intro = _('<span id="content-intro-username">{}</span> added a file entitled:').format(actor.display_name) if content.description: content_text = content.description else: content_text = '<span id="content-body-only-title">{}</span>'.format(content.label) elif content_type_list.Page.slug == content.type: content_intro = _('<span id="content-intro-username">{}</span> added a page entitled:').format(actor.display_name) content_text = '<span id="content-body-only-title">{}</span>'.format(content.label) elif ActionDescription.REVISION == action: content_text = content.description call_to_action_text = _('View online') if content_type_list.File.slug == content.type: content_intro = _('<span id="content-intro-username">{}</span> uploaded a new revision.').format(actor.display_name) content_text = content.description elif ActionDescription.EDITION == action: call_to_action_text = _('View online') if content_type_list.File.slug == content.type: content_intro = _('<span id="content-intro-username">{}</span> updated the file description.').format(actor.display_name) content_text = '<p id="content-body-intro">{}</p>'.format(content.get_label()) + content.description # nopep8 elif content_type_list.Thread.slug == content.type: content_intro = _('<span id="content-intro-username">{}</span> updated the thread description.').format(actor.display_name) previous_revision = content.get_previous_revision() title_diff = '' if previous_revision.label != content.label: title_diff = htmldiff(previous_revision.label, content.label) content_text = str('<p id="content-body-intro">{}</p> {text} {title_diff} {content_diff}').format( text=_('Here is an overview of the changes:'), title_diff=title_diff, content_diff=htmldiff(previous_revision.description, content.description) ) elif content_type_list.Page.slug == content.type: content_intro = _('<span id="content-intro-username">{}</span> updated this page.').format(actor.display_name) previous_revision = content.get_previous_revision() title_diff = '' if previous_revision.label != content.label: title_diff = htmldiff(previous_revision.label, content.label) # nopep8 content_text = str('<p id="content-body-intro">{}</p> {text}</p> {title_diff} {content_diff}').format( # nopep8 actor.display_name, text=_('Here is an overview of the changes:'), title_diff=title_diff, content_diff=htmldiff(previous_revision.description, content.description) ) elif ActionDescription.STATUS_UPDATE == action: intro_user_msg = _( '<span id="content-intro-username">{}</span> ' 'updated the following status:' ) intro_body_msg = '<p id="content-body-intro">{}: {}</p>' call_to_action_text = _('View online') content_intro = intro_user_msg.format(actor.display_name) content_text = intro_body_msg.format( content.get_label(), content.get_status().label, ) elif ActionDescription.COMMENT == action: call_to_action_text = _('Answer') main_title = parent_in_context.label content_intro = _('<span id="content-intro-username">{}</span> added a comment:').format(actor.display_name) # nopep8 call_to_action_url = parent_in_context.frontend_url if not content_intro and not content_text: # Skip notification, but it's not normal logger.error( self, 'A notification is being sent but no content. ' 'Here are some debug informations: [content_id: {cid}]' '[action: {act}][author: {actor}]'.format( cid=content.content_id, act=action, actor=actor ) ) raise EmptyNotificationError('Unexpected empty notification') # FIXME: remove/readapt assert to debug easily broken case assert user assert workspace assert main_title assert status_label # assert status_icon_url assert role_label assert content_intro assert content_text or content_text == content.description assert call_to_action_text assert call_to_action_url assert logo_url return { 'user': role.user, 'workspace': role.workspace, 'workspace_url': workspace_url, 'main_title': main_title, 'status_label': status_label, 'status_icon_url': status_icon_url, 'role_label': role_label, 'content_intro': content_intro, 'content_text': content_text, 'call_to_action_text': call_to_action_text, 'call_to_action_url': call_to_action_url, 'logo_url': logo_url, }