def drilldown_key( slug, obj_type ): label = u'' try: slugs = slug.split('/') if len(slugs) == 1: if _search_drilldown_cache.has_object(obj_type, slug): label = _search_drilldown_cache.get_object(obj_type, slug)['data']['label'] label = label.capitalize() else: label = slug.capitalize() else: if obj_type in ('admin3','admin2'): label = _search_drilldown_cache.get_object(obj_type, slugs[0])['data']['label'] elif obj_type in ('label','slug'): label = _search_drilldown_cache.get_object(obj_type, slugs[1])['data']['label'] else: label = slug.capitalize() label = label.capitalize() except: label = slug.capitalize() if _search_drilldown_cache.has_key(slug): label += ' ('+_search_drilldown_cache.get_key_data(slug)[obj_type]+')' return label
def drilldown_key_count( slug, obj_type ): #if slug.startswith(obj_type): # slug = slug[len(obj_type+'-'):] try: if _search_drilldown_cache.has_key(slug) \ and obj_type in _search_drilldown_cache.get_key_data(slug).keys(): return _search_drilldown_cache.get_key_data(slug)[obj_type][slug] else: return _search_drilldown_cache.get_object(obj_type, slug)['count'] except: traceback.print_exc() return '?'
def drilldown_key_label( slug, obj_type ): try: slugs = slug.split('/') if len(slugs) == 1: if _search_drilldown_cache.has_object(obj_type, slug): label = _search_drilldown_cache.get_object(obj_type, slug)['data']['label'] return label.capitalize() else: return slug.capitalize() else: if obj_type in ('admin3','admin2'): label = _search_drilldown_cache.get_object(obj_type, slugs[0])['data']['label'] elif obj_type in ('label','slug'): label = _search_drilldown_cache.get_object(obj_type, slugs[1])['data']['label'] else: return slug.capitalize() return label.capitalize() except: return slug.capitalize()
def drilldown_item_attrs( slug, obj_type ): attributes = u'' if obj_type in ( 'admin3-label', 'admin3-slug', 'admin2-label', 'admin2-slug'): slug = slug.split('/')[0] obj_type = obj_type.split('-')[0] data = _search_drilldown_cache.get_object(obj_type, slug) attributes += 'data-slug='+slug+' ' attributes += 'data-type='+obj_type+' ' if 'stats' in data and 'lat' in data['stats']: attributes += 'data-lat='+str(data['stats']['lat'])+' ' attributes += 'data-lng='+str(data['stats']['lng'])+' ' attributes += 'data-radius='+str(data['stats']['radius'])+' ' attributes += 'data-count='+str(data['stats']['count'])+' ' return attributes