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')
Ejemplo n.º 4
0
        login_required(json_sublist_send), {
            'queryset': Course.objects.all,
            'fields': ['id', 'slug', 'name', 'description']
        },
        name='courses_all'),
    url(r'get/(?P<slug>[^/]+)',
        login_required(json_select_send), {
            'queryset': Course.objects.all,
            'fields': ['id', 'slug', 'name', 'description']
        },
        name='course_get'),
    url(r'^s/(?P<slug>[^/]+)',
        AR(login_required(object_detail)), {
            'queryset': Course.objects.all(),
            'template_name': 'course_show.tpl',
            'extra_context': {
                'uform': UploadFileForm(),
                'hform': UploadHttpForm(),
                'tform': NewThreadForm(),
                'doc_categories': CAT_DOCUMENTS
            }
        },
        name='course_show'),
    url(r'^view_all',
        AR(login_required(object_list)), {
            'queryset': Course.objects.exclude(slug__startswith="402"),
            'template_name': 'course_all.tpl'
        },
        name='course_view_all'),
)