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_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_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 = 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, )