Beispiel #1
0
def get_preview(request):
    id_ = request.matchdict['docid']
    db = get_doc_db_from_request(request)
    doc = db.find_one(id_)
    data = doc.raw_data
    if 'content_type' in doc:
        content_type = doc.get('content_type')
    else:
        content_type = 'text/html'
    if content_type.startswith('image'):
        data = get_thumbnail(data)
    response = Response(data)
    response.content_type = content_type

    return response
Beispiel #2
0
def get_preview(request):
    id_ = request.matchdict['docid']
    db = get_doc_db_from_request(request)
    doc = db.find_one(id_)
    data = doc.raw_data
    if 'content_type' in doc:
        content_type = doc.get('content_type')
    else:
        content_type = 'text/html'
    if content_type.startswith('image'):
        data = get_thumbnail(data)
    response = Response(data)
    response.content_type = content_type

    return response
Beispiel #3
0
def add(request):
    title = request.params['title']
    created = request.params.get('created', datetime.utcnow()) or \
        datetime.utcnow()
    description = request.params.get('description', '')
    force_detection = request.params.get("force_detection",
                                         'true').lower() == 'true'
    accepted_languages = request.registry.settings['accepted_languages']

    imgstream = request.params['file'].file

    doc_list = request.db.docs

    for image in get_images_from_stream(imgstream):
        try:
            lang, img, text = recognize(image, accepted_languages,
                                        force_detection)
        except TypeError, e:
            err_msg = "Error: " + str(e)
            request.session.flash(err_msg, 'failure')
            return HTTPServerError(explanation=err_msg,
                                   detail='Go back, unselect force '\
                                       'detection, and try again')
        text += " " + description + " " + title
        if text:
            search_terms = list(index(text, [lang]))
        else:
            search_terms = ''
        thumb = get_thumbnail(image)

        doc_list.insert({
            'img': Binary(image),
            'thumb': Binary(thumb),
            'created': created,
            'version': 4,
            'forced_detection': force_detection,
            'language': lang,
            'keywords': [],
            'search_terms': search_terms,
            'title': title
        })
Beispiel #4
0
def add(request):
    title = request.params['title']
    created = request.params.get('created', datetime.utcnow()) or \
        datetime.utcnow()
    description = request.params.get('description', '')
    force_detection = request.params.get("force_detection",
                                         'true').lower() == 'true'
    accepted_languages = request.registry.settings['accepted_languages']

    imgstream = request.params['file'].file

    doc_list = request.db.docs

    for image in get_images_from_stream(imgstream):
        try:
            lang, img, text = recognize(image, accepted_languages,
                                        force_detection)
        except TypeError, e:
            err_msg = "Error: " + str(e)
            request.session.flash(err_msg, 'failure')
            return HTTPServerError(explanation=err_msg,
                                   detail='Go back, unselect force '\
                                       'detection, and try again')
        text += " " + description + " " + title
        if text:
            search_terms = list(index(text, [lang]))
        else:
            search_terms = ''
        thumb = get_thumbnail(image)

        doc_list.insert({'img': Binary(image),
                         'thumb': Binary(thumb),
                         'created': created,
                         'version': 4,
                         'forced_detection': force_detection,
                         'language': lang,
                         'keywords': [],
                         'search_terms': search_terms,
                         'title': title})