Example #1
0
    def get(self):
        form_title = cgi.escape(self.request.get("form_title"))
        if YamlValidator().failure(form_title):  # ERROR!!!!
            self.response.out.write(YamlValidator().failure(form_title))
        else:
            yaml_form = yaml.load(get_form_content(form_title))
            form_links = get_form_links(yaml_form)
            yaml_form = form_translator(yaml_form)

            # print yaml_form
            # ['TEST', ['PCR FOR
            # IMMUNOGLOBULIN AND T CELL
            # RECEPTOR GENE REARRANGEMENTS
            # WAS PERFORMED ON', 'PCR FOR
            # IMMUNOGLO

            # [('TEST', ['PCR FOR IMMUNOGLOBULIN\AND T CELL RECEPTOR GENE REARRANGEMENTS WAS PERFORMED ON',
            #'PCR FOR IMMUNOGLOBULIN AND T
            try:
                self.response.out.write(
                    web_publish(
                        self.template.render(
                            yaml_form=yaml_form,
                            form_links=form_links,
                            disable_unicode=True,
                            input_encoding="utf-8",
                            encoding_errors="replace",
                        )
                        % (form_title, form_title)
                    )
                )
            except:
                print get_form_content(form_title)
Example #2
0
    def failure(self, form_title):
        edit_back = (
            """
    <form action="editform" method="get" accept-charset="utf-8">
      <input type="hidden" name="new_form_name" value="%s">

      <p><input type="submit" value="Continue &rarr;"></p>
    </form>"""
            % form_title
        )
        try:
            yaml_form = yaml.load(get_form_content(form_title))
        except:
            return exceptions.html_error_template().render() + edit_back
        try:
            yaml_form = form_translator(yaml_form)
        except:
            return exceptions.html_error_template().render() + edit_back
        # try:
        #     web_publish(self.template.render(yaml_form=yaml_form) %(form_title,form_title))
        # except:
        #   return exceptions.html_error_template().render()+edit_back

        return False
Example #3
0
 def get(self):
     form_title = cgi.escape(self.request.get("new_form_name"))
     # print form_title
     content = get_form_content(form_title)
     form_start = self.form % (content, form_title)
     self.response.out.write(web_publish(form_start))
Example #4
0
    def post(self):
        check_box_lines = make_ints(self.request.get("check_box_line", allow_multiple=True))
        multiple_choices = self.request.get("get_multiple_choices", allow_multiple=True)
        line_choices = make_ints(self.request.get("line_index_selection", allow_multiple=True))
        input_entries = self.request.get("get_input_entry", allow_multiple=True)
        line_index_input = make_ints(self.request.get("line_index_imput", allow_multiple=True))
        form_title = self.request.get("new_form_name")
        # print check_box_lines, "CHECKBOXLINES"
        # print multiple_choices, "MULTIPLE CHOICES"
        # print line_choices, "LINE CHOICES"
        # print input_entries, "INPUT ENTRIES"
        # print line_index_input, "LINE INDEX INPUT"
        # print "CHECKBOXLINES"
        Entry = ValidatedEntry()
        Entry.multiple_choices = zip(line_choices, multiple_choices)
        Entry.input_choices = zip(line_index_input, input_entries)
        Entry.check_box_lines = check_box_lines
        # print Entry.__dict__, "YEAH...."

        # print self.request
        # print self.request.POST.items()
        # print "BEING CALLED"

        """keys contains the chosen lines numbers+ a list with all the selected multiple choises"""
        # for debugging
        # yield strope(keys)

        choices = []
        t = get_form_key(yaml.load(get_form_content(form_title)))
        # t=yaml.load(file(cherrypy.session["fileName"]).read()) #['TEST', ['PCR FOR IMMUNOGLOBULIN AND T CELL RECEPTOR GENE REARRANGEMENTS WAS PERFORMED ON', 'PCR FOR IMMUNOGLO
        [choices.extend(i) for i in (t[i + 1] for i in range(0, len(t), 2))]  # ['HER-2/neu gene', ....
        # yield strope(choices)
        # print choices, "CHOICES"

        user = users.get_current_user()
        q = db.GqlQuery("SELECT * FROM Settings WHERE user = :1", user)
        if q.get():
            user_setting = q.get()
            header = user_setting.header
            line_start = user_setting.line_start
        else:
            header = ""
            line_start = ""

        text = header + "<br>"

        index = 0
        for chosen_check_box_line_index in Entry.check_box_lines:
            line = choices[chosen_check_box_line_index] + " "
            # print "RAW", line

            for multiple_choice in Entry.multiple_choices:  # (14, 'decreased')
                # yield strope(multiple_choice)+strope(chosen_check_box_line_index)
                if multiple_choice[0] == chosen_check_box_line_index and multiple_choice[1] != "default":
                    # continue
                    # yield "CHOICES MATCH"

                    match = self.MultipleSelect.parse(line)
                    if match:
                        match = match[0]
                        # yield strope(match)
                        line = line.replace(match, multiple_choice[1], 1)
                if multiple_choice[0] == chosen_check_box_line_index and multiple_choice[1] == "default":
                    # continue
                    # yield "CHOICES MATCH"
                    # yield strope(line)
                    ##print line
                    match = self.MultipleSelect.parse(line)
                    ##print match
                    # yield strope(match)
                    if match:

                        match = match[0]
                        # yield strope(match)
                        line = line.replace(match, "", 1)
            # print "NOT RAW", line
            for input_choice in Entry.input_choices:
                # print input_choice

                if input_choice[0] == chosen_check_box_line_index:

                    # yield "INPUT MATCH"
                    match = self.Input.parse(line)[0]
                    # print match, "MATCH", type(match)
                    # print line, type(line), match, type(match), input_choice[1], type(input_choice[1])
                    # continue
                    # yield strope(match)
                    line = line_start + line.replace(match, input_choice[1], 1)
                    # continue

            text += line
            text += "<BR>"
            # if index==0 or index==1:
            #     #continue
            #     text+="<BR>"
            index += 1
        # rendering engine
        # print text

        # print text, "HERE I AM"
        self.response.out.write(web_publish(template.render(self.template_path, {"form_results": text})))