def set_associated_contents(self, associated_contents, user): subject = self.subject current_associated_contents = self.associated_contents associated_contents_to_add = [ i for i in associated_contents if i not in current_associated_contents ] associated_contents_to_del = [ i for i in current_associated_contents if i not in associated_contents and i not in associated_contents_to_add ] correlations = connect( subject, associated_contents_to_add, { 'comment': _('Add related contents'), 'type': _('Edit the comment') }, author=user, ) for correlation in correlations: correlation.setproperty('context', self) disconnect(subject, associated_contents_to_del)
def set_related_ideas(self, relatedideas, user): current_related_ideas = self.related_ideas related_ideas_to_add = [ i for i in relatedideas if i not in current_related_ideas ] related_ideas_to_del = [ i for i in current_related_ideas if i not in relatedideas and i not in related_ideas_to_add ] connect(self, related_ideas_to_add, { 'comment': _('Add related ideas'), 'type': _('Edit the proposal') }, user, ['related_proposals', 'related_ideas'], CorrelationType.solid, True) disconnect(self, related_ideas_to_del, 'related_ideas', CorrelationType.solid)
def set_related_ideas(self, relatedideas, user): current_related_ideas = self.related_ideas related_ideas_to_add = [i for i in relatedideas if i not in current_related_ideas] related_ideas_to_del = [i for i in current_related_ideas if i not in relatedideas and i not in related_ideas_to_add] connect(self, related_ideas_to_add, {'comment': _('Add related ideas'), 'type': _('Edit the proposal')}, user, ['related_proposals', 'related_ideas'], CorrelationType.solid, True) disconnect(self, related_ideas_to_del, 'related_ideas', CorrelationType.solid)
def start(self, context, request, appstruct, **kw): root = getSite() user = get_current(request) mask = user.get_mask(root) if hasattr(user, 'get_mask') else user author = mask if appstruct.get('anonymous', False) and mask else user question = appstruct['_object_data'] root.merge_keywords(question.keywords) root.addtoproperty('questions', question) question.state.extend(['pending', 'published']) grant_roles(user=author, roles=(('Owner', question), )) question.setproperty('author', author) if isinstance(context, Comment): related_contents = [question] content = context.subject correlations = connect( content, list(related_contents), {'comment': context.comment, 'type': context.intention}, author, ['transformation'], CorrelationType.solid) for correlation in correlations: correlation.setproperty('context', context) context_type = context.__class__.__name__.lower() # Add Nia comment alert_comment_nia( question, request, root, internal_kind=InternalAlertKind.content_alert, subject_type='question', alert_kind='transformation', content=context ) # Add Nia comment alert_comment_nia( context, request, root, internal_kind=InternalAlertKind.content_alert, subject_type=context_type, alert_kind='transformation_question', question=question ) question.format(request) question.reindex() request.registry.notify(ActivityExecuted(self, [question], author)) request.registry.notify(ObjectPublished(object=question)) return {'newcontext': question}
def start(self, context, request, appstruct, **kw): root = getSite() user = get_current(request) mask = user.get_mask(root) if hasattr(user, 'get_mask') else user author = mask if appstruct.get('anonymous', False) and mask else user question = appstruct['_object_data'] root.addtoproperty('questions', question) question.state.extend(['pending', 'published']) grant_roles(user=author, roles=(('Owner', question), )) question.setproperty('author', author) if isinstance(context, Comment): related_contents = [question] content = context.subject correlations = connect(content, list(related_contents), { 'comment': context.comment, 'type': context.intention }, author, ['transformation'], CorrelationType.solid) for correlation in correlations: correlation.setproperty('context', context) context_type = context.__class__.__name__.lower() # Add Nia comment alert_comment_nia(question, request, root, internal_kind=InternalAlertKind.content_alert, subject_type='question', alert_kind='transformation', content=context) # Add Nia comment alert_comment_nia(context, request, root, internal_kind=InternalAlertKind.content_alert, subject_type=context_type, alert_kind='transformation_question', question=question) question.format(request) if getattr(question, '_tree', None): tree = getattr(question, '_tree') root.merge_tree(tree) question.reindex() request.registry.notify(ActivityExecuted(self, [question], author)) request.registry.notify(ObjectPublished(object=question)) return {'newcontext': question}
def start(self, context, request, appstruct, **kw): comment = appstruct['_object_data'] context.addtoproperty('comments', comment) user = get_current() comment.setproperty('author', user) if appstruct['related_contents']['associate']: related_contents = appstruct['related_contents']['related_contents'] correlation = connect(context, list(related_contents), {'comment': comment.comment, 'type': comment.intention}, user, unique=True) comment.setproperty('related_correlation', correlation) context.reindex() return {}
def set_associated_contents(self, associated_contents, user): subject = self.subject current_associated_contents = self.associated_contents associated_contents_to_add = [i for i in associated_contents if i not in current_associated_contents] associated_contents_to_del = [i for i in current_associated_contents if i not in associated_contents and i not in associated_contents_to_add] correlations = connect( subject, associated_contents_to_add, {'comment': _('Add related contents'), 'type': _('Edit the comment')}, author=user) for correlation in correlations: correlation.setproperty('context', self) disconnect( subject, associated_contents_to_del)
def alert_comment_nia(context, request, root, **kwargs): nia = root['principals']['users'].get('nia', None) channel = context.channel kind = kwargs.pop('internal_kind', None) alert_class = INTERNAL_ALERTS.get(kind, None) if nia and channel and alert_class: # For Nia the alert is volatil alert = alert_class(**kwargs) alert.subject = context comment_text = alert.render('nia', None, request).strip() # remove spaces and new lines between tags comment_text = re.sub('>[\n|\r|\s]*<', '><', comment_text) comment = Comment( intention=_('Remark'), comment=comment_text ) if isinstance(context, Commentable): context.addtoproperty('comments', comment) else: channel.addtoproperty('comments', comment) channel.add_comment(comment) comment.format(request, True) comment.formatted_comment = '<div class="bot-message">' + \ comment.formatted_comment +\ '</div>' comment.state = PersistentList(['published']) comment.reindex() comment.setproperty('author', nia) if kwargs.get('related_contents', []): related_contents = kwargs.get('related_contents') correlation = connect( context, list(related_contents), {'comment': comment.comment, 'type': comment.intention}, nia, unique=True) comment.setproperty('related_correlation', correlation[0]) context.reindex()
def start(self, context, request, appstruct, **kw): root = getSite() user = get_current(request) mask = user.get_mask(root) if hasattr(user, 'get_mask') else user author = mask if appstruct.get('anonymous', False) and mask else user idea = appstruct['_object_data'] root.addtoproperty('ideas', idea) idea.state.append('to work') grant_roles(user=author, roles=(('Owner', idea), )) idea.setproperty('author', author) idea.subscribe_to_channel(user) if isinstance(context, (Comment, Answer)): content = context.subject correlations = connect( content, [idea], {'comment': context.comment, 'type': getattr(context, 'intention', 'Transformation from another content')}, author, ['transformation'], CorrelationType.solid) for correlation in correlations: correlation.setproperty('context', context) context_type = context.__class__.__name__.lower() # Add Nia comment alert_comment_nia( idea, request, root, internal_kind=InternalAlertKind.content_alert, subject_type='idea', alert_kind='transformation_'+context_type, content=context ) idea.format(request) idea.reindex() request.registry.notify(ActivityExecuted(self, [idea], author)) return {'newcontext': idea}
def start(self, context, request, appstruct, **kw): result = super(CrateAndPublishAsProposal, self).start( context, request, appstruct, **kw) root = getSite() state = result.get('state', False) if state: idea = result.get('newcontext', None) if idea: user = get_current(request) mask = user.get_mask(root) if hasattr(user, 'get_mask') else user author = mask if appstruct.get('anonymous', False) and mask else user idea.subscribe_to_channel(user) related_ideas = [idea] localizer = request.localizer title = idea.title + \ localizer.translate(_(" (the proposal)")) template = getattr(root, 'proposal_template', None) text = '<p>{idea_text}</p>' if template: try: text = template.fp.readall().decode() except Exception as error: log.warning(error) proposal = Proposal( title=title, description=idea.text[:600], text=text.format( idea_text=idea.text.replace('\n', '<br/>')), keywords=list(idea.keywords) ) proposal.text = html_diff_wrapper.normalize_text(proposal.text) root.addtoproperty('proposals', proposal) proposal.state.append('draft') grant_roles(user=author, roles=(('Owner', proposal), )) grant_roles(user=author, roles=(('Participant', proposal), )) proposal.setproperty('author', author) challenge = idea.challenge if challenge: proposal.setproperty('challenge', challenge) wg = WorkingGroup() root.addtoproperty('working_groups', wg) wg.init_workspace() wg.setproperty('proposal', proposal) wg.addtoproperty('members', author) wg.state.append('deactivated') if related_ideas: connect(proposal, related_ideas, {'comment': _('Add related ideas'), 'type': _('Creation')}, author, ['related_proposals', 'related_ideas'], CorrelationType.solid) try: files = { 'add_files': { 'attached_files': [{'_object_data': f.copy()} for f in idea.attached_files] } } add_attached_files(files, proposal) except Exception: pass proposal.subscribe_to_channel(user) proposal.reindex() init_proposal_ballots(proposal) wg.reindex() request.registry.notify( ActivityExecuted(self, [idea, proposal, wg], author)) return {'newcontext': proposal} return {'newcontext': root}