def show_wikipage_view(context, request): layout = request.layout_manager.layout is_front_page = (context.__name__ == 'front_page') if is_front_page: community = find_interface(context, ICommunity) layout.page_title = '%s Community Wiki Page' % community.title backto = False else: layout.page_title = context.title backto = { 'href': resource_url(context.__parent__, request), 'title': context.__parent__.title, } actions = [] if has_permission('edit', context, request): actions.append(('Edit', resource_url(context, request, 'edit.html'))) if has_permission('delete', context, request) and not is_front_page: actions.append(('Delete', resource_url(context, request, 'delete.html'))) repo = find_repo(context) show_trash = False if not find_interface(context, IIntranets): if repo is not None and has_permission('edit', context, request): actions.append( ('History', resource_url(context, request, 'history.html'))) show_trash = True if has_permission('administer', context, request): actions.append( ('Advanced', resource_url(context, request, 'advanced.html'))) api = TemplateAPI(context, request, layout.page_title) client_json_data = dict(tagbox=get_tags_client_data(context, request), ) panel_data = layout.head_data['panel_data'] panel_data['tagbox'] = client_json_data['tagbox'] layout.add_portlet('recent_activity') wiki = find_interface(context, IWiki) feed_url = resource_url(wiki, request, "atom.xml") return dict( api=api, actions=actions, head_data=convert_to_script(client_json_data), feed_url=feed_url, backto=backto, is_front_page=is_front_page, show_trash=show_trash, lock_info=lock.lock_info_for_view(context, request), )
def show_wikipage_view(context, request): layout = request.layout_manager.layout is_front_page = (context.__name__ == 'front_page') if is_front_page: community = find_interface(context, ICommunity) layout.page_title = '%s Community Wiki Page' % community.title backto = False else: layout.page_title = context.title backto = { 'href': resource_url(context.__parent__, request), 'title': context.__parent__.title, } actions = [] if has_permission('edit', context, request): actions.append(('Edit', resource_url(context, request, 'edit.html'))) if has_permission('delete', context, request) and not is_front_page: actions.append(('Delete', resource_url(context, request, 'delete.html'))) repo = find_repo(context) show_trash = False if not find_interface(context, IIntranets): if repo is not None and has_permission('edit', context, request): actions.append(('History', resource_url(context, request, 'history.html'))) show_trash = True if has_permission('administer', context, request): actions.append(('Advanced', resource_url(context, request, 'advanced.html'))) api = TemplateAPI(context, request, layout.page_title) client_json_data = dict( tagbox = get_tags_client_data(context, request), ) panel_data = layout.head_data['panel_data'] panel_data['tagbox'] = client_json_data['tagbox'] layout.add_portlet('recent_activity') wiki = find_interface(context, IWiki) feed_url = resource_url(wiki, request, "atom.xml") return dict( api=api, actions=actions, head_data=convert_to_script(client_json_data), feed_url=feed_url, backto=backto, is_front_page=is_front_page, show_trash=show_trash, lock_info=lock.lock_info_for_view(context, request), )
def archive_portlet(context, request): blog = find_interface(context, IBlog) counts = {} # {(year, month): count} for entry in blog.values(): if not IBlogEntry.providedBy(entry): continue if not has_permission('view', entry, request): continue year = entry.created.year month = entry.created.month counts[(year, month)] = counts.get((year, month), 0) + 1 counts = counts.items() counts.sort() counts.reverse() return { 'archive': [ MonthlyActivity( year, month, count, request.resource_url(blog, query={ 'year': year, 'month': month })) for ((year, month), count) in counts ] }
def preview_wikipage_view(context, request, WikiPage=WikiPage): version_num = int(request.params['version_num']) repo = find_repo(context) for version in repo.history(context.docid): if version.version_num == version_num: break else: raise NotFound("No such version: %d" % version_num) page = WikiPage() page.__parent__ = context.__parent__ page.revert(version) is_front_page = (context.__name__ == 'front_page') if is_front_page: community = find_interface(context, ICommunity) page_title = '%s Community Wiki Page' % community.title else: page_title = page.title profiles = find_profiles(context) author = profiles[version.user] # Extra paranoia, probably not strictly necessary. I just want to make # extra special sure that the temp WikiPage object we create above # doesn't accidentally get attached to the persistent object graph. transaction.doom() return { 'date': format_local_date(version.archive_time), 'author': author.title, 'title': page_title, 'body': page.cook(request), }
def preview_wikipage_view(context, request, WikiPage=WikiPage, tz=None): version_num = int(request.params['version_num']) repo = find_repo(context) for version in repo.history(context.docid): if version.version_num == version_num: break else: raise NotFound("No such version: %d" % version_num) page = WikiPage() page.__parent__ = context.__parent__ page.revert(version) is_front_page = (context.__name__ == 'front_page') if is_front_page: community = find_interface(context, ICommunity) page_title = '%s Community Wiki Page' % community.title else: page_title = page.title profiles = find_profiles(context) author = profiles[version.user] # Extra paranoia, probably not strictly necessary. I just want to make # extra special sure that the temp WikiPage object we create above # doesn't accidentally get attached to the persistent object graph. transaction.doom() return { 'date': format_local_date(version.archive_time, tz), 'author': author.title, 'title': page_title, 'body': page.cook(request), }
def archive_portlet(context, request): with context._p_jar._storage.ex_cursor() as cursor: community = find_community(context) community_cond = qbe.sql(context._p_jar, dict(community=community)) cursor.execute( """ select month, count(*) from ( select substring(state->>'created' from 1 for 7) as month from newt natural join karlex where class_name = 'karl.content.models.blog.BlogEntry' and """ + community_cond + """ and newt_can_view(state, %s) ) _ group by month order by month desc """, (effective_principals(request), )) blog = find_interface(context, IBlog) return { 'archive': [ MonthlyActivity( year, month, count, request.resource_url(blog, query={ 'year': year, 'month': month })) for (year, month, count) in ((month[:4], month[-2:], count) for month, count in cursor) ] }
def show_wikipage_view(context, request): is_front_page = (context.__name__ == 'front_page') if is_front_page: community = find_interface(context, ICommunity) page_title = '%s Community Wiki Page' % community.title backto = False else: page_title = context.title backto = { 'href': model_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) and not is_front_page: actions.append(('Delete', 'delete.html')) repo = find_repo(context) if repo is not None and has_permission('edit', context, request): actions.append(('History', 'history.html')) show_trash = True else: show_trash = False if has_permission('administer', context, request): actions.append(('Advanced', 'advanced.html')) api = TemplateAPI(context, request, page_title) client_json_data = convert_to_script(dict( tagbox = get_tags_client_data(context, request), )) wiki = find_interface(context, IWiki) feed_url = model_url(wiki, request, "atom.xml") return dict( api=api, actions=actions, head_data=client_json_data, feed_url=feed_url, backto=backto, is_front_page=is_front_page, show_trash=show_trash, lock_info=lock.lock_info_for_view(context, 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) 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 exclude_tools(self): # Find out if we are adding this community from somewhere # inside the "intranets" side intranets = find_interface(self.context, IIntranets) site = ISite.providedBy(self.context) if intranets or site: return ['wiki', 'blog'] return ['intranets', 'forums']
def show_wikitoc_view(context, request): is_front_page = (context.__name__ == 'front_page') if is_front_page: community = find_interface(context, ICommunity) page_title = '%s Community Wiki Page' % community.title backto = False else: page_title = context.title backto = { 'href': resource_url(context.__parent__, request), 'title': context.__parent__.title, } actions = [] api = TemplateAPI(context, request, page_title) wikitoc_data = get_wikitoc_data(context, request) page_data = dict( wikitoc = wikitoc_data, ) # ... for ux1 client_json_data = convert_to_script(page_data) # ... for ux2 request.layout_manager.layout.head_data['page_data'] = page_data wiki = find_interface(context, IWiki) feed_url = resource_url(wiki, request, "atom.xml") repo = find_repo(context) show_trash = repo is not None and has_permission('edit', context, request) return dict(api=api, actions=actions, head_data=client_json_data, feed_url=feed_url, backto=backto, lock_info=lock.lock_info_for_view(context, request), show_trash=show_trash, )
def show_wikitoc_view(context, request): is_front_page = (context.__name__ == 'front_page') if is_front_page: community = find_interface(context, ICommunity) page_title = '%s Community Wiki Page' % community.title backto = False else: page_title = context.title backto = { 'href': resource_url(context.__parent__, request), 'title': context.__parent__.title, } actions = [] api = TemplateAPI(context, request, page_title) wikitoc_data = get_wikitoc_data(context, request) page_data = dict(wikitoc=wikitoc_data, ) # ... for ux1 client_json_data = convert_to_script(page_data) # ... for ux2 request.layout_manager.layout.head_data['page_data'] = page_data wiki = find_interface(context, IWiki) feed_url = resource_url(wiki, request, "atom.xml") repo = find_repo(context) show_trash = repo is not None and has_permission('edit', context, request) return dict( api=api, actions=actions, head_data=client_json_data, feed_url=feed_url, backto=backto, lock_info=lock.lock_info_for_view(context, request), show_trash=show_trash, )
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_wikitoc_view(context, request): is_front_page = (context.__name__ == 'front_page') if is_front_page: community = find_interface(context, ICommunity) page_title = '%s Community Wiki Page' % community.title backto = False else: page_title = context.title backto = { 'href': model_url(context.__parent__, request), 'title': context.__parent__.title, } actions = [] api = TemplateAPI(context, request, page_title) wikitoc_data = get_wikitoc_data(context, request) client_json_data = convert_to_script(dict( wikitoc = wikitoc_data, )) wiki = find_interface(context, IWiki) feed_url = model_url(wiki, request, "atom.xml") repo = find_repo(context) show_trash = repo is not None and has_permission('edit', context, request) return render_template_to_response( 'templates/show_wikitoc.pt', api=api, actions=actions, head_data=client_json_data, feed_url=feed_url, backto=backto, show_trash=show_trash, )
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 init_history(docid, path, repo, site): if repo.history(docid, True): # Already in repo return context = find_resource(site, path) if context.__name__ == 'TEMP': return if find_interface(context, IIntranets): return version = queryAdapter(context, IObjectVersion) if version is not None: print "Updating version for %s" % resource_path(context) repo.archive(version) context._p_deactivate()
def _getInfo(profile, content): community = context = find_community(content) if context is None: # try for content inside a profile context = find_interface(content, IProfile) if context is None: context_name = context_url = None else: context_name = context.title context_url = resource_path(context) tagger = find_tags(content) if tagger is not None: cloud = list(tagger.getCloud(items=(content.docid,))) tag_counts = sorted(cloud, key=lambda x: x[1], reverse=True)[:3] tags = [x[0] for x in tag_counts] else: tags = () content_type = get_content_type(content) desc = getattr(content, 'description', '') short = len(desc) > 256 and '%s...' % desc[:256] or desc if IPosts.providedBy(content): comment_count = len(content.get('comments', ())) else: comment_count = False content_creator = profile.__name__ if IComment.providedBy(content): # my content filter needs to know if a comment was made inside my post content_creator = content.__parent__.__parent__.creator return {'content_type': content_type.getTaggedValue('name'), 'userid': profile.__name__, 'context_name': context_name, 'context_url': context_url, 'content_creator': content_creator, 'url': resource_path(content), 'title': content.title, 'description': desc, 'short_description': short, 'allowed': principals_allowed_by_permission(content, 'view'), 'comment_count': comment_count, 'tags': tags, #XXX 'author': profile.title, 'profile_url': '/profiles/%s' % profile.__name__, 'thumbnail': '/profiles/%s/profile_thumbnail' % profile.__name__, 'timestamp': _NOW(), }
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 archive_portlet(context, request): stmt = """SELECT date_part('year', creation_date) as y, date_part('month', creation_date) as m, count(*) FROM pgtextindex WHERE content_type='IBlogEntry' and community_docid='%s' GROUP BY y, m ORDER BY y DESC, m DESC""" community = find_community(context) blog = find_interface(context, IBlog) catalog = find_catalog(context) index = catalog['texts'] results = index.get_sql_catalog_results(stmt % community.docid) return {'archive': [MonthlyActivity(year, month, count, request.resource_url(blog, query={'year': year, 'month': month})) for (year, month, count) in results]}
def archive_portlet(context, request): blog = find_interface(context, IBlog) counts = {} # {(year, month): count} for entry in blog.values(): if not IBlogEntry.providedBy(entry): continue if not has_permission('view', entry, request): continue year = entry.created.year month = entry.created.month counts[(year, month)] = counts.get((year, month), 0) + 1 counts = counts.items() counts.sort() counts.reverse() return {'archive': [MonthlyActivity(year, month, count, request.resource_url(blog, query={'year': year, 'month': month})) for ((year, month), count) in counts]}
def _getInfo(profile, content): community = context = find_community(content) if context is None: # try for content inside a profile context = find_interface(content, IProfile) if context is None: context_name = context_url = None else: context_name = context.title context_url = resource_path(context) tagger = find_tags(content) if tagger is not None: cloud = list(tagger.getCloud(items=(content.docid,))) tag_counts = sorted(cloud, key=lambda x: x[1], reverse=True)[:3] tags = [x[0] for x in tag_counts] else: tags = () content_type = get_content_type(content) desc = getattr(content, "description", "") short = len(desc) > 80 and "%s..." % desc[:80] or desc if IPosts.providedBy(content): comment_count = len(content.get("comments", ())) else: comment_count = False content_creator = profile.__name__ if IComment.providedBy(content): # my content filter needs to know if a comment was made inside my post content_creator = content.__parent__.__parent__.creator return { "content_type": content_type.getTaggedValue("name"), "userid": profile.__name__, "context_name": context_name, "context_url": context_url, "content_creator": content_creator, "url": resource_path(content), "title": content.title, "description": desc, "short_description": short, "allowed": principals_allowed_by_permission(content, "view"), "comment_count": comment_count, "tags": tags, # XXX "author": profile.title, "profile_url": "/profiles/%s" % profile.__name__, "thumbnail": "/profiles/%s/profile_thumbnail" % profile.__name__, "timestamp": _NOW(), }
def form_widgets(self, fields): # compute category values calendar_categories = [] default_category = None calendar = find_interface(self.context, ICalendar) if calendar: default_category_name = ICalendarCategory.getTaggedValue('default_name') for category in _get_calendar_categories(calendar): category_tuple = (model_path(category), category.title) if category.__name__ == default_category_name: default_category = category_tuple else: calendar_categories.append(category_tuple) calendar_categories.sort(key=lambda x: x[1]) category_widget = formish.SelectChoice(calendar_categories) if default_category: category_widget.none_option = default_category widgets = { 'title': formish.Input(empty=''), 'category': category_widget, 'all_day': formish.Hidden(), 'start_date': karlwidgets.DateTime(), 'end_date': karlwidgets.DateTime(), 'location': formish.Input(empty=''), 'text': karlwidgets.RichTextWidget(empty=''), 'attendees': formish.TextArea(rows=5, cols=60), 'contact_name': formish.Input(empty=''), 'contact_email': formish.Input(empty=''), 'attachments': karlwidgets.AttachmentsSequence(sortable=False, min_start_fields=0), 'attachments.*': karlwidgets.FileUpload2(filestore=self.filestore), } schema = dict(fields) if 'security_state' in schema: security_states = self._get_security_states() widgets['security_state'] = formish.RadioChoice( options=[(s['name'], s['title']) for s in security_states], none_option=None) return widgets
def init_container(docid, path, repo, site): try: repo.container_contents(docid) # Already in repo return except NoResultFound: # Not in repo pass context = find_resource(site, path) if context.__name__ == 'TEMP': return if find_interface(context, IIntranets): return container = queryAdapter(context, IContainerVersion) if container is not None: print "Updating container version for %s" % resource_path(context) user = getattr(context, 'creator', None) if user is None: user = get_setting(context, 'system_user', 'admin') repo.archive_container(container, user) context._p_deactivate()
def handle_submit(self, converted): context = self.context request = self.request parent = context.__parent__ creator = authenticated_userid(request) comment = create_content( IComment, 'Re: %s' % parent.title, converted['add_comment'], extract_description(converted['add_comment']), creator, ) next_id = parent['comments'].next_id parent['comments'][next_id] = comment workflow = get_workflow(IComment, 'security', context) if workflow is not None: workflow.initialize(comment) if 'security_state' in converted: workflow.transition_to_state(comment, request, converted['security_state']) if support_attachments(comment): upload_attachments(converted['attachments'], comment, creator, request) relocate_temp_images(comment, request) blogentry = find_interface(context, IBlogEntry) if converted.get('sendalert'): alerts = queryUtility(IAlerts, default=Alerts()) alerts.emit(comment, request) location = resource_url(parent, request) msg = 'Comment added' location = '%s?status_message=%s' % (location, urllib.quote(msg)) self.filestore.clear() return HTTPFound(location=location)
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 handle_cancel(self): context = self.context blogentry = find_interface(self.context, IBlogEntry) return HTTPFound(location=model_url(blogentry, self.request))
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 add_comment_view(context, request): # This is NOT a self-posting form. The BlogEntry has the form # that submits to this view. Thus, we only need to handle # submission requests, then redirect back to the parent (the blog # entry). # Handle the Add Comment form #post_url = model_url(context, request, "comments/add_comment.html") form = AddCommentForm() # add the security state field if appropriate for the context workflow = get_workflow(IComment, 'security', context) if workflow is None: security_states = [] else: security_states = get_security_states(workflow, None, request) if security_states: form.add_field('security_state', security_state_field) if 'form.cancel' in request.POST: return HTTPFound(location=model_url(context.__parent__, request)) if 'form.submitted' in request.POST: converted = form.validate(request.POST) form.is_valid = True parent = context.__parent__ creator = authenticated_userid(request) c = create_content( IComment, 'Re: %s' % parent.title, converted['add_comment'], extract_description(converted['add_comment']), creator, ) next_id = parent['comments'].next_id parent['comments'][next_id] = c if workflow is not None: workflow.initialize(c) if 'security_state' in converted: workflow.transition_to_state(c, request, converted['security_state']) if support_attachments(c): store_attachments(c, request.params, creator) relocate_temp_images(c, request) url = model_url(parent, request) msg = 'Comment added' url = url + '?status_message=%s' % urllib.quote(msg) blogentry = find_interface(context, IBlogEntry) if converted['sendalert']: alerts = queryUtility(IAlerts, default=Alerts()) alerts.emit(c, request) return HTTPFound(location=url) # XXX Need different flow of control here, since it isn't # self-posting. else: raise Invalid('This is not a self-posting form. It is submit only.', None, None)
def _parent_title(context, class_or_interface): """helper to find the title of an object in the parent graph""" obj = find_interface(context, class_or_interface) return obj and obj.title
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, )
) fill_values['contact_email'] = u'' tags_field = dict(records=[]) # Render the form and shove some default values in page_title = 'Add Calendar Event' api = TemplateAPI(context, request, page_title) # Get a little policy. Should we suppress alerts? show_sendalert_field = get_show_sendalert(context, request) # Get a layout layout_provider = get_layout_provider(context, request) layout = layout_provider('community') calendar = find_interface(context, ICalendar) if calendar: default_category_name = ICalendarCategory.getTaggedValue('default_name') calendar_categories = [ {'title':x.title, 'path':model_path(x), 'name':x.__name__} for x in _get_calendar_categories(calendar) ] # default name always first calendar_categories.sort( key=lambda x: x['name'] == default_category_name and True or x['title']) else: calendar_categories = [] return render_form_to_response( 'templates/add_calendarevent.pt', form,
def handle_cancel(self): blogentry = find_interface(self.context, IBlogEntry) return HTTPFound(location=resource_url(blogentry, self.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, )
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_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, )