def apply_filter_idnums(self, form): """Apply the ID number filter. Only one ID number filter at a time.""" self.clear_filter_idnums() # Only filter on one ID at a time. which_idnum = ws.get_cgi_parameter_int(form, PARAM.WHICH_IDNUM) idnum_value = ws.get_cgi_parameter_int(form, PARAM.IDNUM_VALUE) if which_idnum >= 1 and which_idnum <= NUMBER_OF_IDNUMS: setattr(self, "filter_idnum" + str(which_idnum), idnum_value) self.reset_pagination()
def apply_filters(self, form): """Apply filters from details in the CGI form.""" filter_surname = ws.get_cgi_parameter_str_or_none(form, PARAM.SURNAME) if filter_surname: self.filter_surname = filter_surname.upper() filter_forename = ws.get_cgi_parameter_str_or_none(form, PARAM.FORENAME) if filter_forename: self.filter_forename = filter_forename.upper() dt = ws.get_cgi_parameter_datetime(form, PARAM.DOB) if dt: self.filter_dob_iso8601 = cc_dt.format_datetime( dt, DATEFORMAT.ISO8601_DATE_ONLY) # NB date only filter_sex = ws.get_cgi_parameter_str_or_none(form, PARAM.SEX) if filter_sex: self.filter_sex = filter_sex.upper() which_idnum = ws.get_cgi_parameter_int(form, PARAM.WHICH_IDNUM) idnum_value = ws.get_cgi_parameter_int(form, PARAM.IDNUM_VALUE) if (which_idnum and idnum_value is not None and which_idnum >= 1 and which_idnum <= NUMBER_OF_IDNUMS): self.clear_filter_idnums() # Only filter on one ID at a time. setattr(self, "filter_idnum" + str(which_idnum), idnum_value) filter_task = ws.get_cgi_parameter_str_or_none(form, PARAM.TASK) if filter_task: self.filter_task = filter_task filter_complete = ws.get_cgi_parameter_bool_or_none(form, PARAM.COMPLETE) if filter_complete is not None: self.filter_complete = filter_complete filter_include_old_versions = ws.get_cgi_parameter_bool_or_none( form, PARAM.INCLUDE_OLD_VERSIONS) if filter_include_old_versions is not None: self.filter_include_old_versions = filter_include_old_versions filter_device = ws.get_cgi_parameter_str_or_none(form, PARAM.DEVICE) if filter_device: self.filter_device = filter_device filter_user = ws.get_cgi_parameter_str_or_none(form, PARAM.USER) if filter_user: self.filter_user = filter_user dt = ws.get_cgi_parameter_datetime(form, PARAM.START_DATETIME) if dt: self.filter_start_datetime_iso8601 = cc_dt.format_datetime( dt, DATEFORMAT.ISO8601) dt = ws.get_cgi_parameter_datetime(form, PARAM.END_DATETIME) if dt: self.filter_end_datetime_iso8601 = cc_dt.format_datetime( dt, DATEFORMAT.ISO8601) filter_text = ws.get_cgi_parameter_str_or_none(form, PARAM.TEXT) if filter_text: self.filter_text = filter_text self.reset_pagination()
def get_params_from_form(paramspeclist, form): """Returns key/value dictionary of applicable parameters from form.""" kwargs = {} for paramspec in paramspeclist: paramtype = paramspec[PARAM.TYPE] paramname = paramspec[PARAM.NAME] if paramtype == PARAM.WHICH_IDNUM: idnum = ws.get_cgi_parameter_int(form, paramname) if idnum is None or idnum < 1 or idnum > NUMBER_OF_IDNUMS: continue kwargs[paramname] = idnum else: # Invalid paramtype continue return kwargs
def change_number_to_view(self, form): """Set how many tasks to view per page (from CGI form).""" self.number_to_view = ws.get_cgi_parameter_int(form, PARAM.NUMBER_TO_VIEW) self.reset_pagination()