Exemple #1
0
 def get_number_to_view_selector(self) -> str:
     """HTML form to choose how many tasks to view."""
     options = [5, 25, 50, 100]
     html = """
         <form class="filter" method="POST" action="{script}">
             <input type="hidden" name="{PARAM.ACTION}"
                 value="{ACTION.CHANGE_NUMBER_TO_VIEW}">
             <select name="{PARAM.NUMBER_TO_VIEW}">
                 <option value="">all</option>
     """.format(
         script=pls.SCRIPT_NAME,
         ACTION=ACTION,
         PARAM=PARAM,
     )
     for n in options:
         html += """
                 <option{selected} value="{n}">{n}</option>
         """.format(
             selected=ws.option_selected(self.number_to_view, n),
             n=n,
         )
     html += """
             </select>
             <input type="submit" value="Submit">
         </form>
     """
     return html
Exemple #2
0
def get_html_sex_picker(param: str = PARAM.SEX,
                        selected: str = None,
                        offer_all: bool = False) -> str:
    if offer_all:
        option_all = '<option value="">(all)</option>'
    else:
        option_all = ''
    return """
        <select name="{param}">
        {option_all}
        <option value="M"{m}>Male</option>
        <option value="F"{f}>Female</option>
        <option value="X"{x}>
            Indeterminate/unspecified/intersex
        </option>
        </select>
    """.format(param=param,
               option_all=option_all,
               m=ws.option_selected(selected, "M"),
               f=ws.option_selected(selected, "F"),
               x=ws.option_selected(selected, "X"))
Exemple #3
0
def get_device_filter_dropdown(currently_selected_id: int = None) -> str:
    """Get HTML list of all known tablet devices."""
    s = """
        <select name="{}">
            <option value="">(all)</option>
    """.format(PARAM.DEVICE)
    rows = pls.db.fetchall("SELECT id FROM {table}".format(
        table=Device.TABLENAME))
    for pk in [row[0] for row in rows]:
        device = Device(pk)
        s += """<option value="{pk}"{sel}>{name}</option>""".format(
            pk=pk,
            name=ws.webify(device.get_friendly_name_and_id()),
            sel=ws.option_selected(currently_selected_id, pk),
        )
    s += """</select>"""
    return s
Exemple #4
0
def get_html_which_idnum_picker(param: str = PARAM.WHICH_IDNUM,
                                selected: int = None) -> str:
    html = """
        <select name="{param}">
    """.format(
        param=param,
    )
    for n in range(1, NUMBER_OF_IDNUMS + 1):
        html += """
            <option value="{value}"{selected}>{description}</option>
        """.format(
            value=str(n),
            description=cc_pls.pls.get_id_desc(n),
            selected=ws.option_selected(selected, n),
        )
    html += """
        </select>
    """
    return html
