<div dir="ltr">Hi<div>nice customization.</div><div>What about creating your own TopicCategory model in a different application with a one to one foreign key (or many to many one) to base ResourceBase?</div><div>This way you don't need to fork GeoNode, but just extend the template</div><div>regards</div><div>p</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jun 19, 2015 at 12:19 AM, Melvin Ramos <span dir="ltr"><<a href="mailto:melvin.ramos1991@gmail.com" target="_blank">melvin.ramos1991@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello Simone,<div><br></div><div>"You did well young padawan" (:</div><div><br></div><div>Thanks. I just checked it out. In theory I replicated everything but still not working. I will go step by step like before:</div><div><br></div><div><b>Modified search_scripts.html in the search templates</b></div><div><br></div><div>I added this line of code:</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><i>IUCN_CATEGORIES_ENDPOINT = '{% url 'api_dispatch_list' api_name='api' resource_name='iucn_categories' %}';</i></blockquote><div><br></div><div>Just like the categories endpoint</div><div><br></div><div><b>Modified the search.js in the static folder</b></div><div><br></div><div>I added in the loaded section the following</div><div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><i> module.load_iucn_categories = function ($http, $rootScope, $location){<br></i><i> var params = typeof FILTER_TYPE == 'undefined' ? {} : {'type': FILTER_TYPE};<br></i><i> if ($location.search().hasOwnProperty('title__icontains')){<br></i><i> params['title__icontains'] = $location.search()['title__icontains'];<br></i><i> }<br></i><i> $http.get(IUCN_CATEGORIES_ENDPOINT, {params: params}).success(function(data){<br></i><i> if($location.search().hasOwnProperty('iucn_category__identifier__in')){<br></i><i> data.objects = module.set_initial_filters_from_query(data.objects,<br></i><i> $location.search()['iucn_category__identifier__in'], 'identifier');<br></i><i> }<br></i><i> $rootScope.categories = data.objects;<br></i><i> if (HAYSTACK_FACET_COUNTS && $rootScope.query_data) {<br></i><i> module.haystack_facets($http, $rootScope, $location);<br></i><i> }<br></i><i> });<br></i><i> }</i></blockquote></div><div><br></div><div>Then I added in the module.haystack_facets the following</div><div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><i> if ("iucn_categories" in $rootScope) {<br></i><i> $rootScope.category_counts = data.meta.facets.category;<br></i><i> for (var id in $rootScope.categories) {<br></i><i> var category = $rootScope.categories[id];<br></i><i> if (category.identifier in $rootScope.category_counts) {<br></i><i> category.count = $rootScope.category_counts[category.identifier]<br></i><i> } else {<br></i><i> category.count = 0;<br></i><i> }<br></i><i> }<br></i><i> }</i></blockquote></div><div><br></div><div>Finally, in the module.run I added this</div><div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><i> if ($('#iucn_categories').length > 0){<br></i><i> module.load_categories($http, $rootScope, $location);<br></i><i> }</i></blockquote></div><div><br></div><div>But it didn't work, still shows nothing on the template.What am I missing??</div><div><br></div><div>Thanks in advance,</div><div><br></div><div>Melvin</div><div><br></div><div><div><br><br><br><font color="#999999">Enviado con <a href="https://mailtrack.io/install?source=signature&lang=es&referral=melvin.ramos1991@gmail.com&idSignature=23" target="_blank">MailTrack</a></font></div></div><img width="0" height="0" src="https://mailtrack.io/trace/mail/93547d482a5d9ff44a542d11ea76a11890a23bc1.png"></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">2015-06-18 17:01 GMT-04:30 Simone Dalmasso <span dir="ltr"><<a href="mailto:simone.dalmasso@gmail.com" target="_blank">simone.dalmasso@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Melvin,<div>you did well, the only missing thing is here <a href="https://github.com/GeoNode/geonode/blob/master/geonode/static/geonode/js/search/search.js" target="_blank">https://github.com/GeoNode/geonode/blob/master/geonode/static/geonode/js/search/search.js</a>, javascript part that loads the categories through the api and compiles the query.</div><div><br></div><div>Ciao</div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div>2015-06-18 23:17 GMT+02:00 Melvin Ramos <span dir="ltr"><<a href="mailto:melvin.ramos1991@gmail.com" target="_blank">melvin.ramos1991@gmail.com</a>></span>:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr">Hello,<div><br></div><div>I'm trying to duplicate the Categories filter, because I'm need to use a new set of categories for my layers, but I'm having a hard time trying to find out how the templates gets the data since it uses AngularJS.</div><div><br></div><div>So here is what I''ve done so far:</div><div><br></div><div><b>Modified the models.py of the Base app</b></div><div>I added a new class called IUCNCategory</div><div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><i>class IUCNCategory(models.Model):<br> """<br> Metadata regarding IUCN standards<br> """<br> identifier = models.CharField(max_length=255)<br> category_type = models.CharField(<br> choices=(<br> ('risk_criteria', 'Risk Criteria'),<br> ('bio_realm', 'Biogeographical Realm'),<br> ('typology', 'Typology')<br> ),<br> max_length=255,<br> )<br> description = models.TextField(default='')<br> gn_description = models.TextField('RLE description', default='', null=True)<br> # is_choice = models.BooleanField(default=True)<br> def __unicode__(self):<br> return u"{0}".format(self.gn_description)<br> class Meta:<br> ordering = ("category_type","identifier",)<br> verbose_name_plural = 'IUCN Categories'</i></blockquote></div><div><br></div><div>It's just like TopicCategory with one different attribute.</div><div><br></div><div>I added to the class ResourceBase the following attribute</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><i>iucn_category = models.ForeignKey(IUCNCategory, null=True, blank=True)</i></blockquote><div><br></div><div><br></div><div><b>Modified the api.py </b><b>of the Api app</b></div><div>I created a new class called IUCNCategoryResource</div><div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><i>class IUCNCategoryResource(TypeFilteredResource):<br></i><i> """IUCN Category api"""</i><i><br></i><i> def serialize(self, request, data, format, options={}):<br></i><i> options['count_type'] = 'iucn_category'</i><i><br></i><i> return super(IUCNCategoryResource, self).serialize(request, data, format, options)</i><i><br></i><i> class Meta:<br></i><i> queryset = IUCNCategory.objects.all()<br></i><i> resource_name = 'iucn_categories'<br></i><i> allowed_methods = ['get']<br></i><i> filtering = {<br></i><i> 'identifier': ALL,<br></i><i> }<br></i><i> serializer = CountJSONSerializer()</i></blockquote></div><div><br></div><div>It's like the class TopicCategoryResource</div><div><br></div><div><b>Modified the</b><b> </b><b>resourcebase_api.py </b><b>of the Api app</b></div><div><br></div><div>I added to the class CommonModelApi the following attribute</div><div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><i>iucn_category = fields.ToOneField(<br> IUCNCategoryResource,<br> 'iucn_category',<br> null=True,<br> full=True)</i></blockquote></div><div><br></div><div>In the definition on the Haystack filters I added the following in the proper places:</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><i>...<br>iucn_category = parameters.getlist("iucn_category__identifier__in")<br>...<br>if iucn_category:<br> sqs = (SearchQuerySet() if sqs is None else sqs).narrow(<br> 'iucn_category:%s' % ','.join(map(str, iucn_category)))<br>...</i></blockquote><div><i><br></i></div><div>Just like the category field.</div><div><i><br></i></div><div><b>Modified the</b><b> urls</b><b>.py </b><b>of the Api app</b><i><br></i></div><div><i><br></i></div><div>I imported the IUCNCategoryResource from the apy.py and wrote </div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><i>api.register(IUCNCategoryResource())</i></blockquote><div><br></div><div><b>Modified the template _general_filters.html inside the search templates</b><br></div><div><br></div><div>I added the following code</div><div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><i><nav class="filter"><br></i><i> <h4><a href="#" class="toggle toggle-nav"><i class="fa fa-chevron-right"></i>{% trans "Risk Criteria" %}</a></h4><br></i><i> <ul class="nav closed" id="iucn_categories"><br></i><i> {% verbatim %}<br></i><i> <li ng-repeat="iucn_category in iucn_categories" ng-if="iucn_category.count > 0"><br></i><i> <a data-value="{{ iucn_category.identifier }}" data-filter="iucn_category__identifier__in" <br></i><i> ng-click="multiple_choice_listener($event)" class="{{iucn_category.active}}">{{ iucn_category.gn_description | limitTo: 25 }}{{ iucn_category.gn_description.length > 25 ? '...' : ''}}<br></i><i> <span class="badge pull-right">{{ iucn_category.count }}</span><br></i><i> </a><br></i><i> </li><br></i><i> {% endverbatim %}<br></i><i> </ul><br></i><i></nav></i></blockquote></div><div><br></div><div>But nothing shows beneath the filter name in the template, even when I have one IUCN category stored in database. I'm guessing there is a view somewhere or I'm missing something that allows to pass the data and I can't find it or just Angular is too mystic for me.</div><div><br></div><div>Can anybody help me?</div><div><br></div><div>Thanks in advance,</div><div><br></div><div>Melvin</div><span><font color="#888888"><div><br clear="all"><div><br></div>-- <br><div><div>Melvin David Ramos Macías</div><div>07-41408</div><div>Ingeniería de Computación</div><div>Universidad Simón Bolívar</div></div>
<div><br><br><br><font color="#999999">Enviado con <a href="https://mailtrack.io/install?source=signature&lang=es&referral=melvin.ramos1991@gmail.com&idSignature=23" target="_blank">MailTrack</a></font></div></div><img width="0" height="0" src="https://mailtrack.io/trace/mail/285475639f8c9fe8f6aac6bc061e151f3597139f.png"></font></span></div>
<br></div></div>_______________________________________________<br>
geonode-users mailing list<br>
<a href="mailto:geonode-users@lists.osgeo.org" target="_blank">geonode-users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/geonode-users" rel="noreferrer" target="_blank">http://lists.osgeo.org/cgi-bin/mailman/listinfo/geonode-users</a><br>
<br></blockquote></div><span><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div>Simone </div>
</font></span></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div><div>Melvin David Ramos Macías</div><div>07-41408</div><div>Ingeniería de Computación</div><div>Universidad Simón Bolívar</div></div>
</div>
</div></div><br>_______________________________________________<br>
geonode-users mailing list<br>
<a href="mailto:geonode-users@lists.osgeo.org" target="_blank">geonode-users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/geonode-users" rel="noreferrer" target="_blank">http://lists.osgeo.org/cgi-bin/mailman/listinfo/geonode-users</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div>Paolo Corti<br>Geospatial software developer<br>web: <a href="http://www.paolocorti.net" target="_blank">http://www.paolocorti.net</a><br>twitter: @capooti<br>skype: capooti</div>
</div></div>