Beispiel #1
0
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)
Beispiel #2
0
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)
Beispiel #3
0
def add_existing_to_section_item_resources(request):
    section_item_resources_id = request.POST.get('section_item_resources_id', None)
    #is_resource = request.POST.get('is_resource', None) == 'true'
    resource_collection_id = request.POST.get('resource_collection_ID', None)

    try:
        section_item_resources = SectionItemResources.objects.get(pk=section_item_resources_id)
    except:
        section_item_resources = create_resource_set(request, section_item_resources)

        if not section_item_resources:
            return APIUtilities._api_not_found()


    from oer.models import Resource as OEResource    
    resource = OEResource.objects.get(pk=resource_collection_id)

    new_objective_resource = Resource(resource=resource)
    new_objective_resource.save()

    section_item_resources.resources.add(new_objective_resource)

    import oer.CollectionUtilities as cu
    cu.set_resources_type([resource])
    cu.preprocess_collection_listings([resource])

    context = {
        'resource': {
            'id': new_objective_resource.id,
            'url': reverse(
                'read', kwargs={
                    'resource_id': resource.id,
                    'resource_slug': resource.slug
                }
            ),
            'thumbnail': settings.MEDIA_URL + resource.image.name if resource.image else '',
            'title': resource.title,
            'type': resource.type
        }
    }

    return APIUtilities.success(context)
Beispiel #4
0
def _get_fields(item):
    serialized_resource_sets = []

    from os.path import splitext
    from oer.models import Link, Attachment

    from django.contrib.contenttypes.models import ContentType

    link_content_type = ContentType.objects.get_for_model(Link)
    reference_content_type = ContentType.objects.get_for_model(Reference)
    attachment_content_type = ContentType.objects.get_for_model(Attachment)

    from meta.models import Tag

    document = [".doc", ".docx", ".rtf", "odt"]

    for resource_set in item.resource_sets.all():
        serialized_resources = []

        for resource in resource_set.resources.all():
            import oer.CollectionUtilities as cu
            cu.set_resources_type([resource.resource])
            cu.preprocess_collection_listings([resource.resource])

            if resource.resource.revision.content_type == attachment_content_type:
                name, extension = splitext(
                    resource.resource.revision.content.file.name)

                if extension in document:
                    resource.resource.type = 'pdf'

            thumbnail = settings.MEDIA_URL + resource.resource.revision.content.textbook.thumbnail.name if (
                resource.resource.revision.content_type == reference_content_type) else settings.MEDIA_URL + resource.resource.image.name

            serialized_resources.append({
                'id': resource.id,
                'url': resource.resource.revision.content.url if (
                    resource.resource.revision.content_type == link_content_type) else reverse(
                    'read', kwargs={
                        'resource_id': resource.resource.id,
                        'resource_slug': resource.resource.slug
                    }
                ),
                'title': resource.resource.title,
                'thumbnail': thumbnail,
                'user_thumbnail': settings.MEDIA_URL + resource.resource.user.get_profile().profile_pic.name,
                'type': resource.resource.type
            })

        serialized_resource_sets.append({
            'id': resource_set.id,
            'position': resource_set.position,
            'title': resource_set.title,
            'resources': serialized_resources
        })

    """if item.resource_sets.count() == 0:
        serialized_resource_sets.append({
            'id': None,
            'resources': []
        })"""

    if item.meta:
        for meta_item in item.meta:
            if 'standards' in meta_item:
                standards = []
                for std_id in meta_item['standards']:
                    standard = Tag.objects.get(pk=std_id)
                    standards.append({
                        'title': standard.title,
                        'description': standard.description
                    })

                meta_item['standards'] = standards

    return (serialized_resource_sets, item.meta)