Merge pull request 'availibility' (#54) from feature/53-availability into main
All checks were successful
continuous-integration/drone/push Build is passing

Reviewed-on: #54
This commit is contained in:
weeman 2021-10-12 19:04:42 +02:00
commit b63c0f3ede
7 changed files with 75 additions and 11 deletions

View File

@ -2,6 +2,7 @@
# #
# SPDX-License-Identifier: AGPL-3.0-or-later # SPDX-License-Identifier: AGPL-3.0-or-later
repos:
- repo: local - repo: local
hooks: hooks:
- id: flake8 - id: flake8

View File

@ -22,7 +22,7 @@ SPDX-License-Identifier: AGPL-3.0-or-later
Ggf. vorher aufräumen Ggf. vorher aufräumen
``` ```
rm data/ki.sqlite rm storage/ki.sqlite
``` ```
``` ```

View File

@ -26,7 +26,15 @@ def seed_contacttypes():
db.session.add(ContactType(id=int(contacttype["id"]), name=contacttype["name"])) 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="",
availability_status=False,
freetext="",
availability_text="",
availability_hours_per_week=42):
app.logger.info(f"seeding {nickname} \\o/") app.logger.info(f"seeding {nickname} \\o/")
user = User(auth_id=nickname) user = User(auth_id=nickname)
@ -35,7 +43,9 @@ def seed_user(nickname, visible=False, skills=[], languages=[], volunteerwork=""
profile = Profile(nickname=nickname, profile = Profile(nickname=nickname,
pronouns="", pronouns="",
volunteerwork=volunteerwork, volunteerwork=volunteerwork,
availability=availability, availability_status=availability_status,
availability_text=availability_text,
availability_hours_per_week=availability_hours_per_week,
freetext=freetext, freetext=freetext,
visible=visible, visible=visible,
user=user) user=user)
@ -91,7 +101,9 @@ def seed(dev: bool):
peters_profile = Profile(nickname="peternichtlustig", peters_profile = Profile(nickname="peternichtlustig",
pronouns="Herr Dr. Dr.", pronouns="Herr Dr. Dr.",
volunteerwork="Gartenverein", volunteerwork="Gartenverein",
availability="Immer", availability_status=True,
availability_hours_per_week=42,
availability_text="Immer",
freetext="Ich mag Kaffee", freetext="Ich mag Kaffee",
user=peter) user=peter)
db.session.add(peters_profile) db.session.add(peters_profile)
@ -135,7 +147,9 @@ def seed(dev: bool):
seed_user("dirtydieter", seed_user("dirtydieter",
visible=True, visible=True,
volunteerwork="Müll sammeln", volunteerwork="Müll sammeln",
availability="Nur nachts", availability_status=True,
availability_hours_per_week=24,
availability_text="Nur Nachts!",
freetext="1001010010111!!!", freetext="1001010010111!!!",
skills=[(Skill.skill_id_php, 5)]) skills=[(Skill.skill_id_php, 5)])

View File

@ -135,7 +135,9 @@ def update_profile(user_id: int):
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 = request.json.get("availability", "") 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)
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

@ -32,7 +32,11 @@ class Profile(db.Model):
pronouns = Column(String(25), default="") pronouns = Column(String(25), default="")
volunteerwork = Column(String(4000), default="") volunteerwork = Column(String(4000), default="")
freetext = Column(String(4000), default="") freetext = Column(String(4000), default="")
availability = Column(String(4000), default="")
availability_status = Column(Boolean, default=False)
availability_text = Column(String(4000), default="")
availability_hours_per_week = Column(Integer, default=0)
visible = Column(Boolean, nullable=False, default=False) visible = Column(Boolean, nullable=False, default=False)
created = Column(DateTime, nullable=False, default=datetime.now) created = Column(DateTime, nullable=False, default=datetime.now)
updated = Column(DateTime, onupdate=datetime.now, 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, "nickname": self.nickname,
"pronouns": self.pronouns, "pronouns": self.pronouns,
"volunteerwork": self.volunteerwork, "volunteerwork": self.volunteerwork,
"availability": self.availability, "availability_status": self.availability_status,
"availability_text": self.availability_text,
"availability_hours_per_week": self.availability_hours_per_week,
"freetext": self.freetext, "freetext": self.freetext,
"visible": self.visible, "visible": self.visible,
"address": self.address.to_dict() if self.address else None, "address": self.address.to_dict() if self.address else None,

View File

@ -33,7 +33,9 @@ class TestProfileEndpoint(ApiTest):
data = { data = {
"pronouns": "Monsieur", "pronouns": "Monsieur",
"volunteerwork": "ja", "volunteerwork": "ja",
"availability": "Nie", "availability_status": False,
"availability_text": "Nie",
"availability_hours_per_week": "23",
"freetext": "Hallo", "freetext": "Hallo",
"visible": True, "visible": True,
"address": { "address": {
@ -110,7 +112,9 @@ class TestProfileEndpoint(ApiTest):
profile = user.profile profile = user.profile
self.assertEqual("Monsieur", profile.pronouns) self.assertEqual("Monsieur", profile.pronouns)
self.assertEqual("ja", profile.volunteerwork) self.assertEqual("ja", profile.volunteerwork)
self.assertEqual("Nie", profile.availability) self.assertEqual(False, profile.availability_status)
self.assertEqual("Nie", profile.availability_text)
self.assertEqual(23, profile.availability_hours_per_week)
self.assertEqual("Hallo", profile.freetext) self.assertEqual("Hallo", profile.freetext)
self.assertTrue(profile.visible) self.assertTrue(profile.visible)
@ -198,7 +202,9 @@ class TestProfileEndpoint(ApiTest):
"user_id": 1, "user_id": 1,
"nickname": "peternichtlustig", "nickname": "peternichtlustig",
"pronouns": "Herr Dr. Dr.", "pronouns": "Herr Dr. Dr.",
"availability": "Immer", "availability_status": True,
"availability_hours_per_week": 42,
"availability_text": "Immer",
"freetext": "Ich mag Kaffee", "freetext": "Ich mag Kaffee",
"volunteerwork": "Gartenverein", "volunteerwork": "Gartenverein",
"visible": False, "visible": False,

View File

@ -0,0 +1,35 @@
"""empty message
Revision ID: 459520b01f34
Revises: 9183e2335b05
Create Date: 2021-10-03 14:45:30.389359
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.sql import expression
# revision identifiers, used by Alembic.
revision = '459520b01f34'
down_revision = '9183e2335b05'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("profile") as batch_op:
batch_op.alter_column('availability', new_column_name='availability_text')
batch_op.add_column(sa.Column('availability_status', sa.Boolean(), server_default=expression.true(), nullable=False))
batch_op.add_column(sa.Column('availability_hours_per_week', sa.Integer(), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("profile") as batch_op:
batch_op.alter_column('availability_text', new_column_name='availability')
batch_op.drop_column('availability_hours_per_week')
batch_op.drop_column('availability_status')
# ### end Alembic commands ###