Beispiel #1
0
 def keyword_form(self):
     if self.request.method == 'POST':
         return KeywordForm(
             self.request.POST, domain=self.domain,
             process_structured=self.process_structured_message,
         )
     return KeywordForm(
         domain=self.domain,
         process_structured=self.process_structured_message,
     )
Beispiel #2
0
 def keyword_form(self):
     initial = self.get_initial_values()
     if self.request.method == "POST":
         form = KeywordForm(
             self.request.POST,
             domain=self.domain,
             initial=initial,
             process_structured=self.process_structured_message,
         )
         form._sk_id = self.keyword_id
         return form
     return KeywordForm(domain=self.domain, initial=initial, process_structured=self.process_structured_message)
Beispiel #3
0
 def keyword_form(self):
     initial = self.get_initial_values()
     if self.request.method == 'POST':
         form = KeywordForm(
             self.request.POST, domain=self.domain, initial=initial,
             process_structured=self.process_structured_message,
         )
         form._sk_id = self.keyword_id
         return form
     return KeywordForm(
         domain=self.domain, initial=initial,
         process_structured=self.process_structured_message,
     )
Beispiel #4
0
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)
Beispiel #5
0
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)