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
repos:
- repo: local
hooks:
- id: flake8

View File

@ -22,7 +22,7 @@ SPDX-License-Identifier: AGPL-3.0-or-later
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"]))
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/")
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,
availability_status=availability_status,
availability_text=availability_text,
availability_hours_per_week=availability_hours_per_week,
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",
availability_status=True,
availability_hours_per_week=42,
availability_text="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",
availability_status=True,
availability_hours_per_week=24,
availability_text="Nur Nachts!",
freetext="1001010010111!!!",
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.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.visible = request.json.get("visible", False)

View File

@ -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="")
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)
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,
"availability_status": self.availability_status,
"availability_text": self.availability_text,
"availability_hours_per_week": self.availability_hours_per_week,
"freetext": self.freetext,
"visible": self.visible,
"address": self.address.to_dict() if self.address else None,

View File

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