예제 #1
0
    def addNewComment(self, uid, commentTitle, commentBody, commentId = None):
        """Adds a comment on the provided UID with given title, text and commenter user.
        """
        ids = component.getUtility(IIntIds, context = self.context)
        obj = ids.getObject(int(uid))
        discussion = IContentDiscussion(obj)

        commentText = cgi.escape(commentBody)

        comment = Comment(self.request.principal.id, commentText)

        tz = ITZInfo(self.request, None)
        if tz:
            comment.date = datetime.now(tz)
        else:
            comment.date = datetime.now(pytz.utc)

        comment = discussion.add(comment)

        return uid
예제 #2
0
    def reply(self, title, text, message):
        oid = message['In-Reply-To'].split('@', 1)[0].split('.', 1)[0][1:]

        try:
            post = getUtility(IIntIds).getObject(int(oid))
        except:
            return

        if checkPermission('zojax.AddComment', post):
            discussion = IContentDiscussion(post)

            interaction = queryInteraction()
            if interaction is not None and interaction.participations:
                request = interaction.participations[0]

                comment = Comment(request.principal.id, text.text)
                comment.date = datetime.now(ITZInfo(request, pytz.utc))

                comment = discussion.add(comment)
                event.notify(ObjectModifiedEvent(post))
예제 #3
0
    def addCommentHandler(self, action):
        request = self.request
        data, errors = self.extractData()

        if errors:
            IStatusMessage(request).add(self.formErrorsMessage, 'warning')
        else:
            task = self.context

            changes = {}
            if 'severity' in data and task.severity != data['severity']:
                try:
                    value = self.severity.getTerm(task.severity).title
                except:
                    value = u''
                changes['severity'] = [
                    value, self.severity.getTerm(data['severity']).title]
                task.severity = data['severity']

            if 'priority' in data and task.priority != data['priority']:
                try:
                    value = priorityVocabulary.getTerm(task.priority).title
                except:
                    value = u''
                changes['priority'] = [
                    value, priorityVocabulary.getTerm(data['priority']).title]
                task.priority = data['priority']

            if data.get('transition'):
                state = IWorkflowState(task).getState().title

                self.wfinfo.fireTransition(data['transition'], data['comment'])

                changes['status'] = [
                    state, IWorkflowState(task).getState().title]

            if 'assigned' in data:
                assignments = IAssignments(task)

                oldassignees = []
                for principal in assignments.getAssignees():
                    oldassignees.append(principal.title)
                oldassignees.sort()

                assignees = list(assignments.assignees)
                assignees.sort()
                newassignees = list(data['assigned'])
                newassignees.sort()

                if assignees != newassignees:
                    assignments.assign(newassignees)

                    assignees = []
                    for principal in assignments.getAssignees():
                        assignees.append(principal.title)
                    assignees.sort()

                    changes['assigned'] = [oldassignees, assignees]

            # attachments
            comment = data['comment']
            if 'file' in self.widgets:
                attachments = IAttachmentsExtension(self.context)
                chooser = INameChooser(attachments)
                files = self.request.form[self.widgets['file'].name]
                if isinstance(files, FileUpload):
                    files = [files]
            else:
                files = []

            attachs = []

            for file in files:
                if isinstance(file, FileUpload):
                    filename = os.path.split(file.filename)[1].lower().strip()

                    fdata = FileData(file, filename)
                    if fdata.mimeType in ('image/jpeg','image/gif','image/png'):
                        attach = Image(title=filename, description=comment)
                    else:
                        attach = File(title=filename, description=comment)

                    attach.data = fdata
                    event.notify(ObjectCreatedEvent(attach))

                    name = chooser.chooseName(filename, attach)
                    attachments[name] = attach

                    attachs.append(attach)

            if attachs:
                ids = getUtility(IIntIds)
                attachs = [ids.getId(attach) for attach in attachs]

            event.notify(ObjectModifiedEvent(task))

            discussion = IContentDiscussion(task)
            if discussion.status != 1:
                discussion.status = 1

            comment = data['comment'].render()

            comment = TaskComment(
                request.principal.id, comment, changes, attachs)
            comment.date = datetime.now(ITZInfo(self.request, utc))

            comment = discussion.add(comment)

            IStatusMessage(self.request).add(_('Comment has been added.'))
            self.redirect('.')