Esempio n. 1
0
def edit(request, doc_id, callback=None):
    Document = get_document_model()
    DocumentMultiForm = get_document_multi_form(Document)

    doc = get_object_or_404(Document, id=doc_id)

    if not request.is_ajax():
        return HttpResponseBadRequest("Cannot POST to this view without AJAX")

    if not permission_policy.user_has_permission_for_instance(
            request.user, 'change', doc):
        raise PermissionDenied

    form = DocumentMultiForm(request.POST,
                             request.FILES,
                             instance=doc,
                             prefix='doc-' + doc_id,
                             user=request.user)

    if form.is_valid():
        form.save()

        # Reindex the doc to make sure all tags are indexed
        for backend in get_search_backends():
            backend.add(doc)

        return JsonResponse({
            'success': True,
            'doc_id': int(doc_id),
        })
    else:
        return JsonResponse({
            'success':
            False,
            'doc_id':
            int(doc_id),
            'form':
            render_to_string('tuiuiudocs/multiple/edit_form.html', {
                'doc': doc,
                'form': form,
            },
                             request=request),
        })
Esempio n. 2
0
def edit(request, image_id, callback=None):
    Image = get_image_model()
    ImageForm = get_image_edit_form(Image)

    image = get_object_or_404(Image, id=image_id)

    if not request.is_ajax():
        return HttpResponseBadRequest("Cannot POST to this view without AJAX")

    if not permission_policy.user_has_permission_for_instance(request.user, 'change', image):
        raise PermissionDenied

    form = ImageForm(
        request.POST, request.FILES, instance=image, prefix='image-' + image_id, user=request.user
    )

    if form.is_valid():
        form.save()

        # Reindex the image to make sure all tags are indexed
        for backend in get_search_backends():
            backend.add(image)

        return JsonResponse({
            'success': True,
            'image_id': int(image_id),
        })
    else:
        return JsonResponse({
            'success': False,
            'image_id': int(image_id),
            'form': render_to_string('tuiuiuimages/multiple/edit_form.html', {
                'image': image,
                'form': form,
            }, request=request),
        })
Esempio n. 3
0
    def test_get_search_backends_without_auto_update_disabled(self):
        backends = list(get_search_backends())

        self.assertEqual(len(backends), 1)
Esempio n. 4
0
    def test_get_search_backends_with_auto_update(self):
        backends = list(get_search_backends(with_auto_update=True))

        # Auto update is the default
        self.assertEqual(len(backends), 1)
Esempio n. 5
0
    def test_get_search_backends_multiple(self):
        backends = list(get_search_backends())

        self.assertEqual(len(backends), 2)
Esempio n. 6
0
    def test_get_search_backends_with_no_default_defined(self):
        backends = list(get_search_backends())

        self.assertEqual(len(backends), 1)
        self.assertIsInstance(backends[0], DatabaseSearchBackend)