From 8772a13163248ed65d44158e5957bf4cb2f311d8 Mon Sep 17 00:00:00 2001 From: scammo Date: Mon, 4 Oct 2021 18:10:31 +0200 Subject: [PATCH] availibility --- .pre-commit-config.yaml | 1 + ki/actions/seed.py | 22 ++++++++++++++---- ki/handlers/update_profile.py | 4 +++- ki/models.py | 10 ++++++-- ki/test/test_profile_endpoint.py | 9 +++++--- migrations/versions/459520b01f34_.py | 34 ++++++++++++++++++++++++++++ migrations/versions/99f6b0756445_.py | 24 ++++++++++++++++++++ 7 files changed, 94 insertions(+), 10 deletions(-) create mode 100644 migrations/versions/459520b01f34_.py create mode 100644 migrations/versions/99f6b0756445_.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 38232bc..529438e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,6 +2,7 @@ # # SPDX-License-Identifier: AGPL-3.0-or-later +repos: - repo: local hooks: - id: flake8 diff --git a/ki/actions/seed.py b/ki/actions/seed.py index ff02112..fa3e819 100644 --- a/ki/actions/seed.py +++ b/ki/actions/seed.py @@ -26,7 +26,15 @@ def seed_contacttypes(): db.session.add(ContactType(id=int(contacttype["id"]), name=contacttype["name"])) -def seed_user(nickname, visible=False, skills=[], languages=[], volunteerwork="", availability="", freetext=""): +def seed_user(nickname, + visible=False, + skills=[], + languages=[], + volunteerwork="", + availabilityStatus=False, + freetext="", + availabilityText="", + availabilityHoursPerWeek=42): app.logger.info(f"seeding {nickname} \\o/") user = User(auth_id=nickname) @@ -35,7 +43,9 @@ def seed_user(nickname, visible=False, skills=[], languages=[], volunteerwork="" profile = Profile(nickname=nickname, pronouns="", volunteerwork=volunteerwork, - availability=availability, + availabilityStatus=availabilityStatus, + availabilityText=availabilityText, + availabilityHoursPerWeek=availabilityHoursPerWeek, freetext=freetext, visible=visible, user=user) @@ -91,7 +101,9 @@ def seed(dev: bool): peters_profile = Profile(nickname="peternichtlustig", pronouns="Herr Dr. Dr.", volunteerwork="Gartenverein", - availability="Immer", + availabilityStatus=True, + availabilityHoursPerWeek=42, + availabilityText="Immer", freetext="Ich mag Kaffee", user=peter) db.session.add(peters_profile) @@ -135,7 +147,9 @@ def seed(dev: bool): seed_user("dirtydieter", visible=True, volunteerwork="Müll sammeln", - availability="Nur nachts", + availabilityStatus=True, + availabilityHoursPerWeek=24, + availabilityText="Nur Nachts!", freetext="1001010010111!!!", skills=[(Skill.skill_id_php, 5)]) diff --git a/ki/handlers/update_profile.py b/ki/handlers/update_profile.py index ad70991..3722b94 100644 --- a/ki/handlers/update_profile.py +++ b/ki/handlers/update_profile.py @@ -135,7 +135,9 @@ def update_profile(user_id: int): profile.pronouns = request.json.get("pronouns", "") profile.volunteerwork = request.json.get("volunteerwork", "") - profile.availability = request.json.get("availability", "") + profile.availabilityStatus = request.json.get("availabilityStatus", False) + profile.availabilityText = request.json.get("availabilityText", "") + profile.availabilityHoursPerWeek = request.json.get("availabilityHoursPerWeek", 0) profile.freetext = request.json.get("freetext", "") profile.visible = request.json.get("visible", False) diff --git a/ki/models.py b/ki/models.py index af0ee5f..3206497 100644 --- a/ki/models.py +++ b/ki/models.py @@ -32,7 +32,11 @@ class Profile(db.Model): pronouns = Column(String(25), default="") volunteerwork = Column(String(4000), default="") freetext = Column(String(4000), default="") - availability = Column(String(4000), default="") + + availabilityStatus = Column(Boolean, default=False) + availabilityText = Column(String(4000), default="") + availabilityHoursPerWeek = Column(Integer, default=0) + visible = Column(Boolean, nullable=False, default=False) created = Column(DateTime, nullable=False, default=datetime.now) updated = Column(DateTime, onupdate=datetime.now, nullable=False, default=datetime.now) @@ -50,7 +54,9 @@ class Profile(db.Model): "nickname": self.nickname, "pronouns": self.pronouns, "volunteerwork": self.volunteerwork, - "availability": self.availability, + "availabilityStatus": self.availabilityStatus, + "availabilityText": self.availabilityText, + "availabilityHoursPerWeek": self.availabilityHoursPerWeek, "freetext": self.freetext, "visible": self.visible, "address": self.address.to_dict() if self.address else None, diff --git a/ki/test/test_profile_endpoint.py b/ki/test/test_profile_endpoint.py index febc6a0..698b5d3 100644 --- a/ki/test/test_profile_endpoint.py +++ b/ki/test/test_profile_endpoint.py @@ -33,7 +33,8 @@ class TestProfileEndpoint(ApiTest): data = { "pronouns": "Monsieur", "volunteerwork": "ja", - "availability": "Nie", + "availabilityStatus": False, + "availabilityText": "Nie", "freetext": "Hallo", "visible": True, "address": { @@ -110,7 +111,7 @@ class TestProfileEndpoint(ApiTest): profile = user.profile self.assertEqual("Monsieur", profile.pronouns) self.assertEqual("ja", profile.volunteerwork) - self.assertEqual("Nie", profile.availability) + self.assertEqual("Nie", profile.availabilityText) self.assertEqual("Hallo", profile.freetext) self.assertTrue(profile.visible) @@ -198,7 +199,9 @@ class TestProfileEndpoint(ApiTest): "user_id": 1, "nickname": "peternichtlustig", "pronouns": "Herr Dr. Dr.", - "availability": "Immer", + "availabilityStatus": True, + "availabilityHoursPerWeek": 25, + "availabilityText": "Immer", "freetext": "Ich mag Kaffee", "volunteerwork": "Gartenverein", "visible": False, diff --git a/migrations/versions/459520b01f34_.py b/migrations/versions/459520b01f34_.py new file mode 100644 index 0000000..bdd5e78 --- /dev/null +++ b/migrations/versions/459520b01f34_.py @@ -0,0 +1,34 @@ +"""empty message + +Revision ID: 459520b01f34 +Revises: 99f6b0756445 +Create Date: 2021-10-03 14:45:30.389359 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '459520b01f34' +down_revision = '99f6b0756445' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('profile', sa.Column('availabilityStatus', sa.Boolean(), nullable=True)) + op.add_column('profile', sa.Column('availabilityText', sa.String(length=4000), nullable=True)) + op.add_column('profile', sa.Column('availabilityHoursPerWeek', sa.Integer(), nullable=True)) + op.drop_column('profile', 'availability') + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('profile', sa.Column('availability', sa.VARCHAR(length=4000), nullable=True)) + op.drop_column('profile', 'availabilityHoursPerWeek') + op.drop_column('profile', 'availabilityText') + op.drop_column('profile', 'availabilityStatus') + # ### end Alembic commands ### diff --git a/migrations/versions/99f6b0756445_.py b/migrations/versions/99f6b0756445_.py new file mode 100644 index 0000000..8544e8f --- /dev/null +++ b/migrations/versions/99f6b0756445_.py @@ -0,0 +1,24 @@ +"""empty message + +Revision ID: 99f6b0756445 +Revises: 9183e2335b05 +Create Date: 2021-10-03 14:45:10.980556 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '99f6b0756445' +down_revision = '9183e2335b05' +branch_labels = None +depends_on = None + + +def upgrade(): + pass + + +def downgrade(): + pass