[GeoNode-users] Extend autocomplete-light with new fields
Toni Schönbuchner
toni.schoenbuchner at csgis.de
Wed Feb 22 04:26:36 PST 2017
Hi together,
this might be an easy one. In geonode 2.4 I have extended autocomplete registry to search in more fields
on layers left side title-search-input.
https://github.com/GeoNode/geonode/blob/2.4.x/geonode/base/autocomplete_light_registry.py <https://github.com/GeoNode/geonode/blob/2.4.x/geonode/base/autocomplete_light_registry.py>
autocomplete_light.register(ResourceBase,
search_fields=[‘title‘,’abstract’,’purpose'],
autocomplete_js_attributes={'placeholder': 'Resource name..', },)
then changed the base model to return abstract and purpose content as well:
https://github.com/GeoNode/geonode/blob/2.4.x/geonode/base/models.py#L342 <https://github.com/GeoNode/geonode/blob/2.4.x/geonode/base/models.py#L342>
def __unicode__(self):
return self.title + ’,’ + self.abstract + ’,’ + self.purpose
The result is a user can search f.e. for ‚dog‘ and autocomplete shows choices like:
Dog Title, Dogs Heaven, the purpose is sleep
Dogs world, Dogs Hell, the purpose is eat
All that is missing is that I do not want to show a field when the search term is not
found in it. F.e. if purpose does not has ‚dog‘ autoselect should not show it.
Dog Title, Dogs Heaven
…
From the documentation of DAL I assumed that the way to go is to create/register a subclass like:
class CustomResource(autocomplete_light.AutocompleteModelBase):
search_fields = ['title', ‚abstract‘,’purpose']
model = ResourceBase
autocomplete_light.register(CustomResource)
and override the httpResponse method. Unfortunately this basic step already ends in a 404.
Maybe one could bring me on the right track how to achieve filtering the return.
Thanks,
Toni
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/geonode-users/attachments/20170222/99d6c35b/attachment.html>
More information about the geonode-users
mailing list