Beispiel #1
0
 def start(self, context, request, appstruct, **kw):
     user = get_current(request)
     user = context.working_group.get_member(user)
     related_ideas = appstruct.pop('related_ideas')
     add_files = appstruct.pop('add_files')
     copy_of_proposal = context.get_version(user, (context, 'version'))
     context.working_group.init_nonproductive_cycle()
     context.state = PersistentList(['amendable', 'published'])
     context.set_data(appstruct)
     context.text = html_diff_wrapper.normalize_text(context.text)
     context.modified_at = datetime.datetime.now(tz=pytz.UTC)
     context.set_related_ideas(related_ideas, user)
     # Add Nia comment
     alert_comment_nia(
         context,
         request,
         getSite(),
         internal_kind=InternalAlertKind.working_group_alert,
         subject_type='proposal',
         alert_kind='new_version',
         diff=diff_analytics(copy_of_proposal, context,
                             ['title', 'text', 'description']))
     add_attached_files({'add_files': add_files}, context)
     context.reindex()
     return {'newcontext': context}
Beispiel #2
0
 def start(self, context, request, appstruct, **kw):
     user = get_current(request)
     user = context.working_group.get_member(user)
     related_ideas = appstruct.pop('related_ideas')
     add_files = appstruct.pop('add_files')
     copy_of_proposal = context.get_version(user, (context, 'version'))
     context.working_group.init_nonproductive_cycle()
     context.state = PersistentList(['amendable', 'published'])
     context.set_data(appstruct)
     context.text = html_diff_wrapper.normalize_text(
         context.text)
     context.modified_at = datetime.datetime.now(tz=pytz.UTC)
     context.set_related_ideas(
         related_ideas, user)
     # Add Nia comment
     alert_comment_nia(
         context, request, getSite(),
         internal_kind=InternalAlertKind.working_group_alert,
         subject_type='proposal',
         alert_kind='new_version',
         diff=diff_analytics(
             copy_of_proposal, context, ['title', 'text', 'description'])
         )
     add_attached_files({'add_files': add_files}, context)
     context.reindex()
     return {'newcontext': context}
Beispiel #3
0
    def start(self, context, request, appstruct, **kw):
        root = request.root
        if root.support_ideas:
            context.state = PersistentList(['submitted_support', 'published'])
        else:
            context.state = PersistentList(['published', 'submitted_support'])

        context.init_published_at()
        if context.originalentity:
            # Add Nia comment
            alert_comment_nia(
                context.originalentity, request, root,
                internal_kind=InternalAlertKind.content_alert,
                subject_type='idea',
                alert_kind='duplicated',
                duplication=context
                )

        transformed_from = context.transformed_from
        if transformed_from:
            context_type = transformed_from.__class__.__name__.lower()
            # Add Nia comment
            alert_comment_nia(
                transformed_from, request, root,
                internal_kind=InternalAlertKind.content_alert,
                subject_type=context_type,
                alert_kind='transformation_idea',
                idea=context
                )
        root.merge_keywords(context.keywords)
        context.reindex()
        request.registry.notify(ObjectPublished(object=context))
        request.registry.notify(ActivityExecuted(
            self, [context], appstruct.get('user', context.author)))
        return {}
