本文整理汇总了Python中questions.models.Question.add_metadata方法的典型用法代码示例。如果您正苦于以下问题:Python Question.add_metadata方法的具体用法?Python Question.add_metadata怎么用?Python Question.add_metadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类questions.models.Question
的用法示例。
在下文中一共展示了Question.add_metadata方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: aaq
# 需要导入模块: from questions.models import Question [as 别名]
# 或者: from questions.models.Question import add_metadata [as 别名]
#.........这里部分代码省略.........
return jingo.render(request, template,
{'form': form,
'results': results,
'tried_search': tried_search,
'products': products,
'current_product': product,
'current_category': category,
'current_html': html,
'current_articles': articles,
'current_step': step,
'deadend': deadend,
'host': Site.objects.get_current().domain})
# Handle the form post.
if not request.user.is_authenticated():
if request.POST.get('login'):
login_form = handle_login(request, only_active=False)
statsd.incr('questions.user.login')
register_form = RegisterForm()
elif request.POST.get('register'):
login_form = AuthenticationForm()
email_template = 'questions/email/confirm_question.ltxt'
email_subject = _('Please confirm your Firefox Help question')
email_data = request.GET.get('search')
register_form = handle_register(request, email_template,
email_subject, email_data)
if register_form.is_valid(): # Now try to log in.
user = auth.authenticate(username=request.POST.get('username'),
password=request.POST.get('password'))
auth.login(request, user)
statsd.incr('questions.user.register')
else:
# L10n: This shouldn't happen unless people tamper with POST data.
message = _lazy('Request type not recognized.')
return jingo.render(request, 'handlers/400.html',
{'message': message}, status=400)
if request.user.is_authenticated():
# Redirect to GET the current URL replacing the step parameter.
# This is also required for the csrf middleware to set the auth'd
# tokens appropriately.
url = urlparams(request.get_full_path(), step='aaq-question')
return HttpResponseRedirect(url)
else:
return jingo.render(request, login_t,
{'product': product, 'category': category,
'title': request.POST.get('title'),
'register_form': register_form,
'login_form': login_form})
form = NewQuestionForm(product=product, category=category,
data=request.POST)
if form.is_valid():
question = Question(creator=request.user,
title=form.cleaned_data['title'],
content=form.cleaned_data['content'])
question.save()
# User successfully submitted a new question
statsd.incr('questions.new')
question.add_metadata(**form.cleaned_metadata)
if product:
# TODO: This add_metadata call should be removed once we are
# fully IA-driven (sync isn't special case anymore).
question.add_metadata(product=product['key'])
for p in Product.objects.filter(slug__in=product.get('products')):
question.products.add(p)
if category:
# TODO: This add_metadata call should be removed once we are
# fully IA-driven (sync isn't special case anymore).
question.add_metadata(category=category['key'])
t = category.get('topic')
if t:
question.topics.add(Topic.objects.get(slug=t))
# The first time a question is saved, automatically apply some tags:
question.auto_tag()
# Submitting the question counts as a vote
question_vote(request, question.id)
if request.user.is_active:
messages.add_message(request, messages.SUCCESS,
_('Done! Your question is now posted on the Mozilla community '
'support forum.'))
url = reverse('questions.answers',
kwargs={'question_id': question.id})
return HttpResponseRedirect(url)
return HttpResponseRedirect(reverse('questions.aaq_confirm'))
statsd.incr('questions.aaq.details-form-error')
return jingo.render(request, template,
{'form': form, 'products': products,
'current_product': product,
'current_category': category,
'current_articles': articles})
示例2: new_question
# 需要导入模块: from questions.models import Question [as 别名]
# 或者: from questions.models.Question import add_metadata [as 别名]
#.........这里部分代码省略.........
login_form = AuthenticationForm()
register_form = RegisterForm()
return jingo.render(request, login_t,
{'product': product, 'category': category,
'title': search,
'register_form': register_form,
'login_form': login_form})
form = NewQuestionForm(product=product,
category=category,
initial={'title': search})
else:
form = None
return jingo.render(request, template,
{'form': form,
'results': results,
'tried_search': tried_search,
'products': products,
'current_product': product,
'current_category': category,
'current_html': html,
'current_articles': articles,
'deadend': deadend,
'host': Site.objects.get_current().domain})
# Handle the form post.
if not request.user.is_authenticated():
if request.POST.get('login'):
login_form = handle_login(request, only_active=False)
statsd.incr('questions.user.login')
register_form = RegisterForm()
elif request.POST.get('register'):
login_form = AuthenticationForm()
email_template = 'questions/email/confirm_question.ltxt'
email_subject = _('Please confirm your Firefox Help question')
email_data = request.GET.get('search')
register_form = handle_register(request, email_template,
email_subject, email_data)
if register_form.is_valid(): # Now try to log in.
user = auth.authenticate(username=request.POST.get('username'),
password=request.POST.get('password'))
auth.login(request, user)
statsd.incr('questions.user.register')
else:
# L10n: This shouldn't happen unless people tamper with POST data.
message = _lazy('Request type not recognized.')
return jingo.render(request, 'handlers/400.html',
{'message': message}, status=400)
if request.user.is_authenticated():
# Redirect to GET the current URL.
# This is required for the csrf middleware to set the auth'd tokens
# appropriately.
return HttpResponseRedirect(request.get_full_path())
else:
return jingo.render(request, login_t,
{'product': product, 'category': category,
'title': request.POST.get('title'),
'register_form': register_form,
'login_form': login_form})
form = NewQuestionForm(product=product, category=category,
data=request.POST)
if form.is_valid():
question = Question(creator=request.user,
title=form.cleaned_data['title'],
content=form.cleaned_data['content'])
question.save()
statsd.incr('questions.new')
question.add_metadata(**form.cleaned_metadata)
if product:
question.add_metadata(product=product['key'])
if category:
question.add_metadata(category=category['key'])
# The first time a question is saved, automatically apply some tags:
question.auto_tag()
# Submitting the question counts as a vote
question_vote(request, question.id)
if request.user.is_active:
messages.add_message(request, messages.SUCCESS,
_('Thanks! Your question has been posted. See it below.'))
url = reverse('questions.answers',
kwargs={'question_id': question.id})
return HttpResponseRedirect(url)
auth.logout(request)
statsd.incr('questions.user.logout')
confirm_t = ('questions/mobile/confirm_email.html' if request.MOBILE
else 'questions/confirm_email.html')
return jingo.render(request, confirm_t,
{'question': question})
return jingo.render(request, template,
{'form': form, 'products': products,
'current_product': product,
'current_category': category,
'current_articles': articles})
示例3: new_question
# 需要导入模块: from questions.models import Question [as 别名]
# 或者: from questions.models.Question import add_metadata [as 别名]
#.........这里部分代码省略.........
statsd.incr("questions.aaq.suggestions")
return jingo.render(
request,
template,
{
"form": form,
"results": results,
"tried_search": tried_search,
"products": products,
"current_product": product,
"current_category": category,
"current_html": html,
"current_articles": articles,
"deadend": deadend,
"host": Site.objects.get_current().domain,
},
)
# Handle the form post.
if not request.user.is_authenticated():
if request.POST.get("login"):
login_form = handle_login(request, only_active=False)
statsd.incr("questions.user.login")
register_form = RegisterForm()
elif request.POST.get("register"):
login_form = AuthenticationForm()
email_template = "questions/email/confirm_question.ltxt"
email_subject = _("Please confirm your Firefox Help question")
email_data = request.GET.get("search")
register_form = handle_register(request, email_template, email_subject, email_data)
if register_form.is_valid(): # Now try to log in.
user = auth.authenticate(username=request.POST.get("username"), password=request.POST.get("password"))
auth.login(request, user)
statsd.incr("questions.user.register")
else:
# L10n: This shouldn't happen unless people tamper with POST data.
message = _lazy("Request type not recognized.")
return jingo.render(request, "handlers/400.html", {"message": message}, status=400)
if request.user.is_authenticated():
# Redirect to GET the current URL.
# This is required for the csrf middleware to set the auth'd tokens
# appropriately.
return HttpResponseRedirect(request.get_full_path())
else:
return jingo.render(
request,
login_t,
{
"product": product,
"category": category,
"title": request.POST.get("title"),
"register_form": register_form,
"login_form": login_form,
},
)
form = NewQuestionForm(product=product, category=category, data=request.POST)
if form.is_valid():
question = Question(
creator=request.user, title=form.cleaned_data["title"], content=form.cleaned_data["content"]
)
question.save()
# User successfully submitted a new question
statsd.incr("questions.new")
question.add_metadata(**form.cleaned_metadata)
if product:
question.add_metadata(product=product["key"])
if category:
question.add_metadata(category=category["key"])
# The first time a question is saved, automatically apply some tags:
question.auto_tag()
# Submitting the question counts as a vote
question_vote(request, question.id)
if request.user.is_active:
messages.add_message(request, messages.SUCCESS, _("Thanks! Your question has been posted. See it below."))
url = reverse("questions.answers", kwargs={"question_id": question.id})
return HttpResponseRedirect(url)
auth.logout(request)
statsd.incr("questions.user.logout")
confirm_t = "questions/mobile/confirm_email.html" if request.MOBILE else "questions/confirm_email.html"
return jingo.render(request, confirm_t, {"question": question})
statsd.incr("questions.aaq.details-form-error")
return jingo.render(
request,
template,
{
"form": form,
"products": products,
"current_product": product,
"current_category": category,
"current_articles": articles,
},
)
示例4: new_question
# 需要导入模块: from questions.models import Question [as 别名]
# 或者: from questions.models.Question import add_metadata [as 别名]
#.........这里部分代码省略.........
else:
search_results = []
tried_search = False
if request.GET.get('showform'):
# Before we show the form, make sure the user is auth'd:
if not request.user.is_authenticated():
login_form = AuthenticationForm()
register_form = RegisterForm()
return jingo.render(request,
'questions/new_question_login.html',
{'product': product, 'category': category,
'title': search,
'register_form': register_form,
'login_form': login_form})
form = NewQuestionForm(product=product,
category=category,
initial={'title': search})
else:
form = None
return jingo.render(request, 'questions/new_question.html',
{'form': form, 'search_results': search_results,
'tried_search': tried_search,
'products': products,
'current_product': product,
'current_category': category,
'current_html': html,
'current_articles': articles,
'deadend': deadend,
'host': Site.objects.get_current().domain})
# Handle the form post.
just_logged_in = False # Used below for whether to pre-load Question form.
if not request.user.is_authenticated():
type = request.POST.get('type')
if type not in ('login', 'register'):
# L10n: This shouldn't happen unless people tamper with POST data
message = _lazy('Request type not recognized.')
return jingo.render(request, 'handlers/400.html',
{'message': message}, status=400)
if type == 'login':
login_form = handle_login(request, only_active=False)
register_form = RegisterForm()
else: # must be 'register'
login_form = AuthenticationForm()
register_form = handle_register(request)
if register_form.is_valid(): # now try to log in
user = auth.authenticate(username=request.POST.get('username'),
password=request.POST.get('password'))
auth.login(request, user)
if not request.user.is_authenticated():
return jingo.render(request,
'questions/new_question_login.html',
{'product': product, 'category': category,
'title': request.POST.get('title'),
'register_form': register_form,
'login_form': login_form})
else:
just_logged_in = True
if just_logged_in:
form = NewQuestionForm(product=product,
category=category,
initial={'title': request.GET.get('search')})
else:
form = NewQuestionForm(product=product, category=category,
data=request.POST)
if form.is_valid():
question = Question(creator=request.user,
title=form.cleaned_data['title'],
content=form.cleaned_data['content'])
question.save()
question.add_metadata(**form.cleaned_metadata)
if product:
question.add_metadata(product=product['key'])
if category:
question.add_metadata(category=category['key'])
# The first time a question is saved, automatically apply some tags:
question.auto_tag()
# Submitting the question counts as a vote
question_vote(request, question.id)
if request.user.is_active:
url = reverse('questions.answers',
kwargs={'question_id': question.id})
return HttpResponseRedirect(urlparams(url, new=1))
auth.logout(request)
return jingo.render(request, 'questions/confirm_email.html',
{'question': question})
return jingo.render(request, 'questions/new_question.html',
{'form': form, 'products': products,
'current_product': product,
'current_category': category,
'current_articles': articles})
示例5: aaq
# 需要导入模块: from questions.models import Question [as 别名]
# 或者: from questions.models.Question import add_metadata [as 别名]
#.........这里部分代码省略.........
# Handle the form post.
if not request.user.is_authenticated():
if request.POST.get("login"):
login_form = handle_login(request, only_active=False)
statsd.incr("questions.user.login")
register_form = RegisterForm()
elif request.POST.get("register"):
login_form = AuthenticationForm()
email_template = "questions/email/confirm_question.ltxt"
email_subject = _("Please confirm your Firefox Help question")
email_data = request.GET.get("search")
register_form = handle_register(request, email_template, email_subject, email_data)
if register_form.is_valid(): # Now try to log in.
user = auth.authenticate(username=request.POST.get("username"), password=request.POST.get("password"))
auth.login(request, user)
statsd.incr("questions.user.register")
else:
# L10n: This shouldn't happen unless people tamper with POST data.
message = _lazy("Request type not recognized.")
return jingo.render(request, "handlers/400.html", {"message": message}, status=400)
if request.user.is_authenticated():
# Redirect to GET the current URL replacing the step parameter.
# This is also required for the csrf middleware to set the auth'd
# tokens appropriately.
url = urlparams(request.get_full_path(), step="aaq-question")
return HttpResponseRedirect(url)
else:
return jingo.render(
request,
login_t,
{
"product": product,
"category": category,
"title": request.POST.get("title"),
"register_form": register_form,
"login_form": login_form,
},
)
form = NewQuestionForm(product=product, category=category, data=request.POST)
if form.is_valid():
question = Question(
creator=request.user,
title=form.cleaned_data["title"],
content=form.cleaned_data["content"],
locale=request.LANGUAGE_CODE,
)
question.save()
# User successfully submitted a new question
statsd.incr("questions.new")
question.add_metadata(**form.cleaned_metadata)
if product:
# TODO: This add_metadata call should be removed once we are
# fully IA-driven (sync isn't special case anymore).
question.add_metadata(product=product["key"])
if product.get("products"):
for p in Product.objects.filter(slug__in=product["products"]):
question.products.add(p)
if category:
# TODO: This add_metadata call should be removed once we are
# fully IA-driven (sync isn't special case anymore).
question.add_metadata(category=category["key"])
t = category.get("topic")
if t:
question.topics.add(Topic.objects.get(slug=t))
# The first time a question is saved, automatically apply some tags:
question.auto_tag()
# Submitting the question counts as a vote
question_vote(request, question.id)
if request.user.is_active:
messages.add_message(
request,
messages.SUCCESS,
_("Done! Your question is now posted on the Mozilla community " "support forum."),
)
url = reverse("questions.answers", kwargs={"question_id": question.id})
return HttpResponseRedirect(url)
return HttpResponseRedirect(reverse("questions.aaq_confirm"))
statsd.incr("questions.aaq.details-form-error")
return jingo.render(
request,
template,
{
"form": form,
"products": products,
"current_product": product,
"current_category": category,
"current_articles": articles,
},
)