def __call__(self, include_items=True): content_url = self.context.__parent__.__parent__.absolute_url() comments_url = "{}/@comments".format(content_url) url = "{}/{}".format(comments_url, self.context.id) if self.context.in_reply_to: parent_url = "{}/{}".format(comments_url, self.context.in_reply_to) in_reply_to = str(self.context.in_reply_to) else: parent_url = None in_reply_to = None doc_allowed = delete_own_comment_allowed() delete_own = doc_allowed and can_delete_own(self.context) return { "@id": url, "@type": self.context.portal_type, "@parent": parent_url, "comment_id": str(self.context.id), "in_reply_to": in_reply_to, "text": {"data": self.context.text, "mime-type": self.context.mime_type}, "user_notification": self.context.user_notification, "author_username": self.context.author_username, "author_name": self.context.author_name, "creation_date": IJsonCompatible(self.context.creation_date), "modification_date": IJsonCompatible( self.context.modification_date ), # noqa "is_editable": edit_comment_allowed() and can_edit(self.context), "is_deletable": can_delete(self.context) or delete_own, }
def __call__(self): content_url = self.context.__parent__.__parent__.absolute_url() comments_url = '{}/@comments'.format(content_url) url = '{}/{}'.format(comments_url, self.context.id) if self.context.in_reply_to: parent_url = '{}/{}'.format(comments_url, self.context.in_reply_to) in_reply_to = str(self.context.in_reply_to) else: parent_url = None in_reply_to = None doc_allowed = delete_own_comment_allowed() delete_own = doc_allowed and can_delete_own(self.context) return { '@id': url, '@type': self.context.portal_type, '@parent': parent_url, 'comment_id': str(self.context.id), 'in_reply_to': in_reply_to, 'text': { 'data': self.context.text, 'mime-type': self.context.mime_type }, 'user_notification': self.context.user_notification, 'author_username': self.context.author_username, 'author_name': self.context.author_name, 'creation_date': IJsonCompatible(self.context.creation_date), 'modification_date': IJsonCompatible(self.context.modification_date), # noqa 'is_editable': edit_comment_allowed() and can_edit(self.context), 'is_deletable': can_delete(self.context) or delete_own }
def reply(self): conversation = IConversation(self.context) if not self.comment_id: raise BadRequest("Comment id is a required part of the url") if self.comment_id not in conversation: self.request.response.setStatus(404) return comment = conversation[self.comment_id] # Permission checks doc_allowed = delete_own_comment_allowed() delete_own = doc_allowed and can_delete_own(comment) if not (can_delete(comment) or delete_own): raise Unauthorized() del conversation[self.comment_id] return self.reply_no_content()
def __call__(self, include_items=True): content_url = self.context.__parent__.__parent__.absolute_url() comments_url = f"{content_url}/@comments" url = f"{comments_url}/{self.context.id}" if self.context.in_reply_to: parent_url = f"{comments_url}/{self.context.in_reply_to}" in_reply_to = str(self.context.in_reply_to) else: parent_url = None in_reply_to = None doc_allowed = delete_own_comment_allowed() delete_own = doc_allowed and can_delete_own(self.context) if self.context.mime_type == "text/plain": text_data = self.context.text text_mime_type = self.context.mime_type else: text_data = self.context.getText() text_mime_type = "text/html" return { "@id": url, "@type": self.context.portal_type, "@parent": parent_url, "comment_id": str(self.context.id), "in_reply_to": in_reply_to, "text": { "data": text_data, "mime-type": text_mime_type }, "user_notification": self.context.user_notification, "author_username": self.context.author_username, "author_name": self.context.author_name, "author_image": self.get_author_image(self.context.author_username), "creation_date": IJsonCompatible(self.context.creation_date), "modification_date": IJsonCompatible(self.context.modification_date), # noqa "is_editable": edit_comment_allowed() and can_edit(self.context), "is_deletable": can_delete(self.context) or delete_own, "can_reply": can_reply(self.context), }