forked from kompetenzinventar/ki-backend
fix creating languages #56
This commit is contained in:
parent
111d4f08f4
commit
733499303f
@ -30,19 +30,25 @@ def update_languages(profile, languages_data):
|
||||
profile_language_ids = []
|
||||
|
||||
for language_data in languages_data:
|
||||
language_id = language_data["language"]["id"]
|
||||
language = Language.query.get(language_id)
|
||||
if "id" in language_data["language"]:
|
||||
language = Language.query.get(language_data["language"]["id"])
|
||||
else:
|
||||
language_name = language_data["language"]["name"]
|
||||
language = Language.query.filter(Language.name == language_name).first()
|
||||
|
||||
if language is None:
|
||||
language = Language(id=language_name, name=language_name)
|
||||
db.session.add(language)
|
||||
|
||||
profile_language = ProfileLanguage.query.filter(ProfileLanguage.profile == profile,
|
||||
ProfileLanguage.language_id == language_id).first()
|
||||
ProfileLanguage.language == language).first()
|
||||
|
||||
if profile_language is None:
|
||||
profile_language = ProfileLanguage(profile=profile, language=language)
|
||||
db.session.add(profile_language)
|
||||
|
||||
profile_language.level = language_data["level"]
|
||||
|
||||
profile_language_ids.append(language_id)
|
||||
profile_language_ids.append(language.id)
|
||||
|
||||
ProfileLanguage.query.filter(ProfileLanguage.profile == profile,
|
||||
not_(ProfileLanguage.language_id.in_(profile_language_ids))).delete()
|
||||
|
Loading…
Reference in New Issue
Block a user