[GeoNode-users] Extend autocomplete-light with new fields

Toni Schönbuchner toni.schoenbuchner at csgis.de
Wed Feb 22 06:01:26 PST 2017


Sorry Simone,

I cannot see the forest because of trees.

> The 404 is because you the original one must stay, you should add your own.


Do you mean a new resourceBase model? or a new autocomplete register Instance?
This is where I´m getting confused as the text_search_input from layers page is filtering against
resourceBase model. AUTOCOMPLETE_URL_RESOURCEBASE = '/autocomplete/ResourceBaseAutocomplete/
which is what I need but simple with more fields than title (abstract + puropose).
>> 	search_fields=[‘title‘,’abstract’,’purpose'],


> I don't understand why you have to modify the request, in autocomplete all is done in a 'magical' way and if you register your own and add the correct name in the relevant template then it'll just work.

I think that´s the key point I´m asking for. How can I tell autocomplete to search against title, abstract and purpose
but only return fields where the user input is found? It´s this magic that is unclear to me.

To not steal your time, maybe you know of a fork where something like this has been done before?
A code snipptes would help to shorten this and get it running.

all the best,

toni



> Am 22.02.2017 um 14:07 schrieb Simone Dalmasso <simone.dalmasso at gmail.com>:
> 
> The 404 is because you the original one must stay, you should add your own.
> 
> I don't understand why you have to modify the request, in autocomplete all is done in a 'magical' way and if you register your own and add the correct name in the relevant template then it'll just work.
> 
> 2017-02-22 13:56 GMT+01:00 Toni Schönbuchner <toni.schoenbuchner at csgis.de <mailto:toni.schoenbuchner at csgis.de>>:
> Dear Simone,
> 
> thanks for your fast reply!
> 
>> correct name, see https://github.com/GeoNode/geonode/blob/master/geonode/templates/base.html#L296 <https://github.com/GeoNode/geonode/blob/master/geonode/templates/base.html#L296>.
> 
> I think this template is for the top search, right? I´m working on the left side menu which should be here:
> https://github.com/GeoNode/geonode/blob/2.4.x/geonode/static/geonode/js/search/search.js#L366 <https://github.com/GeoNode/geonode/blob/2.4.x/geonode/static/geonode/js/search/search.js#L366>
> 
> Why I´m puzzled is, why do I already get a 404 when changing register as the DAL documentation suggests:
> 
> FROM:
> 
>> autocomplete_light.register(ResourceBase,
>> 	search_fields=[‘title‘,’abstract’,’purpose'],
>> 	autocomplete_js_attributes={'placeholder': 'Resource name..', },)
> 
> TO:
> 
>> class CustomResource(autocomplete_light.AutocompleteModelBase):
>>     search_fields = ['title', ‚abstract‘,’purpose']
>>     model = ResourceBase
>> 
>> autocomplete_light.register(CustomResource)
> 
> 
> And if this works how would I get access to user request q and the choices coming from my model to overwrite the
> http response. Sorry for asking again but even if DAL says it´s build for easy use it has so many options that it´s
> hard for me to find a start.
> 
> thanks!
> 
> toni
> 
> 
>> Am 22.02.2017 um 13:46 schrieb Simone Dalmasso <simone.dalmasso at gmail.com <mailto:simone.dalmasso at gmail.com>>:
>> 
>> Hi, definitely the second way is the one to go with. You can see what there's already in geonode and make your own https://github.com/GeoNode/geonode/blob/master/geonode/base/autocomplete_light_registry.py <https://github.com/GeoNode/geonode/blob/master/geonode/base/autocomplete_light_registry.py> and call it from the template using the correct name, see https://github.com/GeoNode/geonode/blob/master/geonode/templates/base.html#L296 <https://github.com/GeoNode/geonode/blob/master/geonode/templates/base.html#L296>.
>> 
>>  hope this helps
>> 
>> 2017-02-22 13:26 GMT+01:00 Toni Schönbuchner <toni.schoenbuchner at csgis.de <mailto:toni.schoenbuchner at csgis.de>>:
>> 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
>> 
>> _______________________________________________
>> geonode-users mailing list
>> geonode-users at lists.osgeo.org <mailto:geonode-users at lists.osgeo.org>
>> https://lists.osgeo.org/mailman/listinfo/geonode-users <https://lists.osgeo.org/mailman/listinfo/geonode-users>
>> 
>> 
>> 
>> 
>> --
>> Simone
> 
> 
> 
> 
> --
> Simone

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/geonode-users/attachments/20170222/ea9dae8e/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 842 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.osgeo.org/pipermail/geonode-users/attachments/20170222/ea9dae8e/attachment-0001.sig>


More information about the geonode-users mailing list