コード例 #1
0
ファイル: taskcomment.py プロジェクト: Zojax/zojax.project
    def update(self):
        discussion = IContentDiscussion(self.context)
        if discussion.status != 1:
            removeAllProxies(discussion).status = 1

        self.comments = list(discussion.values())

        self.postsAllowed = (discussion.status == 1 and
                             checkPermission('zojax.AddComment', self.context))
        if self.postsAllowed:
            self.reply = getMultiAdapter(
                (self.context, self.request), name='comment.html')
            self.reply.update()
コード例 #2
0
 def publishTraverse(self, request, name):
     self.discussion = IContentDiscussion(self.context)
     if name in self.discussion:
         comment  = self.discussion[name]
         if self.canManage(comment):
             return LocationProxy(self.discussion[name], self, name)
     raise NotFound(self.context, name, request)
コード例 #3
0
ファイル: view.py プロジェクト: Zojax/zojax.cynin.xmlrpc
    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
コード例 #4
0
ファイル: recipient.py プロジェクト: Zojax/zojax.blogger
    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))
コード例 #5
0
class ManageDiscussion(PageletForm):

    label = _(u'Manage discussion')
    title = label
    size = 30

    def update(self):
        self.discussion = IContentDiscussion(self.context)
        self.batch = Batch(self.discussion.values(), size=self.size, request=self.request)
        super(ManageDiscussion, self).update()

    @button.buttonAndHandler(_(u'Back'), name='content.discussion.back')
    def handleBack(self, action):
        self.redirect('.')

    @button.buttonAndHandler(_(u'Remove'), name='content.discussion.remove')
    def handleRemove(self, action):
        request = self.request
        ids = request.get('commentIds', ())
        if not ids:
            IStatusMessage(request).add(_('Please select comments.'))

        else:
            for id in ids:
                if id in self.discussion:
                    del self.discussion[id]

            IStatusMessage(request).add(
                _('Selected comments have been removed.'))
            self.redirect(self.request.getURL())

    def canManage(self, comment):
        return checkPermission('zojax.ModifyContent', self.context) or \
        checkPermission('zojax.ModifyContent', comment)

    def publishTraverse(self, request, name):
        self.discussion = IContentDiscussion(self.context)
        if name in self.discussion:
            comment  = self.discussion[name]
            if self.canManage(comment):
                return LocationProxy(self.discussion[name], self, name)
        raise NotFound(self.context, name, request)
コード例 #6
0
 def update(self):
     self.discussion = IContentDiscussion(self.context)
     self.batch = Batch(self.discussion.values(), size=self.size, request=self.request)
     super(ManageDiscussion, self).update()
コード例 #7
0
ファイル: taskcomment.py プロジェクト: Zojax/zojax.project
    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('.')