Beispiel #1
0
    def test_edit_annotation(self):
        note = SherdNoteFactory(asset=self.asset,
                                author=self.student_one,
                                title='Selection',
                                range1=116.25,
                                range2=6.75)

        data = {
            'annotation-range1': -4.5,
            'annotation-tags': 'foo,bar',
            'next': 'foo'
        }
        request = RequestFactory().post('/', data)
        request.user = self.student_two

        with self.assertRaises(Http404):
            edit_annotation(request, 123)

        response = edit_annotation(request, note.id)
        self.assertEquals(response.status_code, 403)

        # via post
        request.user = self.student_one
        response = edit_annotation(request, note.id)
        self.assertEquals(response.status_code, 302)
        note.refresh_from_db()
        self.assertEquals(note.range1, -4.5)
        self.assertEquals(note.tags, 'foo,bar')

        # via ajax
        data = {'annotation-range2': 7}
        request = RequestFactory().post('/',
                                        data,
                                        HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        request.user = self.student_one
        response = edit_annotation(request, note.id)
        self.assertEquals(response.status_code, 200)
        the_json = loads(response.content)
        self.assertEquals(the_json['asset']['id'], self.asset.id)
        self.assertEquals(the_json['annotation']['id'], note.id)
        note.refresh_from_db()
        self.assertEquals(note.range2, 7)
Beispiel #2
0
def annotation_save(request, asset_id, annot_id):
    try:
        # Verify annotation exists
        SherdNote.objects.get(pk=annot_id,
                              asset=asset_id,
                              asset__course=request.course)

        form = request.GET.copy()
        form['next'] = '.'
        request.GET = form
        return edit_annotation(request, annot_id)  # djangosherd.views
    except SherdNote.DoesNotExist:
        return HttpResponseForbidden("forbidden")
Beispiel #3
0
    def test_edit_annotation(self):
        note = SherdNoteFactory(
            asset=self.asset, author=self.student_one,
            title='Selection', range1=116.25, range2=6.75)

        data = {'annotation-range1': -4.5,
                'annotation-tags': 'foo,bar', 'next': 'foo'}
        request = RequestFactory().post('/', data)
        request.user = self.student_two

        with self.assertRaises(Http404):
            edit_annotation(request, 123)

        response = edit_annotation(request, note.id)
        self.assertEquals(response.status_code, 403)

        # via post
        request.user = self.student_one
        response = edit_annotation(request, note.id)
        self.assertEquals(response.status_code, 302)
        note.refresh_from_db()
        self.assertEquals(note.range1, -4.5)
        self.assertEquals(note.tags, 'foo,bar')

        # via ajax
        data = {'annotation-range2': 7}
        request = RequestFactory().post('/', data,
                                        HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        request.user = self.student_one
        response = edit_annotation(request, note.id)
        self.assertEquals(response.status_code, 200)
        the_json = loads(response.content)
        self.assertEquals(the_json['asset']['id'], self.asset.id)
        self.assertEquals(the_json['annotation']['id'], note.id)
        note.refresh_from_db()
        self.assertEquals(note.range2, 7)
Beispiel #4
0
def annotation_save(request, asset_id, annot_id):
    try:
        # Verify annotation exists
        ann = SherdNote.objects.get(pk=annot_id,
                                    asset=asset_id,
                                    asset__course=request.course)

        if (ann.is_global_annotation() and 'asset-title' in request.POST and
            (request.user.is_staff or request.user == ann.asset.author)):
            ann.asset.title = request.POST.get('asset-title')
            ann.asset.save()

        form = request.GET.copy()
        form['next'] = '.'
        request.GET = form
        return edit_annotation(request, annot_id)  # djangosherd.views
    except SherdNote.DoesNotExist:
        return HttpResponseForbidden("forbidden")
Beispiel #5
0
def annotation_save(request, asset_id, annot_id):
    try:
        # Verify annotation exists
        ann = SherdNote.objects.get(pk=annot_id,
                                    asset=asset_id,
                                    asset__course=request.course)

        if (ann.is_global_annotation() and
            'asset-title' in request.POST and
                (request.user.is_staff or request.user == ann.asset.author)):
            ann.asset.title = request.POST.get('asset-title')
            ann.asset.save()

        form = request.GET.copy()
        form['next'] = '.'
        request.GET = form
        return edit_annotation(request, annot_id)  # djangosherd.views
    except SherdNote.DoesNotExist:
        return HttpResponseForbidden("forbidden")