[GeoNode-users] Create new filter for layers

Melvin Ramos melvin.ramos1991 at gmail.com
Thu Jun 18 14:17:35 PDT 2015


Hello,

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.

So here is what I''ve done so far:

*Modified the models.py of the Base app*
I added a new class called IUCNCategory


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *class IUCNCategory(models.Model):    """    Metadata regarding IUCN
> standards    """    identifier = models.CharField(max_length=255)
> category_type = models.CharField(        choices=(
> ('risk_criteria', 'Risk Criteria'),            ('bio_realm',
> 'Biogeographical Realm'),            ('typology', 'Typology')        ),
>     max_length=255,    )    description = models.TextField(default='')
> gn_description = models.TextField('RLE description', default='',
> null=True)    # is_choice = models.BooleanField(default=True)    def
> __unicode__(self):        return u"{0}".format(self.gn_description)
> class Meta:        ordering = ("category_type","identifier",)
> verbose_name_plural = 'IUCN Categories'*


It's just like TopicCategory with one different attribute.

I added to the class ResourceBase the following attribute

*iucn_category = models.ForeignKey(IUCNCategory, null=True, blank=True)*



*Modified the api.py **of the Api app*
I created a new class called IUCNCategoryResource


> *class IUCNCategoryResource(TypeFilteredResource):**    """IUCN Category
> api"""*
>
> *    def serialize(self, request, data, format, options={}):**
> options['count_type'] = 'iucn_category'*
> *        return super(IUCNCategoryResource, self).serialize(request, data,
> format, options)*
>
> *    class Meta:*
> *        queryset = IUCNCategory.objects.all()*
> *        resource_name = 'iucn_categories'*
> *        allowed_methods = ['get']*
> *        filtering = {*
> *            'identifier': ALL,*
> *        }**        serializer = CountJSONSerializer()*


It's like the class TopicCategoryResource

*Modified the* *resourcebase_api.py **of the Api app*

I added to the class CommonModelApi the following attribute


>
>
>
> *iucn_category = fields.ToOneField(        IUCNCategoryResource,
> 'iucn_category',        null=True,        full=True)*


In the definition on the Haystack filters I added the following in the
proper places:


>
>
>
>
>
> *...iucn_category =
> parameters.getlist("iucn_category__identifier__in")...if iucn_category:
>         sqs = (SearchQuerySet() if sqs is None else sqs).narrow(
>     'iucn_category:%s' % ','.join(map(str, iucn_category)))...*


Just like the category field.

*Modified the** urls**.py **of the Api app*

I imported the IUCNCategoryResource from the apy.py and wrote

*api.register(IUCNCategoryResource())*


*Modified the template _general_filters.html inside the search templates*

I added the following code


> *<nav class="filter">*
> *  <h4><a href="#" class="toggle toggle-nav"><i class="fa
> fa-chevron-right"></i>{% trans "Risk Criteria" %}</a></h4>*
> *  <ul class="nav closed" id="iucn_categories">*
> *    {% verbatim %}*
> *      <li ng-repeat="iucn_category in iucn_categories"
> ng-if="iucn_category.count > 0">*
> *        <a data-value="{{ iucn_category.identifier }}"
> data-filter="iucn_category__identifier__in" *
> *         ng-click="multiple_choice_listener($event)"
> class="{{iucn_category.active}}">{{ iucn_category.gn_description | limitTo:
> 25 }}{{ iucn_category.gn_description.length > 25 ? '...' : ''}}*
> *          <span class="badge pull-right">{{ iucn_category.count }}</span>*
> *        </a>*
> *      </li>*
> *    {% endverbatim %}*
> *  </ul>**</nav>*


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.

Can anybody help me?

Thanks in advance,

Melvin


-- 
Melvin David Ramos Macías
07-41408
Ingeniería de Computación
Universidad Simón Bolívar



Enviado con MailTrack
<https://mailtrack.io/install?source=signature&lang=es&referral=melvin.ramos1991@gmail.com&idSignature=23>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/geonode-users/attachments/20150618/668ad578/attachment.html>


More information about the geonode-users mailing list