def get_reading_languages(): """ A user might be subscribed to multiple languages at once. This endpoint returns them as a list. :return: a json list with languages for which the user is registered; every language in this list is a dictionary with the following info: id = unique id of the language; language = <unicode string> """ all_user_languages = [] reading_languages = Language.all_reading_for_user(flask.g.user) for lan in reading_languages: all_user_languages.append(lan.as_dictionary()) return json_result(all_user_languages)
def get_interesting_reading_languages(): """ 'Interesting languages' are defined as languages the user isn't subscribed to already and thus might subscribe to. :return: a json list with languages the user isn't reading yet. every language in this list is a dictionary with the following info: id = unique id of the language; language = <unicode string> """ all_languages = Language.available_languages() all_languages.sort(key=lambda x: x.name) learned_languages = Language.all_reading_for_user(flask.g.user) interesting_languages = [] for lan in all_languages: if lan not in learned_languages: interesting_languages.append(lan.as_dictionary()) return json_result(interesting_languages)