Exemple #5
0
    def get_current_filter_html(self) -> str:
        """HTML showing current filters and offering ways to set them."""
        # Consider also multiple buttons in a single form:
        # http://stackoverflow.com/questions/942772
        # ... might allow "apply all things entered here" button
        # ... HOWEVER, I think this would break the ability to press Enter
        # after entering information in any box (which is nice).
        found_one = False
        filters = []
        id_filter_values = []
        id_filter_descs = []
        for n in range(1, NUMBER_OF_IDNUMS + 1):
            nstr = str(n)
            id_filter_values.append(getattr(self, "filter_idnum" + nstr))
            id_filter_descs.append(pls.get_id_desc(n))
        id_filter_value = None
        id_filter_name = "ID number"
        for index, value in enumerate(id_filter_values):
            if value is not None:
                id_filter_value = value
                id_filter_name = id_filter_descs[index]
        which_idnum_temp = """
                {picker}
                <input type="number" name="{PARAM.IDNUM_VALUE}">
        """.format(
            picker=cc_html.get_html_which_idnum_picker(PARAM.WHICH_IDNUM),
            PARAM=PARAM,
        )
        found_one = get_filter_html(
            id_filter_name,
            id_filter_value,
            ACTION.CLEAR_FILTER_IDNUMS,
            which_idnum_temp,
            ACTION.APPLY_FILTER_IDNUMS,
            filters
        ) or found_one
        found_one = get_filter_html(
            "Surname",
            self.filter_surname,
            ACTION.CLEAR_FILTER_SURNAME,
            """<input type="text" name="{}">""".format(PARAM.SURNAME),
            ACTION.APPLY_FILTER_SURNAME,
            filters
        ) or found_one
        found_one = get_filter_html(
            "Forename",
            self.filter_forename,
            ACTION.CLEAR_FILTER_FORENAME,
            """<input type="text" name="{}">""".format(PARAM.FORENAME),
            ACTION.APPLY_FILTER_FORENAME,
            filters
        ) or found_one
        found_one = get_filter_html(
            "Date of birth",
            cc_dt.format_datetime(self.get_filter_dob(), DATEFORMAT.LONG_DATE),
            ACTION.CLEAR_FILTER_DOB,
            """<input type="date" name="{}">""".format(PARAM.DOB),
            ACTION.APPLY_FILTER_DOB,
            filters
        ) or found_one
        found_one = get_filter_html(
            "Sex",
            self.filter_sex,
            ACTION.CLEAR_FILTER_SEX,
            cc_html.get_html_sex_picker(param=PARAM.SEX,
                                        selected=self.filter_sex,
                                        offer_all=True),
            ACTION.APPLY_FILTER_SEX,
            filters
        ) or found_one
        found_one = get_filter_html(
            "Task type",
            self.filter_task,
            ACTION.CLEAR_FILTER_TASK,
            cc_task.get_task_filter_dropdown(self.filter_task),
            ACTION.APPLY_FILTER_TASK,
            filters
        ) or found_one
        found_one = get_filter_html(
            "Task completed",
            cc_html.get_yes_no_none(self.filter_complete),
            ACTION.CLEAR_FILTER_COMPLETE,
            """
                <select name="{PARAM.COMPLETE}">
                    <option value="">(all)</option>
                    <option value="1"{selected_1}>Complete</option>
                    <option value="0"{selected_0}>Incomplete</option>
                </select>
            """.format(PARAM=PARAM,
                       selected_1=ws.option_selected(self.filter_complete, 1),
                       selected_0=ws.option_selected(self.filter_complete, 0)),
            ACTION.APPLY_FILTER_COMPLETE,
            filters
        ) or found_one
        found_one = get_filter_html(
            "Include old (overwritten) versions",
            cc_html.get_yes_no_none(self.filter_include_old_versions),
            ACTION.CLEAR_FILTER_INCLUDE_OLD_VERSIONS,
            """
                <select name="{PARAM.INCLUDE_OLD_VERSIONS}">
                    <option value="">(exclude)</option>
                    <option value="1"{y}>Include</option>
                    <option value="0"{n}>Exclude</option>
                </select>
            """.format(PARAM=PARAM,
                       y=ws.option_selected(self.filter_include_old_versions,
                                            1),
                       n=ws.option_selected(self.filter_include_old_versions,
                                            0)),
            ACTION.APPLY_FILTER_INCLUDE_OLD_VERSIONS,
            filters
        ) or found_one
        # found_one = get_filter_html(
        #     "Tablet device",
        #     self.filter_device_id,
        #     ACTION.CLEAR_FILTER_DEVICE,
        #     cc_device.get_device_filter_dropdown(self.filter_device_id),
        #     ACTION.APPLY_FILTER_DEVICE,
        #     filters
        # ) or found_one
        found_one = get_filter_html(
            "Adding user",
            cc_user.get_username_from_id(self.filter_user_id),
            ACTION.CLEAR_FILTER_USER,
            cc_user.get_user_filter_dropdown(self.filter_user_id),
            ACTION.APPLY_FILTER_USER,
            filters
        ) or found_one
        found_one = get_filter_html(
            "Start date (UTC)",
            cc_dt.format_datetime(self.get_filter_start_datetime(),
                                  DATEFORMAT.LONG_DATE),
            ACTION.CLEAR_FILTER_START_DATETIME,
            """<input type="date" name="{}">""".format(PARAM.START_DATETIME),
            ACTION.APPLY_FILTER_START_DATETIME,
            filters
        ) or found_one
        found_one = get_filter_html(
            "End date (UTC)",
            cc_dt.format_datetime(self.get_filter_end_datetime(),
                                  DATEFORMAT.LONG_DATE),
            ACTION.CLEAR_FILTER_END_DATETIME,
            """<input type="date" name="{}">""".format(PARAM.END_DATETIME),
            ACTION.APPLY_FILTER_END_DATETIME,
            filters
        ) or found_one
        found_one = get_filter_html(
            "Text contents",
            ws.webify(self.filter_text),
            ACTION.CLEAR_FILTER_TEXT,
            """<input type="text" name="{}">""".format(PARAM.TEXT),
            ACTION.APPLY_FILTER_TEXT,
            filters
        ) or found_one

        clear_filter_html = """
                <input type="submit" name="{ACTION.CLEAR_FILTERS}"
                        value="Clear all filters">
                <br>
        """.format(
            ACTION=ACTION,
        )
        no_filters_applied = "<p><b><i>No filters applied</i></b></p>"
        html = """
            <form class="filter" method="POST" action="{script}">

                <input type="hidden" name="{PARAM.ACTION}"
                        value="{ACTION.FILTER}">

                <input type="submit" class="important"
                        name="{ACTION.APPLY_FILTERS}"
                        value="Apply new filters">
                <br>
                <!-- First submit button is default on pressing Enter,
                which is why the Apply button is at the top of the form -->

                {clearbutton}

                {filters}
            </form>
        """.format(
            script=pls.SCRIPT_NAME,
            ACTION=ACTION,
            PARAM=PARAM,
            clearbutton=clear_filter_html if found_one else no_filters_applied,
            filters="".join(filters),
        )
        return html