def get_number_to_view_selector(self): """HTML form to choose how many tasks to view.""" options = [5, 25, 50, 100] html = u""" <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 += u""" </select> <input type="submit" value="Submit"> </form> """ return html
def get_current_filter_html(self): """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 = u""" {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, ACTION.CLEAR_FILTER_DEVICE, cc_device.get_device_filter_dropdown(self.filter_device), ACTION.APPLY_FILTER_DEVICE, filters ) or found_one found_one = get_filter_html( "Adding user", self.filter_user, ACTION.CLEAR_FILTER_USER, """<input type="text" name="{}">""".format(PARAM.USER), 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 = u""" <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 = u""" <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