Compare commits

..

4 Commits

Author SHA1 Message Date
733499303f
fix creating languages #56
All checks were successful
continuous-integration/drone/push Build is passing
2021-11-22 21:14:08 +01:00
111d4f08f4
cast hours to int #56 2021-11-22 20:27:33 +01:00
1287893698
fix updating nickname #57 2021-11-22 20:20:53 +01:00
9dc9761a1a
extend skill name to 50 chars #58 2021-11-22 20:20:42 +01:00
5 changed files with 50 additions and 8 deletions

2
app.py
View File

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

View File

@ -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()
@ -133,11 +139,21 @@ def update_profile(user_id: int):
profile = Profile(user=user, nickname=user.auth_id)
db.session.add(profile)
profile.nickname = request.json.get("nickname", "")
profile.pronouns = request.json.get("pronouns", "")
profile.volunteerwork = request.json.get("volunteerwork", "")
profile.availability_status = request.json.get("availability_status", False)
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.visible = request.json.get("visible", False)

View File

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

View File

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

View File

@ -0,0 +1,24 @@
"""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)