2021-06-26 10:51:39 +02:00
|
|
|
import csv
|
|
|
|
import logging
|
|
|
|
|
|
|
|
from app import app, db
|
|
|
|
from ki.models import Address, Contact, ContactType, Language, Skill, Profile, ProfileLanguage, ProfileSkill, User
|
|
|
|
|
|
|
|
|
|
|
|
def seed(dev: bool):
|
|
|
|
skill_seed_file_path = app.config["KI_DATA_DIR"] + "/seed_data/skills.csv"
|
|
|
|
|
|
|
|
logging.info("importing skills")
|
|
|
|
|
|
|
|
with open(skill_seed_file_path) as skills_file:
|
|
|
|
skills_csv_reader = csv.DictReader(skills_file)
|
|
|
|
|
|
|
|
for skill in skills_csv_reader:
|
|
|
|
id = int(skill["id"])
|
|
|
|
db_skill = Skill.query.get(id)
|
|
|
|
|
|
|
|
if db_skill is None:
|
|
|
|
db.session.add(Skill(id=int(skill["id"]), name=skill["name"]))
|
|
|
|
|
|
|
|
logging.info("importing languages")
|
|
|
|
|
|
|
|
iso_seed_file_path = app.config["KI_DATA_DIR"] + "/seed_data/iso_639_1.csv"
|
|
|
|
|
|
|
|
with open(iso_seed_file_path) as iso_file:
|
|
|
|
iso_csv_reader = csv.DictReader(iso_file)
|
|
|
|
|
|
|
|
for iso in iso_csv_reader:
|
|
|
|
id = iso["639-1"]
|
|
|
|
db_language = Language.query.get(id)
|
|
|
|
|
|
|
|
if db_language is None:
|
|
|
|
db.session.add(Language(id=iso["639-1"], name=iso["Sprache"]))
|
|
|
|
|
|
|
|
if dev:
|
|
|
|
logging.info("seeding peter :)")
|
|
|
|
|
|
|
|
peter = User(auth_id="peter")
|
|
|
|
db.session.add(peter)
|
|
|
|
|
|
|
|
peters_profile = Profile(nickname="peternichtlustig",
|
|
|
|
pronouns="Herr Dr. Dr.",
|
|
|
|
volunteerwork="Gartenverein",
|
|
|
|
freetext="Ich mag Kaffee",
|
|
|
|
user=peter)
|
|
|
|
db.session.add(peters_profile)
|
|
|
|
|
|
|
|
matrix_type = ContactType(name="Matrix")
|
|
|
|
db.session.add(matrix_type)
|
|
|
|
|
2021-06-27 13:38:16 +02:00
|
|
|
matrix_contact = Contact(profile=peters_profile, contacttype=matrix_type, content="@peter:wtf-eg.de")
|
2021-06-26 10:51:39 +02:00
|
|
|
db.session.add(matrix_contact)
|
|
|
|
|
2021-06-27 13:07:54 +02:00
|
|
|
email_type = ContactType(name="E-Mail")
|
|
|
|
db.session.add(email_type)
|
|
|
|
|
2021-06-27 13:38:16 +02:00
|
|
|
email_contact = Contact(profile=peters_profile, contacttype=email_type, content="peter@wtf-eg.de")
|
2021-06-27 13:07:54 +02:00
|
|
|
db.session.add(email_contact)
|
|
|
|
|
2021-06-26 10:51:39 +02:00
|
|
|
peters_address = Address(name="Peter Nichtlustig",
|
|
|
|
street="Waldweg",
|
|
|
|
house_number="23i",
|
|
|
|
additional="Hinterhaus",
|
|
|
|
postcode="13337",
|
|
|
|
city="Bielefeld",
|
|
|
|
country="Deutschland",
|
|
|
|
profile=peters_profile)
|
|
|
|
db.session.add(peters_address)
|
|
|
|
|
2021-06-27 13:38:16 +02:00
|
|
|
peters_python_skill = ProfileSkill(profile=peters_profile, skill_id=3, level=3)
|
2021-06-26 10:51:39 +02:00
|
|
|
db.session.add(peters_python_skill)
|
|
|
|
|
2021-06-27 13:38:16 +02:00
|
|
|
peters_php_skill = ProfileSkill(profile=peters_profile, skill_id=1, level=5)
|
|
|
|
db.session.add(peters_php_skill)
|
|
|
|
|
|
|
|
peter_de = ProfileLanguage(profile=peters_profile, language_id="de", level=5)
|
2021-06-26 10:51:39 +02:00
|
|
|
db.session.add(peter_de)
|
|
|
|
|
2021-06-27 13:38:16 +02:00
|
|
|
peter_fr = ProfileLanguage(profile=peters_profile, language_id="fr", level=3)
|
2021-06-26 10:51:39 +02:00
|
|
|
db.session.add(peter_fr)
|
|
|
|
|
|
|
|
db.session.commit()
|