Ejemplo n.º 1
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")
Ejemplo 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 = 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')
Ejemplo 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 = 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')