<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><div><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><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 class=""><br><br><br><font color="#999999" class="">Enviado con <a href="https://mailtrack.io/install?source=signature&lang=es&referral=melvin.ramos1991@gmail.com&idSignature=23" class="">MailTrack</a></font></div></div><img width="0" height="0" class="mailtrack-img" src="https://mailtrack.io/trace/mail/285475639f8c9fe8f6aac6bc061e151f3597139f.png"></div>