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

Simone Dalmasso simone.dalmasso at gmail.com
Wed Feb 22 05:07:51 PST 2017


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>:

> Dear Simone,
>
> thanks for your fast reply!
>
> correct name, see 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
>
> 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
> >:
>
> 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 and
> call it from the template using the correct name, see
> 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>
> :
>
>> 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
>>
>> 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
>>     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
>> 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/76ac3680/attachment.html>


More information about the geonode-users mailing list