Esempio n. 1
0
def upload_doc_api(request):
    user = request.user if request.user.is_authenticated else None
    if user is None:
        return HttpResponse(_('You must be logged to upload files.\n'), status=401)
    elif request.method != 'POST':
        return HttpResponse(_('Only POST requests are allowed.\n'), status=400)
    form = UploadApiForm(request.GET)
    if not form.is_valid():
        return HttpResponse(_('You must supply filename, name and keywords in your query.\n'), status=400)
    tmp_file = tempfile.NamedTemporaryFile(mode='wb', dir=settings.FILE_UPLOAD_TEMP_DIR, delete=False)
    c = False
    chunk = request.read(32768)
    while chunk:
        tmp_file.write(chunk)
        c = True
        chunk = request.read(32768)
    tmp_file.flush()
    if not c:
        os.remove(tmp_file.name)
        return HttpResponse(_('Empty file. You must POST a valid file.\n'), status=400)
    # ok, we have the tmp file

    existing_objs = list(UploadDoc.query(request).filter(name=form.cleaned_data['name'])[0:1])
    if existing_objs:
        doc = existing_objs[0]
        doc.keywords.clear()
    else:
        doc = UploadDoc(uid=str(uuid.uuid1()), name=form.cleaned_data['name'], user=user)
        doc.save()
    for keyword in strip_split(form.cleaned_data['keywords'].lower()):
        doc.keywords.add(Keyword.get(keyword))
    scall(request, 'updoc.process_file', to=[SERVER], doc_id=doc.id, filename=tmp_file.name,
          original_filename=os.path.basename(form.cleaned_data['filename']))
    return HttpResponse(_('File successfully uploaded. It will be uncompressed and indexed.\n'), status=200)
Esempio n. 2
0
def es_excluded_dir():
    return set(strip_split(settings.ES_EXCLUDED_DIR))
Esempio n. 3
0
def es_plain_extensions():
    return set(strip_split(settings.ES_PLAIN_EXTENSIONS))
Esempio n. 4
0
def es_tika_extensions():
    return set(strip_split(settings.ES_TIKA_EXTENSIONS))
Esempio n. 5
0
def es_hosts():
    return strip_split(settings.ES_HOSTS)