Skip to content

Commit

Permalink
Displaying actual values for single and multiple lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
Julius O committed Feb 15, 2016
1 parent 8e8b8f8 commit e39740d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions geokey/contributions/templatetags/kml_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django import template

from geokey.categories.models import Field
from geokey.categories.models import Field, LookupField, MultipleLookupField


register = template.Library()
Expand Down Expand Up @@ -42,18 +42,26 @@ def kml_desc(place):

for key in properties:
name = key
value = properties[key]

try:
field = Field.objects.get(
key=key,
category_id=place.get('meta').get('category').get('id')
)
name = field.name.encode('utf-8')

if value is not None:
if isinstance(field, LookupField):
value = field.lookupvalues.get(pk=value).name
elif isinstance(field, MultipleLookupField):
values = field.lookupvalues.filter(
pk__in=value
)
value = '<br />'.join([v.name for v in values])
except Field.DoesNotExist:
pass

value = properties[key]

if type(value) in [str, unicode]:
value = value.encode('utf-8')

Expand Down

0 comments on commit e39740d

Please sign in to comment.