Compare commits

..

No commits in common. "733499303f44fbfb3940f71d54554263aa45c30f" and "f0d05bbf227da582678a04fe540c0d2fd0b6a8fd" have entirely different histories.

5 changed files with 8 additions and 50 deletions

2
app.py
View File

@ -38,7 +38,7 @@ app.config["KI_LDAP_BASE_DN"] = os.getenv("KI_LDAP_BASE_DN")
CORS(app) CORS(app)
db = SQLAlchemy(app) db = SQLAlchemy(app)
migrate = Migrate(app, db, compare_type=True) migrate = Migrate(app, db)
logging.debug("Hello from KI") logging.debug("Hello from KI")

View File

@ -30,25 +30,19 @@ def update_languages(profile, languages_data):
profile_language_ids = [] profile_language_ids = []
for language_data in languages_data: for language_data in languages_data:
if "id" in language_data["language"]: language_id = language_data["language"]["id"]
language = Language.query.get(language_data["language"]["id"]) language = Language.query.get(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, profile_language = ProfileLanguage.query.filter(ProfileLanguage.profile == profile,
ProfileLanguage.language == language).first() ProfileLanguage.language_id == language_id).first()
if profile_language is None: if profile_language is None:
profile_language = ProfileLanguage(profile=profile, language=language) profile_language = ProfileLanguage(profile=profile, language=language)
db.session.add(profile_language) db.session.add(profile_language)
profile_language.level = language_data["level"] profile_language.level = language_data["level"]
profile_language_ids.append(language.id)
profile_language_ids.append(language_id)
ProfileLanguage.query.filter(ProfileLanguage.profile == profile, ProfileLanguage.query.filter(ProfileLanguage.profile == profile,
not_(ProfileLanguage.language_id.in_(profile_language_ids))).delete() not_(ProfileLanguage.language_id.in_(profile_language_ids))).delete()
@ -139,21 +133,11 @@ def update_profile(user_id: int):
profile = Profile(user=user, nickname=user.auth_id) profile = Profile(user=user, nickname=user.auth_id)
db.session.add(profile) db.session.add(profile)
profile.nickname = request.json.get("nickname", "")
profile.pronouns = request.json.get("pronouns", "") profile.pronouns = request.json.get("pronouns", "")
profile.volunteerwork = request.json.get("volunteerwork", "") profile.volunteerwork = request.json.get("volunteerwork", "")
profile.availability_status = request.json.get("availability_status", False) profile.availability_status = request.json.get("availability_status", False)
profile.availability_text = request.json.get("availability_text", "") profile.availability_text = request.json.get("availability_text", "")
profile.availability_hours_per_week = request.json.get("availability_hours_per_week", 0)
availability_hours_per_week_raw = request.json.get("availability_hours_per_week", 0)
try:
availability_hours_per_week = int(availability_hours_per_week_raw)
except:
availability_hours_per_week = 0
profile.availability_hours_per_week = availability_hours_per_week
profile.freetext = request.json.get("freetext", "") profile.freetext = request.json.get("freetext", "")
profile.visible = request.json.get("visible", False) profile.visible = request.json.get("visible", False)

View File

@ -149,7 +149,7 @@ class Skill(db.Model):
__tablename__ = "skill" __tablename__ = "skill"
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True)
name = Column(String(50), unique=True, nullable=False) name = Column(String(25), unique=True, nullable=False)
profiles = relationship("ProfileSkill", back_populates="skill") profiles = relationship("ProfileSkill", back_populates="skill")
searchtopics = relationship("ProfileSearchtopic", back_populates="skill") searchtopics = relationship("ProfileSearchtopic", back_populates="skill")

View File

@ -31,7 +31,6 @@ class TestProfileEndpoint(ApiTest):
token = self.login("peter", "geheim")["token"] token = self.login("peter", "geheim")["token"]
data = { data = {
"nickname": "Hebbert",
"pronouns": "Monsieur", "pronouns": "Monsieur",
"volunteerwork": "ja", "volunteerwork": "ja",
"availability_status": False, "availability_status": False,
@ -111,7 +110,6 @@ class TestProfileEndpoint(ApiTest):
with app.app_context(): with app.app_context():
user = User.query.filter(User.id == 1).first() user = User.query.filter(User.id == 1).first()
profile = user.profile profile = user.profile
self.assertEqual("Hebbert", profile.nickname)
self.assertEqual("Monsieur", profile.pronouns) self.assertEqual("Monsieur", profile.pronouns)
self.assertEqual("ja", profile.volunteerwork) self.assertEqual("ja", profile.volunteerwork)
self.assertEqual(False, profile.availability_status) self.assertEqual(False, profile.availability_status)

View File

@ -1,24 +0,0 @@
"""extend skill length to 50 chars
Revision ID: b5023977cbda
Revises: 459520b01f34
Create Date: 2021-11-22 20:07:19.188217
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'b5023977cbda'
down_revision = '459520b01f34'
branch_labels = None
depends_on = None
def upgrade():
with op.batch_alter_table("skill") as batch_op:
batch_op.alter_column('name',
existing_type=sa.VARCHAR(length=25),
type_=sa.String(length=50),
existing_nullable=False)