def cell_lookup(value):
    """Use various lookup APIs using the provided value.

    Parameters
    ----------
    value : str
        The cell value to be provided to the different APIs.

    Returns
    -------

    """
    cleaned_value = util.clean_cell(value)
    fam_name = util.detect_name(cleaned_value)
    candidates = api.try_url(cleaned_value)
    if fam_name is not None:  # We detected a name and only use family name
        candidates += api.dbpedia_lookup(fam_name)
        candidates += api.try_url(fam_name)
    else:
        lang = util.get_language(cleaned_value)
        candidates += api.dbpedia_lookup(cleaned_value)

    if len(candidates) <= 1:
        lang = util.get_language(cleaned_value)
        candidates = api.spotlight_lookup(cleaned_value, lang=lang)

    if candidates:
        return util.string_disambiguation(cleaned_value,
                                          candidates,
                                          name=fam_name is not None)
    else:
        return None
def word_add_image(language, uid):
    add_image_form = AddImageForm(request.form, request.files)
    if add_image_form.validate_on_submit():
        # get image
        current_word = Word.query.filter_by(uid=uid).first_or_404()
        new_picture = Picture()
        new_picture.uid = str(uuid.uuid4())
        new_picture_status = util.upload_image(
            request=request,
            subfolder="pictures",
            uploaded_file_name=add_image_form.image_file.name,
            filename=new_picture.uid,
            medium="600x375",
            large="1920x1200",
        )

        if not new_picture_status:
            print add_image_form.image_file.errors.append(u"Fehler beim Bilder-Upload. Bitte versuchen Sie es erneut.")
        else:
            new_picture.author = request.form.get("author")
            new_picture.name = request.form.get("name")
            new_picture.description = request.form.get("description")
            new_picture.word_id = current_word.id

            db.session.add(new_picture)
            db.session.commit()
            flash(
                u"Bild erfolgreich hinzugefügt! Das picturespeak.org Team wird das Bild in den nächsten Tagen freischalten.",
                "success",
            )
            return redirect("/%s/word/%s" % (language, uid))
    return render_template(
        "word_add_image.html",
        add_image_form=add_image_form,
        language=util.get_language(language),
        current_path="/" + "/".join(str(request.path).split("/")[2:]),
    )
def picture_next(language, uid):
    word = Word.query.order_by(Word.uid).filter(Word.uid > uid).first()
    if not word:
        abort(404)
        # return redirect('/picture/random', code=303)
    return redirect("/%s/word/%s" % (util.get_language(language), word.uid), code=303)
def picture_random(language):
    word = Word.query.order_by(func.rand()).first()
    return redirect("/%s/word/%s" % (util.get_language(language), word.uid), code=303)
def information(language):
    return render_template(
        "information.html",
        language=util.get_language(language),
        current_path="/" + "/".join(str(request.path).split("/")[2:]),
    )
def help(language):
    return render_template(
        "help.html", language=util.get_language(language), current_path="/" + "/".join(str(request.path).split("/")[2:])
    )
Exemple #7
0
def slash(request):
    url = request.get_full_path()
    return HttpResponseRedirect(url.strip('/') + '/' + get_language(request) + '/index')