Exemplo n.º 1
0
def upload_file(request, slug):
    form = UploadFileForm(request.POST, request.FILES)
    if form.is_valid():
        course = get_object_or_404(Course, slug=slug)
        d = Document.new(request.user, course, request.FILES['file'].name,
                         form.cleaned_data['category'])
        course.add_document(d)
        transaction.commit()
        run_process_file(d.id, request.FILES['file'])
    # FIXME add an error management
    return HttpResponseRedirect(reverse('course_show', args=[slug]))
Exemplo n.º 2
0
def upload_http(request, slug):
    form = UploadHttpForm(request.POST)
    if form.is_valid():
        course = get_object_or_404(Course, slug=slug)
        url = escape(form.cleaned_data["url"])
        name = match(r".*/([^/]+)$", url).group(1)
        if len(name) < 4:
            return HttpResponse("name invalid", "text/html")
        doc = Document.new(request.user, course, name, escape(form.cleaned_data["category"]))
        course.add_document(doc)
        PendingDocument.objects.create(doc=doc, state="queued", url=url)
        return HttpResponse("ok", "text/html")
    return HttpResponse("form invalid", "text/html")
Exemplo n.º 3
0
def upload_http(request, slug):
    form = UploadHttpForm(request.POST)
    if form.is_valid():
        course = get_object_or_404(Course, slug=slug)
        url = form.cleaned_data['url']
        name = match(r'.*/([^/]+)$', url).group(1)
        if len(name) < 4:
            return HttpResponse('name invalid', 'text/html')
        d = Document.new(request.user, course, name,
                         form.cleaned_data['category'])
        course.add_document(d)
        transaction.commit()
        run_download_file(d.id, url)
        return HttpResponse('ok', 'text/html')
    return HttpResponse('form invalid', 'text/html')
Exemplo n.º 4
0
def upload_file(request, slug):
    form = UploadFileForm(request.POST, request.FILES)

    if form.is_valid() and match(r".*\.[pP][dD][fF]$", request.FILES["file"].name):
        course = get_object_or_404(Course, slug=slug)
        doc = Document.new(
            request.user, course, escape(request.FILES["file"].name), escape(form.cleaned_data["category"])
        )
        course.add_document(doc)

        url = "/tmp/TMP402_%d.pdf" % doc.id
        tmp_doc = open(url, "w")
        tmp_doc.write(request.FILES["file"].read())
        tmp_doc.close()
        PendingDocument.objects.create(doc=doc, state="queued", url="file://" + url)
        return HttpResponseRedirect(reverse("course_show", args=[slug]))
    return HttpResponse("form invalid", "text/html")
Exemplo n.º 5
0
def upload_http(request, slug):
    form = UploadHttpForm(request.POST)
    if form.is_valid():
        course = get_object_or_404(Course, slug=slug)
        url = escape(form.cleaned_data['url'])
        name = match(r'.*/([^/]+)$', url).group(1)
        if "%" in name:
            name = unquote(name)
        if len(name) < 4:
            return HttpResponse('name invalid', 'text/html')
        doc = Document.new(request.user, course, name.replace("_", " "),
                           escape(form.cleaned_data['category']))
        course.add_document(doc)
        request.user.add_row_perm(doc, '')
        Permission.objects.create(name='document_edit', user=request.user,
                                  object_id=doc.id)
        PendingDocument.objects.create(doc=doc, state="queued", url=url)
        return HttpResponse('ok', 'text/html')
    return HttpResponse('form invalid', 'text/html')
Exemplo n.º 6
0
def upload_file(request, slug):
    form = UploadFileForm(request.POST, request.FILES)

    if form.is_valid() and match(r'.*\.[pP][dD][fF]$',
                                 request.FILES['file'].name):
        course = get_object_or_404(Course, slug=slug)
        doc = Document.new(request.user, course, escape(request.FILES['file'].name),
                           escape(form.cleaned_data['category']))
        course.add_document(doc)

        url = '/tmp/TMP402_%d.pdf' % doc.id
        tmp_doc = open(url, 'w')
        tmp_doc.write(request.FILES['file'].read())
        tmp_doc.close()
        Permission.objects.create(name='document_edit', user=request.user,
                                  object_id=doc.id)
        PendingDocument.objects.create(doc=doc, state="queued", url='file://' + url)
        return HttpResponseRedirect(reverse('course_show', args=[slug]))
    return HttpResponse('form invalid', 'text/html')