show filterable:true for filterable fields

This commit is contained in:
Jake McDermott 2018-05-03 16:45:09 -04:00
parent a9c9646060
commit 0682d19d5e
No known key found for this signature in database
GPG Key ID: 3B02CAD476EECB35
3 changed files with 19 additions and 16 deletions

View File

@ -62,15 +62,11 @@ class Metadata(metadata.SimpleMetadata):
opts = serializer.Meta.model._meta.concrete_model._meta
verbose_name = smart_text(opts.verbose_name)
field_info['help_text'] = field_help_text[field.field_name].format(verbose_name)
# If field is not part of the model, then show it as non-filterable
else:
is_model_field = False
for model_field in serializer.Meta.model._meta.fields:
if field.field_name == model_field.name:
is_model_field = True
break
if not is_model_field:
field_info['filterable'] = False
for model_field in serializer.Meta.model._meta.fields:
if field.field_name == model_field.name:
field_info['filterable'] = True
break
# Indicate if a field has a default value.
# FIXME: Still isn't showing all default values?

View File

@ -94,10 +94,16 @@ class TestDeleteViews:
@pytest.mark.django_db
def test_non_filterable_field(options, instance, admin_user):
def test_filterable_fields(options, instance, admin_user):
r = options(
url=instance.get_absolute_url(),
user=admin_user
)
field_info = r.data['actions']['GET']['percent_capacity_remaining']
assert 'filterable' in field_info
filterable_info = r.data['actions']['GET']['created']
non_filterable_info = r.data['actions']['GET']['percent_capacity_remaining']
assert 'filterable' in filterable_info
assert filterable_info['filterable'] is True
assert 'filterable' not in non_filterable_info

View File

@ -53,7 +53,7 @@ function SmartSearchController (
$scope.models = data.models;
$scope.options = data.options.data;
$scope.keyFields = _.reduce(data.models[$scope.djangoModel].base, function(result, value, key) {
if (!(typeof value.filterable === "boolean" && value.filterable === false)) {
if (value.filterable) {
result.push(key);
}
return result;
@ -150,10 +150,11 @@ function SmartSearchController (
const listName = $scope.list.name;
const baseFieldPath = `models.${listName}.base.${rootField}`;
const isBaseField = _.has($scope, `${baseFieldPath}`);
const filterable = _.get($scope, `${baseFieldPath}.filterable`);
const isNotFilterable = typeof filterable === "boolean" && filterable === false;
const isFilterable = _.get($scope, `${baseFieldPath}.filterable`);
const isBaseModelRelatedSearchTermField = (_.get($scope, `${baseFieldPath}.type`) === 'field');
return isBaseField && !isBaseModelRelatedSearchTermField && !isNotFilterable;
return isBaseField && !isBaseModelRelatedSearchTermField && isFilterable;
}
function isRelatedField (termParts) {