def handle_submit(self, converted): context = self.context request = self.request parent = self.parent creator = authenticated_userid(request) log.debug('add_comment.html converted: %s, ctx: %s' % (str(converted), self.context)) comment = create_content( IComment, parent.title, converted['add_comment'], extract_description(converted['add_comment']), creator, ) if not 'comments' in parent.keys(): parent['comments'] = create_content(ICommentsFolder) comments = parent['comments'] next_id = comments.next_id comments[next_id] = comment if support_attachments(comment): upload_attachments(converted['attachments'], comment, creator, request) return self.status_response('Comment added')
def show_forum_topic_view(context, request): post_url = model_url(context, request, "comments", "add_comment.html") page_title = context.title actions = [] if has_permission('edit', context, request): actions.append(('Edit', 'edit.html')) if has_permission('delete', context, request): actions.append(('Delete', 'delete.html')) api = request.api api.page_title = page_title byline_info = getMultiAdapter((context, request), IBylineInfo) forum = find_interface(context, IForum) backto = { 'href': model_url(forum, request), 'title': forum.title, } # provide client data for rendering current tags in the tagbox client_json_data = dict( tagbox = get_tags_client_data(context, request), ) # Get a layout layout_provider = get_layout_provider(context, request) layout = layout_provider('community') if support_attachments(context): attachments = fetch_attachments(context['attachments'], request) else: attachments = () # enable imagedrawer for adding forum replies (comments) api.karl_client_data['text'] = dict( enable_imagedrawer_upload = True, ) return render_template_to_response( 'templates/show_forum_topic.pt', api=api, actions=actions, comments=comments_to_display(request), attachments=attachments, formfields=api.formfields, post_url=post_url, byline_info=byline_info, head_data=convert_to_script(client_json_data), backto=backto, layout=layout, comment_form={}, )
def show_comment_view(context, request): page_title = "Comment on " + context.title api = request.api api.page_title = page_title actions = [] if has_permission('edit', context, request): actions.append(('Edit', 'edit.html')) if has_permission('delete', context, request): actions.append(('Delete', 'delete.html')) byline_info = getMultiAdapter((context, request), IBylineInfo) container = find_supported_interface(context, api.supported_comment_interfaces()) if not container: err_msg = 'unsupported interface for show_comment_view found for ' \ 'context: %s' % context log.warn(err_msg) exception_response = ExceptionResponse(err_msg) exception_response.status = '500 Internal Server Error' return exception_response backto = { 'href': model_url(container, request), 'title': container.title, } # Get a layout layout_provider = get_layout_provider(context, request) layout = layout_provider('community') if support_attachments(context): attachments = fetch_attachments(context, request) else: attachments = () return render_template_to_response( 'templates/show_comment.pt', api=api, actions=actions, byline_info=byline_info, attachments=attachments, backto=backto, layout=layout, )
def support_attachments(self): return support_attachments(self.context)