@register.filter(name='user_location')
def parse_location(user):
 path = ''
 try:
  membership = user.membership
 except Membership.DoesNotExist:
  return ''
 if membership.city:
  path += ('%s' % membership.city)
 if membership.region:
  if membership.city:
   path += ', '
  path += ('%s' % membership.region)
 if membership.country:
  if membership.region:
   path += ' '
  elif membership.city:
   path += ', '
  path += ('%s' % membership.country)
 return path

@ register . filter ( name = 'user_location' ) def parse_location ( user ) : path = '' try : membership = user . membership except Membership . DoesNotExist : return '' if membership . city : path += ( '%s' % membership . city ) if membership . region : if membership . city : path += ', ' path += ( '%s' % membership . region ) if membership . country : if membership . region : path += ' ' elif membership . city : path += ', ' path += ( '%s' % membership . country ) return path
returns a formatted string of user location data .