class EditFormOFF(form.EditForm):
    """ Edit the comment in the context of the commented item.

    TODO: How to get permission right???"""

    zope.interface.implements(ITabbedContentLayout)

    label = _('comment-edit-label', u"Change comment")

    fields = field.Fields(interfaces.IComment).select(
        'comment')  #, 'source_type')

    def __init__(self, context, request):
        super(SimpleEditForm, self).__init__(context, request)
        zc.resourcelibrary.need('quotationtool.tinymce.Comment')

    def getContent(self):
        comment_id = self.request.form.get('id', None)
        try:
            comment_id = int(comment_id)
            intids = zope.component.getUtility(IIntIds, context=self.context)
            self.comment = intids.queryObject(id, default=None)
            if not interfaces.IComment.providedBy(self.comment):
                raise Exception
        except:
            raise UserError(_(u"Invalid object ID"))
        return self.comment

    def updateWidgetsOFF(self):
        super(SimpleEditForm, self).updateWidgets()
        self.widgets['source_type'].mode = DISPLAY_MODE

    def nextURL(self):
        return absoluteURL(self.context.about, self.request)
 def getContent(self):
     comment_id = self.request.form.get('id', None)
     try:
         comment_id = int(comment_id)
         intids = zope.component.getUtility(IIntIds, context=self.context)
         self.comment = intids.queryObject(id, default=None)
         if not interfaces.IComment.providedBy(self.comment):
             raise Exception
     except:
         raise UserError(_(u"Invalid object ID"))
     return self.comment
 def __init__(self, context, request):
     super(SingleCommentPagelet, self).__init__(context, request)
     id = request.form.get('id', None)
     try:
         id = int(id)
         intids = zope.component.getUtility(IIntIds, context=self.context)
         self.comment = intids.queryObject(id, default=None)
         if not interfaces.IComment.providedBy(self.comment):
             raise Exception
     except:
         raise UserError(_(u"Invalid object ID"))
 def renderCell(self, item):
     source = zope.component.createObject(item.source_type, item.comment)
     renderer = zope.component.getMultiAdapter(
         (removeAllProxies(source), self.request), IHTMLRenderer, name=u'')
     intids = zope.component.getUtility(IIntIds, context=self.context)
     cid = intids.getId(item)
     cell = renderer.render(limit=self.limit)
     more_anchor = _('more-link', "[Read more]")
     cell += "<div><a href='%s'>%s</a></div>" % (
         absoluteURL(item.about, self.request) + '/@@comment.html?id=' +
         unicode(cid) + '#tabs',
         translate(more_anchor, context=self.request, default=more_anchor))
     return cell
class SimpleEditForm(form.EditForm):

    label = _('comment-edit-label', u"Change comment")

    fields = field.Fields(interfaces.IComment).select(
        'comment')  #, 'source_type')

    def __init__(self, context, request):
        super(SimpleEditForm, self).__init__(context, request)
        zc.resourcelibrary.need('quotationtool.tinymce.Comment')

    def updateWidgetsOFF(self):
        super(SimpleEditForm, self).updateWidgets()
        self.widgets['source_type'].mode = DISPLAY_MODE

    def nextURL(self):
        return absoluteURL(self.context.about, self.request)
class CreatorColumn(column.Column):
    """ The creator column of a comments table."""

    zope.interface.implements(ISortingColumn)

    header = _('commentary-columnheader-creator', u"By")
    weight = 100

    def renderCell(self, item):
        creator = u"Unkown"
        dc = IZopeDublinCore(item, None)
        if dc is None:
            return creator
        pau = zope.component.queryUtility(IAuthentication,
                                          context=self.context)
        if pau is not None:
            try:
                creator = pau.getPrincipal(dc.creators[0]).title
            except Exception:
                pass
        return creator
class TextColumn(column.Column):
    """ The text column of a comments table."""

    #zope.interface.implements(ISortingColumn)

    header = _('commentary-columnheader-text', u"Text")
    weight = 100

    limit = 200

    def renderCell(self, item):
        source = zope.component.createObject(item.source_type, item.comment)
        renderer = zope.component.getMultiAdapter(
            (removeAllProxies(source), self.request), IHTMLRenderer, name=u'')
        intids = zope.component.getUtility(IIntIds, context=self.context)
        cid = intids.getId(item)
        cell = renderer.render(limit=self.limit)
        more_anchor = _('more-link', "[Read more]")
        cell += "<div><a href='%s'>%s</a></div>" % (
            absoluteURL(item.about, self.request) + '/@@comment.html?id=' +
            unicode(cid) + '#tabs',
            translate(more_anchor, context=self.request, default=more_anchor))
        return cell
class AddComment(form.AddForm):

    zope.interface.implements(ITabbedContentLayout)

    fields = field.Fields(interfaces.IComment).select('comment')

    label = _('comment-add-label', u"Add a comment")

    def __init__(self, context, request):
        super(AddComment, self).__init__(context, request)
        zc.resourcelibrary.need('quotationtool.tinymce.Comment')

    def create(self, data):
        obj = Comment()
        form.applyChanges(self, obj, data)
        obj.source_type = 'html'
        obj.about = removeAllProxies(self.context)

        # Grant the current user the Edit permission by assigning him
        # the quotationtool.Creator role, but only locally in the
        # context of the newly created object.
        manager = IPrincipalRoleManager(obj)
        manager.assignRoleToPrincipal('quotationtool.Creator',
                                      self.request.principal.id)

        return obj

    def add(self, obj):
        container = zope.component.getUtility(
            interfaces.ICommentContainer,
            context=self.context,
        )
        self._name = INameChooser(container).chooseName(None, obj)
        container[self._name] = self._obj = obj

    def nextURL(self):
        return absoluteURL(self.context, self.request) + u"/@@comments.html"
예제 #9
0
 def __call__(self):
     return _('commentcontainer-label', u"Comments")
예제 #10
0
 def __call__(self):
     return _('comment-label', u"Comment")