def list_collection(request, project_slug, collection_slug): try: project = Project.objects.get(slug=project_slug) except: raise Http404 (browse_tree, flattened_tree) = _get_browse_tree(project.collection) collection = next( tree_item for tree_item in flattened_tree if tree_item.slug == collection_slug) root_assets = collection.resources import oer.CollectionUtilities as cu child_collections = cu._get_child_collections(collection) resources = root_assets.all() cu.set_resources_type(resources) cu.preprocess_collection_listings(resources) context = { 'project': project, 'resources': resources, 'collections': child_collections, 'collection': collection, 'browse_tree': browse_tree, # TODO(Varun): Make this a custom title. 'title': (_(settings.STRINGS['projects']['BROWSE_TITLE']) + ' ‹ ' + project.title) } return render(request, 'project/browse.html', context)
def browse(request, project_slug): try: project = Project.objects.get(slug=project_slug) except: raise Http404 # Get the root collection of the project. root_collection = project.collection # Get all the assets of the root collection. root_assets = root_collection.resources import oer.CollectionUtilities as cu child_collections = cu._get_child_collections(root_collection) (browse_tree, flattened_tree) = _get_browse_tree(root_collection) resources = root_assets.all() cu.set_resources_type(resources) cu.preprocess_collection_listings(resources) context = { 'project': project, 'resources': resources, 'collections': child_collections, 'collection': root_collection, 'browse_tree': browse_tree, 'title': (_(settings.STRINGS['projects']['BROWSE_TITLE']) + ' ‹ ' + project.title) } return render(request, 'project/browse.html', context)
def _hasImmediateChildren(collection): """Adapted from _hasImmediateChildren() in articles.views""" import oer.CollectionUtilities as cu childCollections = list(cu._get_child_collections(collection)) if len(childCollections) > 0: return {collection: childCollections} else: return None