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_community_view(context, request): assert ICommunity.providedBy(context), str(type(context)) user = authenticated_userid(request) page_title = 'View Community ' + context.title api = request.api api.page_title = page_title # provide client data for rendering current tags in the tagbox tagquery = getMultiAdapter((context, request), ITagQuery) client_json_data = {'tagbox': {'docid': tagquery.docid, 'records': tagquery.tagswithcounts, }, } # Filter the actions based on permission actions = [] if has_permission(MODERATE, context, request): actions.append(('Edit', 'edit.html')) # If user has permission to see this view then has permission to join. if not(user in context.member_names or user in context.moderator_names): actions.append(('Join', 'join.html')) if has_permission(DELETE_COMMUNITY, context, request): actions.append(('Delete', 'delete.html')) recent_items = [] recent_items_batch = get_recent_items_batch(context, request) for item in recent_items_batch["entries"]: adapted = getMultiAdapter((item, request), IGridEntryInfo) recent_items.append(adapted) feed_url = model_url(context, request, "atom.xml") return {'api': api, 'actions': actions, 'recent_items': recent_items, 'batch_info': recent_items_batch, 'head_data': convert_to_script(client_json_data), 'feed_url': feed_url, }
def render_karl_client_data(self, update_dict=None): """ How to provide data to the client? There are 3 ways: 1. specify the data via the template api api.karl_client_data['my_widget'] = {...my_data...} The code will be injected to all pages automatically. Be careful not to overwrite api.karl_client_data, only update one or more fields of the dictionary. 2. Pass the data directly to the template render_template_to_response(... ... karl_client_data = {'my_widget': {...my_data...}}, ...) The passed dictionary will update the one specified via the template api. 3. Legacy way: head_data from karl.views.utils import convert_to_script render_template_to_response(... ... head_data = convert_to_script({'my_widget': {...my_data...}), ...) Data inserted this way is supported in order to not break old code, but for new code please prefer to use the methods described in point 1. or 2. """ d = dict(self.karl_client_data) if update_dict: d.update(update_dict) return convert_to_script(d, var_name='karl_client_data')
def __call__(self): profile_details = getUtility(IProfileDict, name='profile-details') profile_details.update_details(self.context, self.request, self.api, self.photo_thumb_size) context = self.context request = self.request api = self.api # provide client data for rendering current tags in the tagbox client_json_data = dict( tagbox = get_tags_client_data(context, request), ) # Get communities this user is a member of, along with moderator info # communities = {} communities_folder = find_communities(context) user_info = find_users(context).get_by_id(context.__name__) if user_info is not None: for group in user_info["groups"]: if group.startswith("group.community:"): unused, community_name, role = group.split(":") if (communities.has_key(community_name) and role != "moderators"): continue community = communities_folder.get(community_name, None) if community is None: continue if has_permission('view', community, request): communities[community_name] = { "title": community.title, "moderator": role == "moderators", "url": model_url(community, request), } communities = communities.values() communities.sort(key=lambda x:x["title"]) preferred_communities = [] my_communities = None name = context.__name__ # is this the current user's profile? if authenticated_userid(request) == name: preferred_communities = get_preferred_communities(communities_folder, request) my_communities = get_my_communities(communities_folder, request) tagger = find_tags(context) if tagger is None: tags = () else: tags = [] names = tagger.getTags(users=[context.__name__]) for name, count in sorted(tagger.getFrequency(names, user=context.__name__), key=lambda x: x[1], reverse=True, )[:10]: tags.append({'name': name, 'count': count}) self.profile = profile_details self.communities = communities self.my_communities = my_communities or [] self.preferred_communities = preferred_communities self.tags = tags self.actions = get_profile_actions(context,request) self.head_data = convert_to_script(client_json_data) return self.make_response()