forked from kompetenzinventar/ki-backend
Rewrite sqlachemy code for 1.4 to 2.x migration
This commit is contained in:
parent
ecfa344904
commit
2c781dec6c
2
app.py
2
app.py
@ -38,7 +38,7 @@ app.config["KI_LDAP_AUTH_PASSWORD"] = os.getenv("KI_LDAP_AUTH_PASSWORD")
|
|||||||
app.config["KI_LDAP_BASE_DN"] = os.getenv("KI_LDAP_BASE_DN")
|
app.config["KI_LDAP_BASE_DN"] = os.getenv("KI_LDAP_BASE_DN")
|
||||||
|
|
||||||
CORS(app)
|
CORS(app)
|
||||||
db = SQLAlchemy(app)
|
db = SQLAlchemy(app, session_options={"future": True})
|
||||||
migrate = Migrate(app, db, compare_type=True)
|
migrate = Migrate(app, db, compare_type=True)
|
||||||
|
|
||||||
app.logger.info("Hello from KI")
|
app.logger.info("Hello from KI")
|
||||||
|
@ -19,7 +19,7 @@ def seed_contacttypes():
|
|||||||
|
|
||||||
for contacttype in csv_reader:
|
for contacttype in csv_reader:
|
||||||
id = int(contacttype["id"])
|
id = int(contacttype["id"])
|
||||||
db_contacttype = ContactType.query.get(id)
|
db_contacttype = db.session.get(ContactType, id)
|
||||||
|
|
||||||
if db_contacttype is None:
|
if db_contacttype is None:
|
||||||
db.session.add(ContactType(id=int(contacttype["id"]), name=contacttype["name"]))
|
db.session.add(ContactType(id=int(contacttype["id"]), name=contacttype["name"]))
|
||||||
@ -99,7 +99,7 @@ def seed(dev: bool):
|
|||||||
|
|
||||||
for skill in skills_csv_reader:
|
for skill in skills_csv_reader:
|
||||||
id = int(skill["id"])
|
id = int(skill["id"])
|
||||||
db_skill = Skill.query.get(id)
|
db_skill = db.session.get(Skill, id)
|
||||||
|
|
||||||
if db_skill is None:
|
if db_skill is None:
|
||||||
db.session.add(Skill(id=int(skill["id"]), name=skill["name"]))
|
db.session.add(Skill(id=int(skill["id"]), name=skill["name"]))
|
||||||
@ -113,7 +113,7 @@ def seed(dev: bool):
|
|||||||
|
|
||||||
for iso in iso_csv_reader:
|
for iso in iso_csv_reader:
|
||||||
id = iso["639-1"]
|
id = iso["639-1"]
|
||||||
db_language = Language.query.get(id)
|
db_language = db.session.get(Language, id)
|
||||||
|
|
||||||
if db_language is None:
|
if db_language is None:
|
||||||
db.session.add(Language(id=iso["639-1"], name=iso["Sprache"]))
|
db.session.add(Language(id=iso["639-1"], name=iso["Sprache"]))
|
||||||
|
@ -33,7 +33,7 @@ def update_languages(profile, languages_data):
|
|||||||
if "id" not in language_data["language"]:
|
if "id" not in language_data["language"]:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
language = Language.query.get(language_data["language"]["id"])
|
language = db.session.get(Language, language_data["language"]["id"])
|
||||||
profile_language = ProfileLanguage.query.filter(ProfileLanguage.profile == profile,
|
profile_language = ProfileLanguage.query.filter(ProfileLanguage.profile == profile,
|
||||||
ProfileLanguage.language == language).first()
|
ProfileLanguage.language == language).first()
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ def update_contacts(profile, contacts_data):
|
|||||||
if "id" in contact_data:
|
if "id" in contact_data:
|
||||||
contact_id = int(contact_data["id"])
|
contact_id = int(contact_data["id"])
|
||||||
contact_ids_to_be_deleted.remove(contact_id)
|
contact_ids_to_be_deleted.remove(contact_id)
|
||||||
contact = Contact.query.get(contact_id)
|
contact = db.session.get(Contact, contact_id)
|
||||||
else:
|
else:
|
||||||
contact = Contact(profile=profile, contacttype=contacttype)
|
contact = Contact(profile=profile, contacttype=contacttype)
|
||||||
db.session.add(contact)
|
db.session.add(contact)
|
||||||
@ -122,7 +122,7 @@ def update_contacts(profile, contacts_data):
|
|||||||
|
|
||||||
|
|
||||||
def update_profile(user_id: int):
|
def update_profile(user_id: int):
|
||||||
user = User.query.get(user_id)
|
user = db.session.get(User, user_id)
|
||||||
|
|
||||||
if user is None:
|
if user is None:
|
||||||
return make_response({}, 404)
|
return make_response({}, 404)
|
||||||
|
@ -10,13 +10,14 @@ from ki.auth import auth
|
|||||||
from ki.handlers import find_profiles as find_profiles_handler
|
from ki.handlers import find_profiles as find_profiles_handler
|
||||||
from ki.handlers import update_profile as update_profile_handler
|
from ki.handlers import update_profile as update_profile_handler
|
||||||
from ki.models import ContactType, Language, Skill, Token, User
|
from ki.models import ContactType, Language, Skill, Token, User
|
||||||
from app import app
|
from app import app, db
|
||||||
|
|
||||||
content_type_svg = "image/svg+xml"
|
content_type_svg = "image/svg+xml"
|
||||||
content_type_png = "image/png"
|
content_type_png = "image/png"
|
||||||
|
|
||||||
|
|
||||||
def token_auth(func):
|
def token_auth(func):
|
||||||
|
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
def _token_auth(*args, **kwargs):
|
def _token_auth(*args, **kwargs):
|
||||||
auth_header = request.headers.get("Authorization")
|
auth_header = request.headers.get("Authorization")
|
||||||
@ -65,7 +66,7 @@ def handle_completion_request(model, key):
|
|||||||
|
|
||||||
|
|
||||||
def handle_icon_request(model, id, path):
|
def handle_icon_request(model, id, path):
|
||||||
object = model.query.get(id)
|
object = db.session.get(model, id)
|
||||||
|
|
||||||
if object is None:
|
if object is None:
|
||||||
return make_response({}, 404)
|
return make_response({}, 404)
|
||||||
|
Loading…
Reference in New Issue
Block a user