Beispiel #1
0
def create(request):
    """Creates a collection."""
    role_bucket = services.get_or_update_role_bucket(request)
    course_collections = LTIService(request).getCourseCollections()
    collection_filters = dict(
        collection_ids=course_collections,
        can_filter=not queries.is_superuser_or_staff(request.user))
    collection_list = queries.getCollectionList(role_bucket,
                                                **collection_filters)

    if request.method == 'POST':
        lti_req = LTIService(request)
        published = not lti_req.isTeacher()
        request.POST = request.POST.copy()
        request.POST['published'] = published
        collection_form = CollectionForm(request.POST)

        card_template_id = collection_form.data['card_template']
        if collection_form.is_valid():
            collection = collection_form.save()
            lti_req.associateCourse(collection.id)
            services.add_user_to_collection(
                user=request.user,
                collection=collection,
                role=Users_Collections.ADMINISTRATOR)
            #update role_bucket to add admin permission to the user for this newly created collection
            services.get_or_update_role_bucket(
                request, collection.id,
                Users_Collections.role_map[Users_Collections.ADMINISTRATOR])
            log.info('Collection %s created.' % collection.id,
                     extra={'user': request.user})
            analytics.track(actor=request.user,
                            verb=analytics.VERBS.created,
                            object=analytics.OBJECTS.collection,
                            context={"custom": False})
            return redirect(collection)
    else:
        rel_templates = CardTemplate.objects.filter(
            Q(owner__isnull=True) | Q(owner=request.user))
        initial = {'card_template': '1'}
        card_template_id = initial['card_template']
        collection_form = CollectionForm(query_set=rel_templates,
                                         initial=initial)

    # Pre-populate the "preview" of the card template
    # This view is also called via AJAX on the page.
    prev_request = HttpRequest()
    prev_request.method = 'GET'
    prev_request.GET['card_template_id'] = card_template_id
    prev_response = card_template.preview(prev_request)
    card_template_preview_html = prev_response.content

    context = {
        "nav_collections": collection_list,
        "active_collection": None,
        "collection_form": collection_form,
        "card_template_preview_html": card_template_preview_html
    }

    return render(request, 'collections/create.html', context)
Beispiel #2
0
def create(request):
    """Creates a collection."""
    role_bucket = services.get_or_update_role_bucket(request)
    course_collections = LTIService(request).getCourseCollections()
    collection_filters = dict(collection_ids=course_collections, can_filter=not queries.is_superuser_or_staff(request.user))
    collection_list = queries.getCollectionList(role_bucket, **collection_filters)

    if request.method == 'POST':
        lti_req = LTIService(request)
        published = not lti_req.isTeacher()
        request.POST = request.POST.copy()
        request.POST['published'] = published
        collection_form = CollectionForm(request.POST)

        card_template_id = collection_form.data['card_template']
        if collection_form.is_valid():
            collection = collection_form.save()
            lti_req.associateCourse(collection.id)
            services.add_user_to_collection(user=request.user, collection=collection, role=Users_Collections.ADMINISTRATOR)
            #update role_bucket to add admin permission to the user for this newly created collection
            services.get_or_update_role_bucket(request, collection.id, Users_Collections.role_map[Users_Collections.ADMINISTRATOR])
            log.info('Collection %s created.' %collection.id, extra={'user': request.user})
            analytics.track(
                actor=request.user,
                verb=analytics.VERBS.created,
                object=analytics.OBJECTS.collection,
                context={"custom": False}
            )
            return redirect(collection)
    else:
        rel_templates = CardTemplate.objects.filter(Q(owner__isnull=True) | Q(owner=request.user))
        initial = {'card_template': '1'}
        card_template_id = initial['card_template']
        collection_form = CollectionForm(query_set=rel_templates,initial=initial)


    # Pre-populate the "preview" of the card template
    # This view is also called via AJAX on the page.
    prev_request = HttpRequest()
    prev_request.method = 'GET'
    prev_request.GET['card_template_id'] = card_template_id
    prev_response = card_template.preview(prev_request)
    card_template_preview_html = prev_response.content

    context = {
        "nav_collections": collection_list,
        "active_collection": None,
        "collection_form": collection_form,
        "card_template_preview_html": card_template_preview_html
    }

    return render(request, 'collections/create.html', context)
Beispiel #3
0
def copy_collection(request):
    collection_id = request.POST.get('collection_id', '')
    if collection_id == '':
        raise Http404

    has_perm_to_copy = queries.can_copy_collection(request.user, collection_id)
    if not has_perm_to_copy:
         raise PermissionDenied()

    new_collection = services.copy_collection(request.user, collection_id)

    services.add_user_to_collection(user=request.user, collection=new_collection, role=Users_Collections.ADMINISTRATOR)
    LTIService(request).associateCourse(new_collection.id)

    return redirect(new_collection)
Beispiel #4
0
def copy_collection(request):
    collection_id = request.POST.get('collection_id', '')
    if collection_id == '':
        raise Http404

    has_perm_to_copy = queries.can_copy_collection(request.user, collection_id)
    if not has_perm_to_copy:
        raise PermissionDenied()

    new_collection = services.copy_collection(request.user, collection_id)

    services.add_user_to_collection(user=request.user,
                                    collection=new_collection,
                                    role=Users_Collections.ADMINISTRATOR)
    LTIService(request).associateCourse(new_collection.id)

    return redirect(new_collection)
Beispiel #5
0
    def test_addUserToCollection(self):
        collection = self.make_collection()
        user = self.user
        role = Users_Collections.LEARNER

        success = services.add_user_to_collection(user=user, collection=collection, role=role)
        self.assertTrue(success)
        self.assertTrue(Users_Collections.objects.filter(user=user, collection=collection, role=role))
Beispiel #6
0
    def test_addUserToCollection(self):
        collection = self.make_collection()
        user = self.user
        role = Users_Collections.LEARNER

        success = services.add_user_to_collection(user=user,
                                                  collection=collection,
                                                  role=role)
        self.assertTrue(success)
        self.assertTrue(
            Users_Collections.objects.filter(user=user,
                                             collection=collection,
                                             role=role))