def recompute_for_topics_and_languages():
    from zeeguu.core.model import Topic, Language

    for each in Topic.get_all_topics():
        each.all_articles()

    for each in Language.available_languages():
        each.get_articles()
def system_languages():
    result = dict()
    result["learnable_languages"] = list(
        map((lambda x: dict(name=x.name, code=x.code)),
            Language.available_languages()))
    result["native_languages"] = list(
        map((lambda x: dict(name=x.name, code=x.code)),
            Language.native_languages()))
    return result
def available_languages():
    """
    :return: jason with language codes for the
    supported languages.
    e.g. ["en", "fr", "de", "it", "no", "ro"]
    """
    available_language_codes = list(
        map((lambda x: x.code), Language.available_languages()))
    return json.dumps(available_language_codes)
Exemplo n.º 4
0
def create_own_cohort():
    """
    Creates a cohort in the database.
    Requires form input (inv_code, name, language_id, max_students, teacher_id)

    """
    def _link_teacher_cohort(user_id, cohort_id):
        """
        Takes user_id and cohort_id and links them together in teacher_cohort_map table.
        """
        from zeeguu.core.model import TeacherCohortMap

        user = User.find_by_id(user_id)
        cohort = Cohort.find(cohort_id)
        db.session.add(TeacherCohortMap(user, cohort))
        db.session.commit()
        return "added teacher_cohort relationship"

    params = request.form
    inv_code = params.get("inv_code")
    name = params.get("name")

    # language_id is deprecated and kept here for backwards compatibility
    # use language_code instead
    language_code = params.get("language_code") or params.get("language_id")
    if name is None or inv_code is None or language_code is None:
        flask.abort(400)

    available_languages = Language.available_languages()
    code_allowed = False
    for code in available_languages:
        if language_code in str(code):
            code_allowed = True

    if not code_allowed:
        flask.abort(400)
    language = Language.find_or_create(language_code)
    teacher_id = flask.g.user.id
    max_students = params.get("max_students")
    if int(max_students) < 1:
        flask.abort(400)

    try:
        c = Cohort(inv_code, name, language, max_students)
        db.session.add(c)
        db.session.commit()
        _link_teacher_cohort(teacher_id, c.id)
        return "OK"
    except ValueError:
        flask.abort(400)
        return "ValueError"
    except sqlalchemy.exc.IntegrityError:
        flask.abort(400)
        return "IntegrityError"
Exemplo n.º 5
0
def cache_articles(code):
    if code != zeeguu.core.app.config.get("PRIVATE_API_CODE"):
        return "Nope"

    from zeeguu.core.model import Topic, Language

    for each in Topic.get_all_topics():
        each.all_articles()

    for each in Language.available_languages():
        each.get_articles()

    return "OK"
Exemplo n.º 6
0
import zeeguu.core
from zeeguu.core.model import Article, Language, LocalizedTopic

session = zeeguu.core.db.session

counter = 0

languages = Language.available_languages()
languages = [Language.find('da')]

for language in languages:
    articles = Article.query.filter(Article.language == language).order_by(
        Article.id.desc()).all()

    loc_topics = LocalizedTopic.all_for_language(language)

    total_articles = len(articles)
    for article in articles:
        counter += 1
        print(f"{article.title}")
        print(f"{article.url.as_string()}")
        for loc_topic in loc_topics:
            if loc_topic.matches_article(article):
                article.add_topic(loc_topic.topic)
                print(f" #{loc_topic.topic_translated}")
        print("")
        session.add(article)

        if counter % 1000 == 0:
            percentage = (100 * counter / total_articles) / 100
            print(