def setup_languages(check_defaults: bool = True) -> None: """ Make sure languages specified in the config YAML exist in the database """ from app.settings import settings from app.lib.database import db from app.lib.models import Language, Status with db.atomic(): for language in settings['languages'].values(): try: l = Language.create(**language) except peewee.IntegrityError: # Language already exists, skipping pass if check_defaults: try: languages = Language.select() \ .join(Status, on=Language.status) \ .where(Language.default == True, Status.title == "active") \ .get() except peewee.DoesNotExist: languages = None if languages and len(languages) > 1: db.rollback() raise RuntimeError("Found more than one default language, this is not supported")
def setup_status() -> None: """ Make sure all status are available """ from app.settings import settings from app.lib.database import db from app.lib.models import Status with db.atomic(): for status in settings['languages'].values(): try: s = Status.create(**status) except peewee.IntegrityError: # Language already exists, skipping pass