def get_child_tags_from_category(request, category_id): from meta.models import Category, TagCategory category = Category.objects.get(pk=category_id) # Get all tags in order that belong to this category. from meta.CategoryUtilities import TreeBuilder tag_category_builder = TreeBuilder('tag_category') (browse_tree, flattened_tree) = tag_category_builder.build_tree( {'root': [TagCategory.objects.get(title='Standards')]}, []) tags = category.tags.filter(category__in=flattened_tree).order_by('position') serialized_tags = {} for tag in tags: serialized_tags[tag.id] = { 'id': tag.id, 'title': tag.title, 'description': tag.description, 'position': tag.position, 'url': reverse( 'meta:standard', kwargs={ 'tag_title': tag.title }) } context = { 'tags': serialized_tags } return APIUtilities._api_success(context)
def get_standards_tree(request): try: standards_category = Category.objects.get(title='Standards') from meta.CategoryUtilities import TreeBuilder category_builder = TreeBuilder('category_tags') (browse_tree, flattened_tree) = category_builder.build_tree( {'root': [standards_category]}, []) tree = build_standards_navigation(browse_tree) context = { 'tree': tree } return APIUtilities._api_success(context) except: context = { 'title': 'Could not load the standards list', 'message': 'We failed to load the list of standards for you. ' + 'Please contact us if the problem persists.' } return APIUtilities._api_failure(context)