def attachments(context, request, other_context=None): if other_context: context = other_context has_attachments = 'attachments' in context and context['attachments'] get_attachments = getattr(context, 'get_attachments', None) if not get_attachments and not has_attachments: return '' folder = has_attachments or get_attachments() return {'attachments': fetch_attachments(folder, request)}
def show_newsitem_view(context, request): backto = { 'href': resource_url(context.__parent__, request), 'title': context.__parent__.title, } actions = [] if has_permission('edit', context, request): actions.append(('Edit', 'edit.html')) if has_permission('delete', context, request): actions.append(('Delete', 'delete.html')) if has_permission('administer', context, request): actions.append(('Advanced', 'advanced.html')) page_title = context.title api = TemplateAPI(context, request, page_title) previous, next = get_previous_next(context, request) # provide client data for rendering current tags in the tagbox client_json_data = dict( tagbox = get_tags_client_data(context, request), ) # Display photo photo = context.get('photo') if photo is not None: photo = { "url": thumb_url(photo, request, PHOTO_DISPLAY_SIZE), } # Get a layout layout_provider = get_layout_provider(context, request) layout = layout_provider('generic') ux2_layout = request.layout_manager.layout ux2_layout.section_style = None return render_to_response( 'templates/show_newsitem.pt', dict(api=api, actions=actions, attachments=fetch_attachments(context['attachments'], request), formfields=api.formfields, head_data=convert_to_script(client_json_data), backto=backto, previous=previous, next=next, old_layout=layout, photo=photo), request=request, )
def show_newsitem_view(context, request): backto = { 'href': resource_url(context.__parent__, request), 'title': context.__parent__.title, } actions = [] if has_permission('edit', context, request): actions.append(('Edit', 'edit.html')) if has_permission('delete', context, request): actions.append(('Delete', 'delete.html')) if has_permission('administer', context, request): actions.append(('Advanced', 'advanced.html')) page_title = context.title api = TemplateAPI(context, request, page_title) previous, next = get_previous_next(context, request) # provide client data for rendering current tags in the tagbox client_json_data = dict(tagbox=get_tags_client_data(context, request), ) # Display photo photo = context.get('photo') if photo is not None: photo = { "url": thumb_url(photo, request, PHOTO_DISPLAY_SIZE), } # Get a layout layout_provider = get_layout_provider(context, request) layout = layout_provider('generic') ux2_layout = request.layout_manager.layout ux2_layout.section_style = None return render_to_response( 'templates/show_newsitem.pt', dict(api=api, actions=actions, attachments=fetch_attachments(context['attachments'], request), formfields=api.formfields, head_data=convert_to_script(client_json_data), backto=backto, previous=previous, next=next, old_layout=layout, photo=photo), request=request, )
def show_newsitem_view(context, request): backto = { 'href': model_url(context.__parent__, request), 'title': context.__parent__.title, } actions = [] if has_permission('create', context, request): actions.append( ('Edit', 'edit.html') ) actions.append( ('Delete', 'delete.html'), ) page_title = context.title api = TemplateAPI(context, request, page_title) previous, next = get_previous_next(context, request) # provide client data for rendering current tags in the tagbox client_json_data = dict( tagbox = get_tags_client_data(context, request), ) # Display photo photo = context.get_photo() if photo is not None: photo = { "url": model_url(photo, request), } # Get a layout layout_provider = get_layout_provider(context, request) layout = layout_provider('generic') return render_template_to_response( 'templates/show_newsitem.pt', api=api, actions=actions, attachments=fetch_attachments(context['attachments'], request), formfields=api.formfields, head_data=convert_to_script(client_json_data), backto=backto, previous=previous, next=next, layout=layout, photo=photo, )
def comments(context, request): profiles = find_profiles(context) karldates = request.registry.getUtility(IKarlDates) comments = [] for comment in context['comments'].values(): profile = profiles.get(comment.creator) author_name = profile.title author_url = resource_url(profile, request) newc = {} newc['id'] = comment.__name__ if has_permission('edit', comment, request): newc['edit_url'] = resource_url(comment, request, 'edit.html') else: newc['edit_url'] = None if has_permission('delete', comment, request): newc['delete_url'] = resource_url(comment, request, 'delete.html') else: newc['delete_url'] = None if has_permission('administer', comment, request): newc['advanced_url'] = resource_url(comment, request, 'advanced.html') else: newc['advanced_url'] = None # Display portrait photo = profile.get('photo') if photo is not None: photo_url = thumb_url(photo, request, PROFILE_THUMB_SIZE) else: photo_url = request.static_url( "karl.views:static/images/defaultUser.gif") newc["portrait_url"] = photo_url newc['author_url'] = author_url newc['author_name'] = author_name newc['date'] = karldates(comment.created, 'longform') newc['timestamp'] = comment.created newc['text'] = comment.text # Fetch the attachments info newc['attachments'] = fetch_attachments(comment, request) comments.append(newc) comments.sort(key=lambda c: c['timestamp']) return {'comments': comments}
def show_blogentry_view(context, request): post_url = resource_url(context, request, "comments", "add_comment.html") workflow = get_workflow(IBlogEntry, 'security', context) if workflow is None: security_states = [] else: security_states = get_security_states(workflow, context, request) page_title = context.title api = TemplateAPI(context, request, page_title) client_json_data = dict( tagbox=get_tags_client_data(context, request)) actions = [] if has_permission('edit', context, request): actions.append(('Edit', 'edit.html')) if has_permission('edit', context, request): actions.append(('Delete', 'delete.html')) if has_permission('administer', context, request): actions.append(('Advanced', 'advanced.html')) api.is_taggable = True byline_info = getMultiAdapter((context, request), IBylineInfo) blog = find_interface(context, IBlog) backto = { 'href': resource_url(blog, request), 'title': blog.title, } comments = get_comment_data(context, context['comments'], api, request) comment_form = get_comment_form(context, context['comments'], api, request) return dict( api=api, actions=actions, comments=comments, attachments=fetch_attachments( context['attachments'], request), head_data=convert_to_script(client_json_data), comment_form=comment_form, post_url=post_url, byline_info=byline_info, backto=backto, security_states=security_states, )
def show_page_view(context, request): backto = { 'href': resource_url(context.__parent__, request), 'title': context.__parent__.title, } actions = [] if has_permission('edit', context, request): actions.append(('Edit', 'edit.html')) if has_permission('delete', context, request): actions.append(('Delete', 'delete.html')) if has_permission('administer', context, request): actions.append(('Advanced', 'advanced.html')) page_title = context.title api = TemplateAPI(context, request, page_title) previous, next = get_previous_next(context, request) # provide client data for rendering current tags in the tagbox client_json_data = dict( tagbox = get_tags_client_data(context, request), ) # Get a layout community = find_community(context) layout_provider = get_layout_provider(context, request) if community is not None: layout = layout_provider('community') else: layout = layout_provider('generic') ux2_layout = request.layout_manager.layout ux2_layout.section_style = "none" return render_to_response( 'templates/show_page.pt', dict(api=api, actions=actions, attachments=fetch_attachments(context['attachments'], request), formfields=api.formfields, head_data=convert_to_script(client_json_data), backto=backto, previous_entry=previous, next_entry=next, old_layout=layout), request = request, )
def get_comment_data(context, comments_folder, api, request): # get comment data to be used to render comments profiles = find_profiles(comments_folder) karldates = getUtility(IKarlDates) comments = [] for comment in comments_folder.values(): profile = profiles.get(comment.creator) author_name = profile.title author_url = resource_url(profile, request) newc = {} newc['id'] = comment.__name__ if has_permission('edit', comment, request): newc['edit_url'] = resource_url(comment, request, 'edit.html') else: newc['edit_url'] = None if has_permission('delete', comment, request): newc['delete_url'] = resource_url(comment, request, 'delete.html') else: newc['delete_url'] = None if has_permission('administer', comment, request): newc['advanced_url'] = resource_url(comment, request, 'advanced.html') else: newc['advanced_url'] = None # Display portrait photo = profile.get('photo') if photo is not None: photo_url = thumb_url(photo, request, PROFILE_THUMB_SIZE) else: photo_url = api.static_url + "/images/defaultUser.gif" newc["portrait_url"] = photo_url newc['author_url'] = author_url newc['author_name'] = author_name newc['date'] = karldates(comment.created, 'longform') newc['timestamp'] = comment.created newc['text'] = comment.text # Fetch the attachments info newc['attachments'] = fetch_attachments(comment, request) comments.append(newc) comments.sort(key=lambda c: c['timestamp']) return comments
def show_page_view(context, request): backto = { 'href': resource_url(context.__parent__, request), 'title': context.__parent__.title, } actions = [] if has_permission('edit', context, request): actions.append(('Edit', 'edit.html')) if has_permission('delete', context, request): actions.append(('Delete', 'delete.html')) if has_permission('administer', context, request): actions.append(('Advanced', 'advanced.html')) page_title = context.title api = TemplateAPI(context, request, page_title) previous, next = get_previous_next(context, request) # provide client data for rendering current tags in the tagbox client_json_data = dict(tagbox=get_tags_client_data(context, request), ) # Get a layout community = find_community(context) layout_provider = get_layout_provider(context, request) if community is not None: layout = layout_provider('community') else: layout = layout_provider('generic') ux2_layout = request.layout_manager.layout ux2_layout.section_style = "none" return render_to_response( 'templates/show_page.pt', dict(api=api, actions=actions, attachments=fetch_attachments(context['attachments'], request), formfields=api.formfields, head_data=convert_to_script(client_json_data), backto=backto, previous_entry=previous, next_entry=next, old_layout=layout), request=request, )
def show_blogentry_view(context, request): post_url = resource_url(context, request, "comments", "add_comment.html") workflow = get_workflow(IBlogEntry, 'security', context) if workflow is None: security_states = [] else: security_states = get_security_states(workflow, context, request) page_title = context.title api = TemplateAPI(context, request, page_title) client_json_data = dict(tagbox=get_tags_client_data(context, request)) actions = [] if has_permission('edit', context, request): actions.append(('Edit', 'edit.html')) if has_permission('edit', context, request): actions.append(('Delete', 'delete.html')) if has_permission('administer', context, request): actions.append(('Advanced', 'advanced.html')) api.is_taggable = True byline_info = getMultiAdapter((context, request), IBylineInfo) blog = find_interface(context, IBlog) backto = { 'href': resource_url(blog, request), 'title': blog.title, } comments = get_comment_data(context, context['comments'], api, request) comment_form = get_comment_form(context, context['comments'], api, request) return dict( api=api, actions=actions, comments=comments, attachments=fetch_attachments(context['attachments'], request), head_data=convert_to_script(client_json_data), comment_form=comment_form, post_url=post_url, byline_info=byline_info, backto=backto, security_states=security_states, )
def show_comment_view(context, request): page_title = "Comment on " + context.title api = TemplateAPI(context, request, 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')) if has_permission('administer', context, request): actions.append(('Advanced', 'advanced.html')) byline_info = getMultiAdapter((context, request), IBylineInfo) container = find_interface(context, IBlogEntry) if container is None: # Comments can also be in forum topics container = find_interface(context, IForumTopic) if container is None: # Comments can also be files container = find_interface(context, ICommunityFile) backto = { 'href': resource_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_to_response( 'templates/show_comment.pt', dict(api=api, actions=actions, byline_info=byline_info, attachments=attachments, backto=backto, layout=layout), request=request, )
def show_comment_view(context, request): page_title = "Comment on " + context.title api = TemplateAPI(context, request, 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')) if has_permission('administer', context, request): actions.append(('Advanced', 'advanced.html')) byline_info = getMultiAdapter((context, request), IBylineInfo) container = find_interface(context, IBlogEntry) if container is None: # Comments can also be in forum topics container = find_interface(context, IForumTopic) backto = { 'href': resource_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_to_response( 'templates/show_comment.pt', dict(api=api, actions=actions, byline_info=byline_info, attachments=attachments, backto=backto, old_layout=layout), request=request, )
def show_blogentry_view(context, request): post_url = resource_url(context, request, "comments", "add_comment.html") karldates = getUtility(IKarlDates) profiles = find_profiles(context) workflow = get_workflow(IBlogEntry, 'security', context) if workflow is None: security_states = [] else: security_states = get_security_states(workflow, context, request) # Convert blog comments into a digestable form for the template comments = [] page_title = context.title api = TemplateAPI(context, request, page_title) for comment in context['comments'].values(): profile = profiles.get(comment.creator) author_name = profile.title author_url = resource_url(profile, request) newc = {} newc['id'] = comment.__name__ if has_permission('edit', comment, request): newc['edit_url'] = resource_url(comment, request, 'edit.html') else: newc['edit_url'] = None if has_permission('delete', comment, request): newc['delete_url'] = resource_url(comment, request, 'delete.html') else: newc['delete_url'] = None if has_permission('administer', comment, request): newc['advanced_url'] = resource_url(comment, request, 'advanced.html') else: newc['advanced_url'] = None # Display portrait photo = profile.get('photo') if photo is not None: photo_url = thumb_url(photo, request, PROFILE_THUMB_SIZE) else: photo_url = api.static_url + "/images/defaultUser.gif" newc["portrait_url"] = photo_url newc['author_url'] = author_url newc['author_name'] = author_name newc['date'] = karldates(comment.created, 'longform') newc['timestamp'] = comment.created newc['text'] = comment.text # Fetch the attachments info newc['attachments'] = fetch_attachments(comment, request) comments.append(newc) comments.sort(key=lambda c: c['timestamp']) client_json_data = dict( tagbox = get_tags_client_data(context, request), ) actions = [] if has_permission('edit', context, request): actions.append(('Edit', 'edit.html')) if has_permission('edit', context, request): actions.append(('Delete', 'delete.html')) if has_permission('administer', context, request): actions.append(('Advanced', 'advanced.html')) api.is_taggable = True byline_info = getMultiAdapter((context, request), IBylineInfo) blog = find_interface(context, IBlog) backto = { 'href': resource_url(blog, request), 'title': blog.title, } # manually construct formish comment form controller = AddCommentFormController(context['comments'], request) form_schema = schemaish.Structure() form_fields = controller.form_fields() for fieldname, field in form_fields: form_schema.add(fieldname, field) form_action_url = '%sadd_comment.html' % resource_url(context['comments'], request) comment_form = Form(form_schema, add_default_action=False, name='save', action_url=form_action_url) form_defaults = controller.form_defaults() comment_form.defaults = form_defaults request.form_defaults = form_defaults form_actions = [FormAction('submit', 'submit'), FormAction('cancel', 'cancel', validate=False)] for action in form_actions: comment_form.add_action(action.name, action.title) widgets = controller.form_widgets(form_fields) for name, widget in widgets.items(): comment_form[name].widget = widget # this is for enable imagedrawer for adding blog comments api.karl_client_data['text'] = dict( enable_imagedrawer_upload = True, ) return dict( api=api, actions=actions, comments=comments, attachments=fetch_attachments( context['attachments'], request), head_data=convert_to_script(client_json_data), comment_form=comment_form, post_url=post_url, byline_info=byline_info, backto=backto, security_states = security_states, )
else: security_state = workflow.state_of(context) fill_values = dict( add_comment=context.text, security_state = security_state) # Render the form and shove some default values in page_title = 'Edit ' + context.title api = TemplateAPI(context, request, page_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_form_to_response( 'templates/edit_comment.pt', form, fill_values, post_url=request.url, formfields=api.formfields, fielderrors=fielderrors, api=api, attachments=attachments, layout=layout, security_states = security_states, )
def show_blogentry_view(context, request): post_url = resource_url(context, request, "comments", "add_comment.html") karldates = getUtility(IKarlDates) profiles = find_profiles(context) workflow = get_workflow(IBlogEntry, 'security', context) if workflow is None: security_states = [] else: security_states = get_security_states(workflow, context, request) # Convert blog comments into a digestable form for the template comments = [] page_title = context.title api = TemplateAPI(context, request, page_title) for comment in context['comments'].values(): profile = profiles.get(comment.creator) author_name = profile.title author_url = resource_url(profile, request) newc = {} newc['id'] = comment.__name__ if has_permission('edit', comment, request): newc['edit_url'] = resource_url(comment, request, 'edit.html') else: newc['edit_url'] = None if has_permission('delete', comment, request): newc['delete_url'] = resource_url(comment, request, 'delete.html') else: newc['delete_url'] = None if has_permission('administer', comment, request): newc['advanced_url'] = resource_url(comment, request, 'advanced.html') else: newc['advanced_url'] = None # Display portrait photo = profile.get('photo') if photo is not None: photo_url = thumb_url(photo, request, PROFILE_THUMB_SIZE) else: photo_url = api.static_url + "/images/defaultUser.gif" newc["portrait_url"] = photo_url newc['author_url'] = author_url newc['author_name'] = author_name newc['date'] = karldates(comment.created, 'longform') newc['timestamp'] = comment.created newc['text'] = comment.text # Fetch the attachments info newc['attachments'] = fetch_attachments(comment, request) comments.append(newc) comments.sort(key=lambda c: c['timestamp']) client_json_data = dict(tagbox=get_tags_client_data(context, request), ) actions = [] if has_permission('edit', context, request): actions.append(('Edit', 'edit.html')) if has_permission('edit', context, request): actions.append(('Delete', 'delete.html')) if has_permission('administer', context, request): actions.append(('Advanced', 'advanced.html')) api.is_taggable = True byline_info = getMultiAdapter((context, request), IBylineInfo) blog = find_interface(context, IBlog) backto = { 'href': resource_url(blog, request), 'title': blog.title, } # manually construct formish comment form controller = AddCommentFormController(context['comments'], request) form_schema = schemaish.Structure() form_fields = controller.form_fields() for fieldname, field in form_fields: form_schema.add(fieldname, field) form_action_url = '%sadd_comment.html' % resource_url( context['comments'], request) comment_form = Form(form_schema, add_default_action=False, name='save', action_url=form_action_url) form_defaults = controller.form_defaults() comment_form.defaults = form_defaults request.form_defaults = form_defaults form_actions = [ FormAction('submit', 'submit'), FormAction('cancel', 'cancel', validate=False) ] for action in form_actions: comment_form.add_action(action.name, action.title) widgets = controller.form_widgets(form_fields) for name, widget in widgets.items(): comment_form[name].widget = widget # this is for enable imagedrawer for adding blog comments api.karl_client_data['text'] = dict(enable_imagedrawer_upload=True, ) return dict( api=api, actions=actions, comments=comments, attachments=fetch_attachments(context['attachments'], request), head_data=convert_to_script(client_json_data), comment_form=comment_form, post_url=post_url, byline_info=byline_info, backto=backto, security_states=security_states, )
def show_blogentry_view(context, request): post_url = model_url(context, request, "comments", "add_comment.html") karldates = getUtility(IKarlDates) profiles = find_profiles(context) workflow = get_workflow(IBlogEntry, 'security', context) if workflow is None: security_states = [] else: security_states = get_security_states(workflow, context, request) # Convert blog comments into a digestable form for the template comments = [] page_title = context.title api = TemplateAPI(context, request, page_title) for comment in context['comments'].values(): profile = profiles.get(comment.creator) author_name = profile.title author_url = model_url(profile, request) newc = {} newc['id'] = comment.__name__ if has_permission('edit', comment, request): newc['edit_url'] = model_url(comment, request, 'edit.html') else: newc['edit_url'] = None if has_permission('delete', comment, request): newc['delete_url'] = model_url(comment, request, 'delete.html') else: newc['delete_url'] = None # Display portrait photo = profile.get_photo() photo_url = {} if photo is not None: photo_url = model_url(photo, request) else: photo_url = api.static_url + "/images/defaultUser.gif" newc["portrait_url"] = photo_url newc['author_url'] = author_url newc['author_name'] = author_name newc['date'] = karldates(comment.created, 'longform') newc['timestamp'] = comment.created newc['text'] = comment.text # Fetch the attachments info newc['attachments'] = fetch_attachments(comment, request) comments.append(newc) comments.sort(key=lambda c: c['timestamp']) client_json_data = dict( tagbox = get_tags_client_data(context, request), ) actions = [] if has_permission('edit', context, request): actions.append(('Edit', 'edit.html')) if has_permission('edit', context, request): actions.append(('Delete', 'delete.html')) api.is_taggable = True byline_info = getMultiAdapter((context, request), IBylineInfo) blog = find_interface(context, IBlog) backto = { 'href': model_url(blog, request), 'title': blog.title, } return render_template_to_response( 'templates/show_blogentry.pt', api=api, actions=actions, comments=comments, attachments=fetch_attachments(context['attachments'], request), head_data=convert_to_script(client_json_data), formfields=api.formfields, post_url=post_url, byline_info=byline_info, backto=backto, security_states = security_states, )
def show_forum_topic_view(context, request): post_url = model_url(context, request, "comments", "add_comment.html") karldates = getUtility(IKarlDates) profiles = find_profiles(context) # Convert comments into a digestable form for the template comments = [] 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 = TemplateAPI(context, request, page_title) for comment in context['comments'].values(): profile = profiles.get(comment.creator) author_name = profile.title author_url = model_url(profile, request) newc = {} newc['id'] = comment.__name__ if has_permission('edit', comment, request): newc['edit_url'] = model_url(comment, request, 'edit.html') newc['delete_url'] = model_url(comment, request, 'delete.html') else: newc['edit_url'] = None newc['delete_url'] = None # Display portrait photo = profile.get_photo() photo_url = {} if photo is not None: photo_url = model_url(photo, request) else: photo_url = api.static_url + "/images/defaultUser.gif" newc["portrait_url"] = photo_url newc['author_url'] = author_url newc['author_name'] = author_name newc['date'] = karldates(comment.created, 'longform') newc['timestamp'] = comment.created newc['text'] = comment.text # Fetch the attachments info newc['attachments'] = fetch_attachments(comment, request) comments.append(newc) comments.sort(key=lambda x: x['timestamp']) 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 = () return render_template_to_response( 'templates/show_forum_topic.pt', api=api, actions=actions, comments=comments, 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, )
def show_forum_topic_view(context, request): post_url = resource_url(context, request, "comments", "add_comment.html") karldates = getUtility(IKarlDates) profiles = find_profiles(context) # Convert comments into a digestable form for the template comments = [] 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')) if has_permission('administer', context, request): actions.append(('Advanced', 'advanced.html')) api = TemplateAPI(context, request, page_title) for comment in context['comments'].values(): profile = profiles.get(comment.creator) author_name = profile.title author_url = resource_url(profile, request) newc = {} newc['id'] = comment.__name__ if has_permission('edit', comment, request): newc['edit_url'] = resource_url(comment, request, 'edit.html') else: newc['edit_url'] = None if has_permission('delete', comment, request): newc['delete_url'] = resource_url(comment, request, 'delete.html') else: newc['delete_url'] = None if has_permission('administer', comment, request): newc['advanced_url'] = resource_url(comment, request, 'advanced.html') else: newc['advanced_url'] = None # Display portrait photo = profile.get('photo') photo_url = {} if photo is not None: photo_url = thumb_url(photo, request, PROFILE_THUMB_SIZE) else: photo_url = api.static_url + "/images/defaultUser.gif" newc["portrait_url"] = photo_url newc['author_url'] = author_url newc['author_name'] = author_name newc['date'] = karldates(comment.created, 'longform') newc['timestamp'] = comment.created newc['text'] = comment.text # Fetch the attachments info newc['attachments'] = fetch_attachments(comment, request) comments.append(newc) comments.sort(key=lambda x: x['timestamp']) byline_info = getMultiAdapter((context, request), IBylineInfo) forum = find_interface(context, IForum) backto = { 'href': resource_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) old_layout = layout_provider('community') if support_attachments(context): attachments = fetch_attachments(context['attachments'], request) else: attachments = () # manually construct formish comment form controller = AddCommentFormController(context['comments'], request) form_schema = schemaish.Structure() form_fields = controller.form_fields() for fieldname, field in form_fields: form_schema.add(fieldname, field) form_action_url = '%sadd_comment.html' % resource_url(context['comments'], request) comment_form = Form(form_schema, add_default_action=False, name='save', action_url=form_action_url) form_defaults = controller.form_defaults() comment_form.defaults = form_defaults request.form_defaults = form_defaults form_actions = [FormAction('submit', 'submit'), FormAction('cancel', 'cancel', validate=False)] for action in form_actions: comment_form.add_action(action.name, action.title) widgets = controller.form_widgets(form_fields) for name, widget in widgets.items(): comment_form[name].widget = widget # enable imagedrawer for adding forum replies (comments) api.karl_client_data['text'] = dict( enable_imagedrawer_upload = True, ) # ux2 layout = request.layout_manager.layout layout.section_style = "none" layout.head_data['panel_data']['tinymce'] = api.karl_client_data['text'] layout.head_data['panel_data']['tagbox'] = client_json_data['tagbox'] layout.add_portlet('tagbox') return render_to_response( 'templates/show_forum_topic.pt', dict(api=api, actions=actions, comments=comments, attachments=attachments, formfields=api.formfields, post_url=post_url, byline_info=byline_info, head_data=convert_to_script(client_json_data), backto=backto, old_layout=old_layout, comment_form=comment_form), request=request, )
def show_calendarevent_view(context, request): 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')) if has_permission('administer', context, request): actions.append(('Advanced', 'advanced.html')) api = TemplateAPI(context, request, page_title) container = context.__parent__ backto = { 'href': model_url(container, request), 'title': container.title, } # Flatten the data into ZPT-friendly info karldates = getUtility(IKarlDates) title = context.title startDate = karldates(context.startDate, 'longform') endDate = karldates(context.endDate, 'longform') attendees = None if context.attendees: attendees = '; '.join(context.attendees) location = context.location contact_name = context.contact_name contact_email = context.contact_email # Get a layout layout_provider = get_layout_provider(context, request) layout = layout_provider('community') # find this event's calendar category title calendar = find_interface(context, ICalendar) if calendar is not None: titles = {} for cat in _get_calendar_categories(calendar): titles[model_path(cat)] = cat.title category_title = titles.get(context.calendar_category) else: category_title = None return render_template_to_response( 'templates/show_calendarevent.pt', api=api, actions=actions, head_data=convert_to_script(dict( tagbox = get_tags_client_data(context, request), )), title=title, startDate=startDate, endDate=endDate, attendees=attendees, location=location, contact_name=contact_name, contact_email=contact_email, category_title=category_title, attachments=fetch_attachments(context['attachments'], request), backto=backto, layout=layout, )