Beispiel #4
0
    def start(self, context, request, appstruct, **kw):
        result = set()
        working_group = context.working_group
        for ballot in working_group.amendments_ballots:
            electeds = ballot.report.get_electeds()
            if electeds is not None:
                result.update(electeds)

        amendments = [a for a in result if isinstance(a, Amendment)]
        members = working_group.members
        root = getSite()
        user = get_current()
        if amendments:
            merged_text = html_diff_wrapper.merge(context.text,
                                                  [a.text for a in amendments])
            merged_text = html_diff_wrapper.normalize_text(merged_text)
            #TODO merged_keywords + merged_description
            version = context.get_version(user, (context, 'version'))
            for amendment in version.amendments:
                amendment.state = PersistentList(['archived'])
                amendment.reindex()

            self._send_ballot_result(context, request, result, members)
            context.text = merged_text
            related_ideas = [a.related_ideas for a in amendments]
            related_ideas = [
                item for sublist in related_ideas for item in sublist
            ]
            related_ideas.extend(context.related_ideas)
            related_ideas = list(set(related_ideas))
            context.set_related_ideas(related_ideas, user)
            context.working_group.init_nonproductive_cycle()
            context.reindex()
            alert('internal', [root],
                  members,
                  internal_kind=InternalAlertKind.working_group_alert,
                  subjects=[context],
                  alert_kind='amendments_result')
            # Add Nia comment
            alert_comment_nia(
                context,
                request,
                root,
                internal_kind=InternalAlertKind.working_group_alert,
                subject_type='proposal',
                alert_kind='new_version',
                diff=diff_analytics(version, context,
                                    ['title', 'text', 'description']))
        else:
            context.state = PersistentList(['amendable', 'published'])
            alert('internal', [root],
                  members,
                  internal_kind=InternalAlertKind.working_group_alert,
                  subjects=[context])
            for amendment in context.amendments:
                amendment.state = PersistentList(['archived'])
                amendment.reindex()

        context.reindex()
        return {'newcontext': context}
Beispiel #5
0
    def start(self, context, request, appstruct, **kw):
        result = set()
        working_group = context.working_group
        for ballot in working_group.amendments_ballots:
            electeds = ballot.report.get_electeds()
            if electeds is not None:
                result.update(electeds)

        amendments = [a for a in result if isinstance(a, Amendment)]
        members = working_group.members
        root = getSite()
        user = get_current()
        if amendments:
            merged_text = html_diff_wrapper.merge(
                context.text, [a.text for a in amendments])
            merged_text = html_diff_wrapper.normalize_text(merged_text)
            #TODO merged_keywords + merged_description
            version = context.get_version(
                user, (context, 'version'))
            for amendment in version.amendments:
                amendment.state = PersistentList(['archived'])
                amendment.reindex()

            self._send_ballot_result(context, request,
                                     result, members)
            context.text = merged_text
            related_ideas = [a.related_ideas for a in amendments]
            related_ideas = [item for sublist in related_ideas
                             for item in sublist]
            related_ideas.extend(context.related_ideas)
            related_ideas = list(set(related_ideas))
            context.set_related_ideas(related_ideas, user)
            context.working_group.init_nonproductive_cycle()
            context.reindex()
            alert('internal', [root], members,
                  internal_kind=InternalAlertKind.working_group_alert,
                  subjects=[context], alert_kind='amendments_result')
            # Add Nia comment
            alert_comment_nia(
                context, request, root,
                internal_kind=InternalAlertKind.working_group_alert,
                subject_type='proposal',
                alert_kind='new_version',
                diff=diff_analytics(
                    version, context, ['title', 'text', 'description'])
                )
        else:
            context.state = PersistentList(['amendable', 'published'])
            alert('internal', [root], members,
                  internal_kind=InternalAlertKind.working_group_alert,
                  subjects=[context])
            for amendment in context.amendments:
                amendment.state = PersistentList(['archived'])
                amendment.reindex()

        context.reindex()
        return {'newcontext': context}
