本文整理汇总了Python中askbot.views.context.get_extra函数的典型用法代码示例。如果您正苦于以下问题:Python get_extra函数的具体用法?Python get_extra怎么用?Python get_extra使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_extra函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: user_stats
#.........这里部分代码省略.........
# if t['thread__tags'] == 11:
# print t['thread'], t['id']
# import ipdb; ipdb.set_trace()
#
# Badges/Awards (TODO: refactor into Managers/QuerySets when a pattern emerges; Simplify when we get rid of Question&Answer models)
#
post_type = ContentType.objects.get_for_model(models.Post)
user_awards = models.Award.objects.filter(user=user).select_related('badge')
awarded_post_ids = []
for award in user_awards:
if award.content_type_id == post_type.id:
awarded_post_ids.append(award.object_id)
awarded_posts = models.Post.objects.filter(id__in=awarded_post_ids)\
.select_related('thread') # select related to avoid additional queries in Post.get_absolute_url()
awarded_posts_map = {}
for post in awarded_posts:
awarded_posts_map[post.id] = post
badges_dict = collections.defaultdict(list)
for award in user_awards:
if award.badge.is_enabled() == False:
continue
# Fetch content object
if award.content_type_id == post_type.id:
#here we go around a possibility of awards
#losing the content objects when the content
#objects are deleted for some reason
awarded_post = awarded_posts_map.get(award.object_id, None)
if awarded_post is not None:
#protect from awards that are associated with deleted posts
award.content_object = awarded_post
award.content_object_is_post = True
else:
award.content_object_is_post = False
else:
award.content_object_is_post = False
# "Assign" to its Badge
badges_dict[award.badge].append(award)
badges = badges_dict.items()
badges.sort(key=operator.itemgetter(1), reverse=True)
user_groups = models.Group.objects.get_for_user(user = user)
user_groups = user_groups.exclude_personal()
global_group = models.Group.objects.get_global_group()
user_groups = user_groups.exclude(name=global_group.name)
if request.user.pk == user.pk:
groups_membership_info = user.get_groups_membership_info(user_groups)
else:
groups_membership_info = collections.defaultdict()
data = {
'active_tab':'users',
'page_class': 'user-profile-page',
'support_custom_avatars': ('avatar' in django_settings.INSTALLED_APPS),
'tab_name' : 'stats',
'page_title' : _('user profile overview'),
'questions' : questions,
'question_count': question_count,
'q_paginator_context': q_paginator_context,
'top_answers': top_answers,
'top_answer_count': top_answer_count,
'a_paginator_context': a_paginator_context,
'page_size': const.USER_POSTS_PAGE_SIZE,
'up_votes' : up_votes,
'down_votes' : down_votes,
'total_votes': up_votes + down_votes,
'votes_today_left': votes_total - votes_today,
'votes_total_per_day': votes_total,
'user_tags' : user_tags,
'user_groups': user_groups,
'groups_membership_info': groups_membership_info,
'interesting_tag_names': interesting_tag_names,
'ignored_tag_names': ignored_tag_names,
'subscribed_tag_names': subscribed_tag_names,
'badges': badges,
'total_badges' : len(badges),
}
context.update(data)
extra_context = view_context.get_extra(
'ASKBOT_USER_PROFILE_PAGE_EXTRA_CONTEXT',
request,
context
)
context.update(extra_context)
return render(request, 'user_profile/user_stats.html', context)
示例2: tags
def tags(request):#view showing a listing of available tags - plain list
#1) Get parameters. This normally belongs to form cleaning.
post_data = request.GET
sortby = post_data.get('sort', 'used')
try:
page = int(post_data.get('page', '1'))
except ValueError:
page = 1
if sortby == 'name':
order_by = 'name'
else:
order_by = '-used_count'
query = post_data.get('query', '').strip()
tag_list_type = askbot_settings.TAG_LIST_FORMAT
#2) Get query set for the tags.
query_params = {'deleted': False}
if query != '':
query_params['name__icontains'] = query
tags_qs = Tag.objects.filter(**query_params).exclude(used_count=0)
tags_qs = tags_qs.order_by(order_by)
#3) Start populating the template context.
data = {
'active_tab': 'tags',
'page_class': 'tags-page',
'tag_list_type' : tag_list_type,
'stag' : query,
'tab_id' : sortby,
'keywords' : query,
'search_state': SearchState(*[None for x in range(7)])
}
if tag_list_type == 'list':
#plain listing is paginated
objects_list = Paginator(tags_qs, DEFAULT_PAGE_SIZE)
try:
tags = objects_list.page(page)
except (EmptyPage, InvalidPage):
tags = objects_list.page(objects_list.num_pages)
paginator_data = {
'is_paginated' : (objects_list.num_pages > 1),
'pages': objects_list.num_pages,
'page': page,
'has_previous': tags.has_previous(),
'has_next': tags.has_next(),
'previous': tags.previous_page_number(),
'next': tags.next_page_number(),
'base_url' : reverse('tags') + '?sort=%s&' % sortby
}
paginator_context = functions.setup_paginator(paginator_data)
data['paginator_context'] = paginator_context
else:
#tags for the tag cloud are given without pagination
tags = tags_qs
font_size = extra_tags.get_tag_font_size(tags)
data['font_size'] = font_size
data['tags'] = tags
data.update(context.get_extra('ASKBOT_TAGS_PAGE_EXTRA_CONTEXT', request, data))
if request.is_ajax():
template = get_template('tags/content.html')
template_context = RequestContext(request, data)
json_data = {'success': True, 'html': template.render(template_context)}
json_string = simplejson.dumps(json_data)
return HttpResponse(json_string, mimetype='application/json')
else:
return render(request, 'tags.html', data)
示例3: questions
#.........这里部分代码省略.........
reset_method_count = len(filter(None, [search_state.query, search_state.tags, meta_data.get('author_name', None)]))
if request.is_ajax():
q_count = paginator.count
question_counter = ungettext('%(q_num)s question', '%(q_num)s questions', q_count)
question_counter = question_counter % {'q_num': humanize.intcomma(q_count),}
if q_count > page_size:
paginator_tpl = get_template('main_page/paginator.html')
paginator_html = paginator_tpl.render(
RequestContext(
request, {
'context': functions.setup_paginator(paginator_context),
'questions_count': q_count,
'page_size' : page_size,
'search_state': search_state,
}
)
)
else:
paginator_html = ''
questions_tpl = get_template('main_page/questions_loop.html')
questions_html = questions_tpl.render(
RequestContext(
request, {
'threads': page,
'search_state': search_state,
'reset_method_count': reset_method_count,
'request': request
}
)
)
ajax_data = {
'query_data': {
'tags': search_state.tags,
'sort_order': search_state.sort,
'ask_query_string': search_state.ask_query_string(),
},
'paginator': paginator_html,
'question_counter': question_counter,
'faces': [],#[extra_tags.gravatar(contributor, 48) for contributor in contributors],
'feed_url': context_feed_url,
'query_string': search_state.query_string(),
'page_size' : page_size,
'questions': questions_html.replace('\n',''),
'non_existing_tags': meta_data['non_existing_tags']
}
ajax_data['related_tags'] = [{
'name': escape(tag.name),
'used_count': humanize.intcomma(tag.local_used_count)
} for tag in related_tags]
return HttpResponse(simplejson.dumps(ajax_data), mimetype = 'application/json')
else: # non-AJAX branch
template_data = {
'active_tab': 'questions',
'author_name' : meta_data.get('author_name',None),
'contributors' : contributors,
'context' : paginator_context,
'is_unanswered' : False,#remove this from template
'interesting_tag_names': meta_data.get('interesting_tag_names', None),
'ignored_tag_names': meta_data.get('ignored_tag_names', None),
'subscribed_tag_names': meta_data.get('subscribed_tag_names', None),
'language_code': translation.get_language(),
'name_of_anonymous_user' : models.get_name_of_anonymous_user(),
'page_class': 'main-page',
'page_size': page_size,
'query': search_state.query,
'threads' : page,
'questions_count' : paginator.count,
'reset_method_count': reset_method_count,
'scope': search_state.scope,
'show_sort_by_relevance': conf.should_show_sort_by_relevance(),
'search_tags' : search_state.tags,
'sort': search_state.sort,
'tab_id' : search_state.sort,
'tags' : related_tags,
'tag_list_type' : tag_list_type,
'font_size' : extra_tags.get_tag_font_size(related_tags),
'display_tag_filter_strategy_choices': conf.get_tag_display_filter_strategy_choices(),
'email_tag_filter_strategy_choices': conf.get_tag_email_filter_strategy_choices(),
'update_avatar_data': schedules.should_update_avatar_data(request),
'query_string': search_state.query_string(),
'search_state': search_state,
'feed_url': context_feed_url,
}
extra_context = context.get_extra(
'ASKBOT_QUESTIONS_PAGE_EXTRA_CONTEXT',
request,
template_data
)
template_data.update(extra_context)
return render(request, 'main_page.html', template_data)
示例4: edit_answer
def edit_answer(request, id):
answer = get_object_or_404(models.Post, id=id)
if askbot_settings.READ_ONLY_MODE_ENABLED:
return HttpResponseRedirect(answer.get_absolute_url())
revision = answer.get_latest_revision()
class_path = getattr(settings, "ASKBOT_EDIT_ANSWER_FORM", None)
if class_path:
edit_answer_form_class = load_module(class_path)
else:
edit_answer_form_class = forms.EditAnswerForm
try:
request.user.assert_can_edit_answer(answer)
if request.method == "POST":
if request.POST["select_revision"] == "true":
# user has changed revistion number
revision_form = forms.RevisionForm(answer, revision, request.POST)
if revision_form.is_valid():
# Replace with those from the selected revision
rev = revision_form.cleaned_data["revision"]
revision = answer.revisions.get(revision=rev)
form = edit_answer_form_class(answer, revision, user=request.user)
else:
form = edit_answer_form_class(answer, revision, request.POST, user=request.user)
else:
form = edit_answer_form_class(answer, revision, request.POST, user=request.user)
revision_form = forms.RevisionForm(answer, revision)
if form.is_valid():
if form.has_changed():
user = form.get_post_user(request.user)
suppress_email = form.cleaned_data["suppress_email"]
is_private = form.cleaned_data.get("post_privately", False)
user.edit_answer(
answer=answer,
body_text=form.cleaned_data["text"],
revision_comment=form.cleaned_data["summary"],
wiki=form.cleaned_data.get("wiki", answer.wiki),
is_private=is_private,
suppress_email=suppress_email,
ip_addr=request.META.get("REMOTE_ADDR"),
)
signals.answer_edited.send(None, answer=answer, user=user, form_data=form.cleaned_data)
return HttpResponseRedirect(answer.get_absolute_url())
else:
revision_form = forms.RevisionForm(answer, revision)
form = edit_answer_form_class(answer, revision, user=request.user)
if request.user.can_make_group_private_posts():
form.initial["post_privately"] = answer.is_private()
data = {
"page_class": "edit-answer-page",
"active_tab": "questions",
"answer": answer,
"revision": revision,
"revision_form": revision_form,
"form": form,
}
extra_context = context.get_extra("ASKBOT_EDIT_ANSWER_PAGE_EXTRA_CONTEXT", request, data)
data.update(extra_context)
return render(request, "answer_edit.html", data)
except exceptions.PermissionDenied, e:
request.user.message_set.create(message=unicode(e))
return HttpResponseRedirect(answer.get_absolute_url())
示例5: render
'tab_id' : answer_sort_method,
'favorited' : favorited,
'similar_threads' : thread.get_similar_threads(),
'language_code': translation.get_language(),
'paginator_context' : paginator_context,
'show_post': show_post,
'show_comment': show_comment,
'show_comment_position': show_comment_position,
}
#shared with ...
if askbot_settings.GROUPS_ENABLED:
data['sharing_info'] = thread.get_sharing_info()
data.update(context.get_for_tag_editor())
extra = context.get_extra('ASKBOT_QUESTION_PAGE_EXTRA_CONTEXT', request, data)
data.update(extra)
return render(request, 'question.html', data)
def revisions(request, id, post_type = None):
assert post_type in ('question', 'answer')
post = get_object_or_404(models.Post, post_type=post_type, id=id)
revisions = list(models.PostRevision.objects.filter(post=post))
revisions.reverse()
for i, revision in enumerate(revisions):
if i == 0:
revision.diff = sanitize_html(revisions[i].html)
revision.summary = _('initial version')
else:
revision.diff = htmldiff(
示例6: questions
#.........这里部分代码省略.........
'sort_order': search_state.sort,
'ask_query_string': search_state.ask_query_string(),
},
'paginator': paginator_html,
'question_counter': question_counter,
'faces': [],#[extra_tags.gravatar(contributor, 48) for contributor in contributors],
'feed_url': context_feed_url,
'query_string': search_state.query_string(),
'page_size' : search_state.page_size,
'questions': questions_html.replace('\n',''),
'non_existing_tags': meta_data['non_existing_tags'],
}
related_tags_tpl = get_template('widgets/related_tags.html')
related_tags_data = {
'tags': related_tags,
'tag_list_type': tag_list_type,
'query_string': search_state.query_string(),
'search_state': search_state,
'language_code': translation.get_language(),
}
if tag_list_type == 'cloud':
related_tags_data['font_size'] = extra_tags.get_tag_font_size(related_tags)
ajax_data['related_tags_html'] = related_tags_tpl.render(
RequestContext(request, related_tags_data)
)
#here we add and then delete some items
#to allow extra context processor to work
ajax_data['tags'] = related_tags
ajax_data['interesting_tag_names'] = None
ajax_data['threads'] = page
extra_context = context.get_extra(
'ASKBOT_QUESTIONS_PAGE_EXTRA_CONTEXT',
request,
ajax_data
)
del ajax_data['tags']
del ajax_data['interesting_tag_names']
del ajax_data['threads']
ajax_data.update(extra_context)
return HttpResponse(simplejson.dumps(ajax_data), mimetype = 'application/json')
else: # non-AJAX branch
template_data = {
'active_tab': 'questions',
'author_name' : meta_data.get('author_name',None),
'contributors' : contributors,
'context' : paginator_context,
'is_unanswered' : False,#remove this from template
'interesting_tag_names': meta_data.get('interesting_tag_names', None),
'ignored_tag_names': meta_data.get('ignored_tag_names', None),
'subscribed_tag_names': meta_data.get('subscribed_tag_names', None),
'language_code': translation.get_language(),
'name_of_anonymous_user' : models.get_name_of_anonymous_user(),
'page_class': 'main-page',
'page_size': search_state.page_size,
'query': search_state.query,
'threads' : page,
'questions_count' : paginator.count,
'reset_method_count': reset_method_count,
'scope': search_state.scope,
示例7: tags
def tags(request):#view showing a listing of available tags - plain list
form = ShowTagsForm(request.REQUEST)
form.full_clean() #always valid
page = form.cleaned_data['page']
sort_method = form.cleaned_data['sort']
query = form.cleaned_data['query']
tag_list_type = askbot_settings.TAG_LIST_FORMAT
#2) Get query set for the tags.
query_params = {
'deleted': False,
'language_code': translation.get_language()
}
if query != '':
query_params['name__icontains'] = query
tags_qs = Tag.objects.filter(**query_params).exclude(used_count=0)
if sort_method == 'name':
order_by = 'name'
else:
order_by = '-used_count'
tags_qs = tags_qs.order_by(order_by)
#3) Start populating the template context.
data = {
'active_tab': 'tags',
'page_class': 'tags-page',
'tag_list_type' : tag_list_type,
'query' : query,
'tab_id' : sort_method,
'keywords' : query,
'search_state': SearchState(*[None for x in range(8)])
}
if tag_list_type == 'list':
#plain listing is paginated
objects_list = Paginator(tags_qs, DEFAULT_PAGE_SIZE)
try:
tags = objects_list.page(page)
except (EmptyPage, InvalidPage):
tags = objects_list.page(objects_list.num_pages)
paginator_data = {
'is_paginated' : (objects_list.num_pages > 1),
'pages': objects_list.num_pages,
'current_page_number': page,
'page_object': tags,
'base_url' : reverse('tags') + '?sort=%s&' % sort_method
}
paginator_context = functions.setup_paginator(paginator_data)
data['paginator_context'] = paginator_context
else:
#tags for the tag cloud are given without pagination
tags = tags_qs
font_size = extra_tags.get_tag_font_size(tags)
data['font_size'] = font_size
data['tags'] = tags
data.update(context.get_extra('ASKBOT_TAGS_PAGE_EXTRA_CONTEXT', request, data))
if request.is_ajax():
template = get_template('tags/content.html')
template_context = RequestContext(request, data)
json_data = {'success': True, 'html': template.render(template_context)}
json_string = simplejson.dumps(json_data)
return HttpResponse(json_string, content_type='application/json')
else:
return render(request, 'tags.html', data)
示例8: question
#.........这里部分代码省略.........
page_objects = objects_list.page(show_page)
# count visits
signals.question_visited.send(None, request=request, question=question_post)
paginator_data = {
'is_paginated': (objects_list.count > const.ANSWERS_PAGE_SIZE),
'pages': objects_list.num_pages,
'current_page_number': show_page,
'page_object': page_objects,
'base_url': request.path + '?sort=%s&' % answer_sort_method,
}
paginator_context = functions.setup_paginator(paginator_data)
# TODO: maybe consolidate all activity in the thread
# for the user into just one query?
favorited = thread.has_favorite_by_user(request.user)
is_cacheable = True
if show_page != 1:
is_cacheable = False
elif (show_comment_position or 0) > askbot_settings.MAX_COMMENTS_TO_SHOW:
is_cacheable = False
# maybe load draft
initial = {}
if request.user.is_authenticated():
# TODO: refactor into methor on thread
drafts = DraftAnswer.objects.filter(author=request.user, thread=thread)
if drafts.count() > 0:
initial['text'] = drafts[0].text
custom_answer_form_path = getattr(django_settings, 'ASKBOT_NEW_ANSWER_FORM', None)
if custom_answer_form_path:
answer_form_class = load_module(custom_answer_form_path)
else:
answer_form_class = AnswerForm
answer_form = answer_form_class(initial=initial, user=request.user)
user_can_post_comment = (request.user.is_authenticated() and request.user.can_post_comment(question_post))
new_answer_allowed = True
previous_answer = None
if request.user.is_authenticated():
if askbot_settings.LIMIT_ONE_ANSWER_PER_USER:
for answer in answers:
if answer.author_id == request.user.pk:
new_answer_allowed = False
previous_answer = answer
break
if request.user.is_authenticated() and askbot_settings.GROUPS_ENABLED:
group_read_only = request.user.is_read_only()
else:
group_read_only = False
data = {
'active_tab': 'questions',
'answer': answer_form,
'answers': page_objects.object_list,
'answer_count': thread.get_answer_count(request.user),
'blank_comment': MockPost(post_type='comment', author=request.user), # data for the js comment template
'category_tree_data': askbot_settings.CATEGORY_TREE,
'editor_is_unfolded': answer_form.has_data(),
'favorited': favorited,
'group_read_only': group_read_only,
'is_cacheable': False, # is_cacheable, # temporary, until invalidation fix
'language_code': translation.get_language(),
'long_time': const.LONG_TIME, # "forever" caching
'new_answer_allowed': new_answer_allowed,
'oldest_answer_id': thread.get_oldest_answer_id(request.user),
'page_class': 'question-page',
'paginator_context': paginator_context,
'previous_answer': previous_answer,
'published_answer_ids': published_answer_ids,
'question': question_post,
'show_comment': show_comment,
'show_comment_position': show_comment_position,
'show_post': show_post,
'similar_threads': thread.get_similar_threads(),
'tab_id': answer_sort_method,
'thread': thread,
'thread_is_moderated': thread.is_moderated(),
'user_is_thread_moderator': thread.has_moderator(request.user),
'user_votes': user_votes,
'user_post_id_list': user_post_id_list,
'user_can_post_comment': user_can_post_comment, # in general
}
# shared with ...
if askbot_settings.GROUPS_ENABLED:
data['sharing_info'] = thread.get_sharing_info()
data.update(context.get_for_tag_editor())
extra = context.get_extra('ASKBOT_QUESTION_PAGE_EXTRA_CONTEXT', request, data)
data.update(extra)
return render(request, 'question.jinja', data)
示例9: user_stats
#.........这里部分代码省略.........
subscribed_tag_names = None
# tags = models.Post.objects.filter(author=user).values('id', 'thread', 'thread__tags')
# post_ids = set()
# thread_ids = set()
# tag_ids = set()
# for t in tags:
# post_ids.add(t['id'])
# thread_ids.add(t['thread'])
# tag_ids.add(t['thread__tags'])
# if t['thread__tags'] == 11:
# print t['thread'], t['id']
# import ipdb; ipdb.set_trace()
#
# Badges/Awards (TODO: refactor into Managers/QuerySets when a pattern emerges; Simplify when we get rid of Question&Answer models)
#
post_type = ContentType.objects.get_for_model(models.Post)
user_awards = models.Award.objects.filter(user=user).select_related("badge")
awarded_post_ids = []
for award in user_awards:
if award.content_type_id == post_type.id:
awarded_post_ids.append(award.object_id)
awarded_posts = models.Post.objects.filter(id__in=awarded_post_ids).select_related(
"thread"
) # select related to avoid additional queries in Post.get_absolute_url()
awarded_posts_map = {}
for post in awarded_posts:
awarded_posts_map[post.id] = post
badges_dict = collections.defaultdict(list)
for award in user_awards:
# Fetch content object
if award.content_type_id == post_type.id:
# here we go around a possibility of awards
# losing the content objects when the content
# objects are deleted for some reason
awarded_post = awarded_posts_map.get(award.object_id, None)
if awarded_post is not None:
# protect from awards that are associated with deleted posts
award.content_object = awarded_post
award.content_object_is_post = True
else:
award.content_object_is_post = False
else:
award.content_object_is_post = False
# "Assign" to its Badge
badges_dict[award.badge].append(award)
badges = badges_dict.items()
badges.sort(key=operator.itemgetter(1), reverse=True)
user_groups = models.Group.objects.get_for_user(user=user)
user_groups = user_groups.exclude_personal()
global_group = models.Group.objects.get_global_group()
user_groups = user_groups.exclude(name=global_group.name)
if request.user == user:
groups_membership_info = user.get_groups_membership_info(user_groups)
else:
groups_membership_info = collections.defaultdict()
data = {
"active_tab": "users",
"page_class": "user-profile-page",
"support_custom_avatars": ("avatar" in django_settings.INSTALLED_APPS),
"tab_name": "stats",
"tab_description": _("user profile"),
"page_title": _("user profile overview"),
"user_status_for_display": user.get_status_display(soft=True),
"questions": questions,
"question_count": question_count,
"top_answers": top_answers,
"top_answer_count": top_answer_count,
"up_votes": up_votes,
"down_votes": down_votes,
"total_votes": up_votes + down_votes,
"votes_today_left": votes_total - votes_today,
"votes_total_per_day": votes_total,
"user_tags": user_tags,
"user_groups": user_groups,
"groups_membership_info": groups_membership_info,
"interesting_tag_names": interesting_tag_names,
"ignored_tag_names": ignored_tag_names,
"subscribed_tag_names": subscribed_tag_names,
"badges": badges,
"total_badges": len(badges),
}
context.update(data)
extra_context = view_context.get_extra("ASKBOT_USER_PROFILE_PAGE_EXTRA_CONTEXT", request, context)
context.update(extra_context)
return render(request, "user_profile/user_stats.html", context)