def episodes_for_criteria(self, criteria): """ Given one set of criteria, return episodes that match it. """ query = criteria querytype = query['queryType'] contains = '__iexact' if querytype == 'Contains': contains = '__icontains' column_name = query['column'] search_rule = SearchRule.get(column_name) if search_rule: return search_rule().query(query) field = query['field'].replace(' ', '_').lower() Mod = get_model_from_api_name(column_name) named_fields = [f for f in Mod._meta.fields if f.name == field] if len(named_fields) == 1 and isinstance(named_fields[0], djangomodels.BooleanField): eps = self._episodes_for_boolean_fields(query, field, contains) elif len(named_fields) == 1 and isinstance(named_fields[0], djangomodels.DateField): eps = self._episodes_for_date_fields(query, field, contains) elif len(named_fields) == 1 and fields.is_numeric(named_fields[0]): eps = self._episodes_for_number_fields(query, field, contains) elif hasattr(Mod, field) and isinstance(getattr(Mod, field), fields.ForeignKeyOrFreeText): eps = self._episodes_for_fkorft_fields(query, field, contains, Mod) elif hasattr(Mod, field) and isinstance(Mod._meta.get_field(field), djangomodels.ManyToManyField): eps = self._episodes_for_fkft_many_to_many_fields( query, field, contains, Mod ) else: model_name = get_model_name_from_column_name(query['column']) queryset_path = '{0}__{1}{2}'.format(model_name, field, contains) kw = {queryset_path: query['query']} if Mod == models.Tagging: tag_name = query['field'].replace(" ", "_").title() eps = models.Episode.objects.filter( tagging__value__iexact=tag_name ) elif issubclass(Mod, models.EpisodeSubrecord): eps = models.Episode.objects.filter(**kw) elif issubclass(Mod, models.PatientSubrecord): pats = models.Patient.objects.filter(**kw) eps = [] for p in pats: eps += list(p.episode_set.all()) return eps
def episodes_for_criteria(self, criteria): """ Given one set of criteria, return episodes that match it. """ query = criteria querytype = query['queryType'] contains = '__iexact' if querytype == 'Contains': contains = '__icontains' column_name = query['column'] search_rule = SearchRule.get(column_name) if search_rule: return search_rule().query(query) field = query['field'].replace(' ', '_').lower() Mod = get_model_from_api_name(column_name) named_fields = [f for f in Mod._meta.fields if f.name == field] if len(named_fields) == 1 and isinstance(named_fields[0], djangomodels.BooleanField): eps = self._episodes_for_boolean_fields(query, field, contains) elif len(named_fields) == 1 and isinstance(named_fields[0], djangomodels.DateField): eps = self._episodes_for_date_fields(query, field, contains) elif len(named_fields) == 1 and fields.is_numeric(named_fields[0]): eps = self._episodes_for_number_fields(query, field, contains) elif hasattr(Mod, field) and isinstance(getattr(Mod, field), fields.ForeignKeyOrFreeText): eps = self._episodes_for_fkorft_fields(query, field, contains, Mod) elif hasattr(Mod, field) and isinstance(Mod._meta.get_field(field), djangomodels.ManyToManyField): eps = self._episodes_for_fkft_many_to_many_fields( query, field, contains, Mod ) else: model_name = get_model_name_from_column_name(query['column']) queryset_path = '{0}__{1}{2}'.format(model_name, field, contains) kw = {queryset_path: query['query']} if Mod == models.Tagging: tag_name = query['field'].replace(" ", "_").title() eps = models.Episode.objects.filter( tagging__value__iexact=tag_name ) elif issubclass(Mod, models.EpisodeSubrecord): eps = models.Episode.objects.filter(**kw) elif issubclass(Mod, models.PatientSubrecord): pats = models.Patient.objects.filter(**kw) eps = [] for p in pats: eps += list(p.episode_set.all()) return eps
def test_is_numeric_true(self): numeric_fields = ( models.IntegerField, models.DecimalField, models.BigIntegerField, models.FloatField, models.PositiveIntegerField ) for field in numeric_fields: self.assertTrue(is_numeric(field()))
def test_is_numeric_true(self): numeric_fields = ( models.IntegerField, models.DecimalField, models.BigIntegerField, models.FloatField, models.PositiveIntegerField ) for field in numeric_fields: self.assertTrue(is_numeric(field()))
def infer_from_subrecord_field_path(subRecordFieldPath): _, field_name = subRecordFieldPath.split('.') model, field = _model_and_field_from_path(subRecordFieldPath) ctx = {} ctx["label"] = model._get_field_title(field_name) ctx["model"] = "editing.{0}.{1}".format( model.get_api_name(), field_name ) ctx['element_name'] = "editing.{0}._client.id + '_{1}'".format( model.get_api_name(), field_name ) if fields.is_numeric(field): ctx["element_type"] = "number" # for all django fields we'll get an empty list back # we default for free text or foreign keys enum = model.get_field_enum(field_name) if enum: ctx["lookuplist"] = json.dumps(enum, cls=OpalSerializer) else: lookuplist_api_name = model.get_lookup_list_api_name(field_name) if lookuplist_api_name: ctx["lookuplist"] = "{}_list".format(lookuplist_api_name) if hasattr(field, "formfield"): # TODO remove the blankable condition and make sure # all fields are null=False blankable = getattr(field, "blank", True) ctx["required"] = (not blankable) or field.formfield().required else: # ForeignKeyOrFreeText are never required at this time # so if we can't work out if its required, lets default # to false ctx["required"] = False if hasattr(field, "max_length"): ctx["maxlength"] = field.max_length return ctx
def infer_from_subrecord_field_path(subRecordFieldPath): _, field_name = subRecordFieldPath.split('.') model, field = _model_and_field_from_path(subRecordFieldPath) ctx = {} ctx["label"] = model._get_field_title(field_name) ctx["model"] = "editing.{0}.{1}".format(model.get_api_name(), field_name) ctx['element_name'] = "editing.{0}._client.id + '_{1}'".format( model.get_api_name(), field_name) if fields.is_numeric(field): ctx["element_type"] = "number" # for all django fields we'll get an empty list back # we default for free text or foreign keys enum = model.get_field_enum(field_name) if enum: ctx["lookuplist"] = json.dumps(enum) else: lookuplist_api_name = model.get_lookup_list_api_name(field_name) if lookuplist_api_name: ctx["lookuplist"] = "{}_list".format(lookuplist_api_name) if hasattr(field, "formfield"): # TODO remove the blankable condition and make sure # all fields are null=False blankable = getattr(field, "blank", True) ctx["required"] = (not blankable) or field.formfield().required else: # ForeignKeyOrFreeText are never required at this time # so if we can't work out if its required, lets default # to false ctx["required"] = False if hasattr(field, "max_length"): ctx["maxlength"] = field.max_length return ctx
def test_is_numeric_false(self): self.assertFalse(is_numeric(models.CharField))
def test_is_numeric_false(self): self.assertFalse(is_numeric(models.CharField))