Beispiel #6
0
    def start(self, context, request, appstruct, **kw):
        root = getSite()
        if root.support_ideas:
            context.state = PersistentList(['submitted_support', 'published'])
        else:
            context.state = PersistentList(['published', 'submitted_support'])

        context.init_published_at()
        root.merge_keywords(context.keywords)
        context.reindex()
        user = context.author
        alert('internal', [root], [user],
              internal_kind=InternalAlertKind.moderation_alert,
              subjects=[context], alert_kind='moderation')
        if context.originalentity:
            # Add Nia comment
            alert_comment_nia(
                context.originalentity, request, root,
                internal_kind=InternalAlertKind.content_alert,
                subject_type='idea',
                alert_kind='duplicated',
                duplication=context
                )

        transformed_from = context.transformed_from
        if transformed_from:
            context_type = transformed_from.__class__.__name__.lower()
            # Add Nia comment
            alert_comment_nia(
                transformed_from, request, root,
                internal_kind=InternalAlertKind.content_alert,
                subject_type=context_type,
                alert_kind='transformation_idea',
                idea=context
                )

        if getattr(user, 'email', ''):
            mail_template = root.get_mail_template(
                'publish_idea_decision', user.user_locale)
            subject = mail_template['subject'].format(
                subject_title=context.title)
            email_data = get_user_data(user, 'recipient', request)
            email_data.update(get_entity_data(context, 'subject', request))
            message = mail_template['template'].format(
                novaideo_title=root.title,
                **email_data
            )
            alert('email', [root.get_site_sender()], [user.email],
                  subject=subject, body=message)

        request.registry.notify(ObjectPublished(object=context))
        request.registry.notify(ActivityExecuted(
            self, [context], get_current(request)))
        return {}
Beispiel #7
0
    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}
Beispiel #8
0
    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}
Beispiel #9
0
    def start(self, context, request, appstruct, **kw):
        appstruct.pop('_csrf_token_')
        context.opinion = PersistentDict(appstruct)
        context.state = PersistentList(
            ['examined', 'published', context.opinion['opinion']])
        context.init_examined_at()
        context.remove_tokens()
        context.reindex()
        member = context.author
        root = getSite()
        users = list(get_users_by_preferences(context))
        users.append(member)
        alert(
            'internal', [root], users,
            internal_kind=InternalAlertKind.examination_alert,
            subjects=[context])
        # Add Nia comment
        alert_comment_nia(
            context, request, root,
            internal_kind=InternalAlertKind.examination_alert,
            subject_type='idea'
            )
        if getattr(member, 'email', ''):
            mail_template = root.get_mail_template(
                'opinion_idea', member.user_locale)
            subject = mail_template['subject'].format(
                subject_title=context.title)
            localizer = request.localizer
            email_data = get_user_data(member, 'recipient', request)
            email_data.update(get_entity_data(context, 'subject', request))
            message = mail_template['template'].format(
                opinion=localizer.translate(_(context.opinion_value)),
                explanation=context.opinion['explanation'],
                novaideo_title=root.title,
                **email_data
            )
            alert('email', [root.get_site_sender()], [member.email],
                  subject=subject, body=message)

        request.registry.notify(ActivityExecuted(
            self, [context], get_current(request)))
        return {}
Beispiel #10
0
def valid_correction(process, correction, proposal, request):
    correction.state.remove('in process')
    correction.state.append('processed')
    current_version = correction.current_version
    old_version = proposal.version
    if old_version:
        current_version.setproperty('version', old_version)

    proposal.setproperty('version', current_version)
    proposal.reindex()
    current_version.reindex()
    # Add Nia comment
    alert_comment_nia(proposal,
                      request,
                      getSite(),
                      internal_kind=InternalAlertKind.working_group_alert,
                      subject_type='proposal',
                      alert_kind='new_version',
                      diff=diff_analytics(current_version, proposal,
                                          ['title', 'text', 'description']))
Beispiel #11
0
def valid_correction(process, correction, proposal, request):
    correction.state.remove('in process')
    correction.state.append('processed')
    current_version = correction.current_version
    old_version = proposal.version
    if old_version:
        current_version.setproperty('version', old_version)

    proposal.setproperty('version', current_version)
    proposal.reindex()
    current_version.reindex()
    # Add Nia comment
    alert_comment_nia(
        proposal, request, getSite(),
        internal_kind=InternalAlertKind.working_group_alert,
        subject_type='proposal',
        alert_kind='new_version',
        diff=diff_analytics(
            current_version, proposal, ['title', 'text', 'description'])
        )
Beispiel #12
0
    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}