本文整理汇总了Python中corehq.apps.reminders.models.SurveyKeyword.save方法的典型用法代码示例。如果您正苦于以下问题:Python SurveyKeyword.save方法的具体用法?Python SurveyKeyword.save怎么用?Python SurveyKeyword.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.reminders.models.SurveyKeyword
的用法示例。
在下文中一共展示了SurveyKeyword.save方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_keyword
# 需要导入模块: from corehq.apps.reminders.models import SurveyKeyword [as 别名]
# 或者: from corehq.apps.reminders.models.SurveyKeyword import save [as 别名]
def add_keyword(request, domain, keyword_id=None):
sk = None
if keyword_id is not None:
sk = SurveyKeyword.get(keyword_id)
if sk.domain != domain:
raise Http404
if request.method == "POST":
form = KeywordForm(request.POST)
form._cchq_domain = domain
form._sk_id = sk._id if sk is not None else None
if form.is_valid():
if sk is None:
sk = SurveyKeyword(domain=domain)
sk.keyword = form.cleaned_data.get("keyword")
sk.form_type = form.cleaned_data.get("form_type")
sk.form_unique_id = form.cleaned_data.get("form_unique_id")
sk.delimiter = form.cleaned_data.get("delimiter")
sk.use_named_args = form.cleaned_data.get("use_named_args", False)
sk.named_args = form.cleaned_data.get("named_args")
sk.named_args_separator = form.cleaned_data.get("named_args_separator")
sk.save()
return HttpResponseRedirect(reverse("manage_keywords", args=[domain]))
else:
initial = {}
if sk is not None:
initial = {
"keyword" : sk.keyword,
"form_unique_id" : sk.form_unique_id,
"form_type" : sk.form_type,
"use_custom_delimiter" : sk.delimiter is not None,
"delimiter" : sk.delimiter,
"use_named_args" : sk.use_named_args,
"use_named_args_separator" : sk.named_args_separator is not None,
"named_args" : [{"name" : k, "xpath" : v} for k, v in sk.named_args.items()],
"named_args_separator" : sk.named_args_separator,
}
form = KeywordForm(initial=initial)
context = {
"domain" : domain,
"form_list" : get_form_list(domain),
"form" : form,
"keyword" : sk,
}
return render(request, "reminders/partial/add_keyword.html", context)
示例2: add_keyword
# 需要导入模块: from corehq.apps.reminders.models import SurveyKeyword [as 别名]
# 或者: from corehq.apps.reminders.models.SurveyKeyword import save [as 别名]
def add_keyword(request, domain, keyword_id=None):
if keyword_id is None:
s = SurveyKeyword(domain = domain)
else:
s = SurveyKeyword.get(keyword_id)
context = {
"domain" : domain,
"form_list" : get_form_list(domain),
"errors" : [],
"keyword" : s
}
if request.method == "GET":
return render_to_response(request, "reminders/partial/add_keyword.html", context)
else:
keyword = request.POST.get("keyword", None)
form_unique_id = request.POST.get("survey", None)
if keyword is not None:
keyword = keyword.strip()
s.keyword = keyword
s.form_unique_id = form_unique_id
errors = []
if keyword is None or keyword == "":
errors.append("Please enter a keyword.")
if form_unique_id is None:
errors.append("Please create a form first, and then add a keyword for it.")
duplicate_entry = SurveyKeyword.get_keyword(domain, keyword)
if duplicate_entry is not None and keyword_id != duplicate_entry._id:
errors.append("Keyword already exists.")
if len(errors) > 0:
context["errors"] = errors
return render_to_response(request, "reminders/partial/add_keyword.html", context)
else:
s.save()
return HttpResponseRedirect(reverse("manage_surveys", args=[domain]))
示例3: create_survey_keyword
# 需要导入模块: from corehq.apps.reminders.models import SurveyKeyword [as 别名]
# 或者: from corehq.apps.reminders.models.SurveyKeyword import save [as 别名]
def create_survey_keyword(self, keyword, form_unique_id, delimiter=None,
override_open_sessions=True, initiator_filter=None):
sk = SurveyKeyword(
domain=self.domain,
keyword=keyword,
description=keyword,
actions=[SurveyKeywordAction(
recipient=RECIPIENT_SENDER,
recipient_id=None,
action=METHOD_SMS_SURVEY,
message_content=None,
form_unique_id=form_unique_id,
use_named_args=False,
named_args={},
named_args_separator=None,
)],
delimiter=delimiter,
override_open_sessions=override_open_sessions,
initiator_doc_type_filter=initiator_filter or [],
)
sk.save()
self.keywords.append(sk)
return sk