Skip to content

Commit

Permalink
[#556] Add show_as_textarea column into question group
Browse files Browse the repository at this point in the history
  • Loading branch information
wayangalihpratama committed Dec 23, 2024
1 parent d262656 commit 8e43f36
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 0 deletions.
2 changes: 2 additions & 0 deletions backend/db/crud_question.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def add_question(
deactivate=payload["deactivate"],
autofield=payload["autofield"],
is_repeat_identifier=payload.get("is_repeat_identifier", False),
show_as_textarea=payload.get("show_as_textarea", False),
)
if payload["option"]:
for o in payload["option"]:
Expand Down Expand Up @@ -138,6 +139,7 @@ def update_question(
question.deactivate = payload["deactivate"]
question.autofield = payload["autofield"]
question.is_repeat_identifier = payload.get("is_repeat_identifier", False)
question.show_as_textarea = payload.get("show_as_textarea", False)
# Add member access
delete_member_access_by_question_id(session=session, question=[id])
if payload["member_access"]:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""alter question add show_as_textarea column
Revision ID: 1471ff286611
Revises: f1d3c82e4840
Create Date: 2024-12-23 03:33:14.500641
"""

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "1471ff286611"
down_revision = "f1d3c82e4840"
branch_labels = None
depends_on = None


def upgrade():
op.add_column(
"question",
sa.Column(
"show_as_textarea",
sa.Boolean(),
nullable=False,
server_default=sa.text("false"),
),
)


def downgrade():
op.drop_column("question", "show_as_textarea")
10 changes: 10 additions & 0 deletions backend/models/question.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class QuestionPayload(TypedDict):
skip_logic: Optional[List[SkipLogicPayload]] = None
autofield: Optional[dict] = None
is_repeat_identifier: Optional[bool] = False
show_as_textarea: Optional[bool] = False


class QuestionDict(TypedDict):
Expand All @@ -97,6 +98,7 @@ class QuestionDict(TypedDict):
order: Optional[int] = None
autofield: Optional[dict] = None
is_repeat_identifier: Optional[bool] = False
show_as_textarea: Optional[bool] = False


class Question(Base):
Expand All @@ -122,6 +124,7 @@ class Question(Base):
order = Column(Integer, nullable=True)
autofield = Column(MutableDict.as_mutable(pg.JSONB), nullable=True)
is_repeat_identifier = Column(Boolean, default=False)
show_as_textarea = Column(Boolean, default=False)
member_access = relationship(
"QuestionMemberAccess",
primaryjoin="QuestionMemberAccess.question==Question.id",
Expand Down Expand Up @@ -174,6 +177,7 @@ def __init__(
deactivate: Optional[bool],
autofield: Optional[dict],
is_repeat_identifier: Optional[bool] = False,
show_as_textarea: Optional[bool] = False,
):
self.id = id
self.form = form
Expand All @@ -195,6 +199,7 @@ def __init__(
self.deactivate = deactivate
self.autofield = autofield
self.is_repeat_identifier = is_repeat_identifier
self.show_as_textarea = show_as_textarea

def __repr__(self) -> int:
return f"<Question {self.id}>"
Expand Down Expand Up @@ -242,6 +247,7 @@ def serialize(self) -> QuestionDict:
"deactivate": self.deactivate,
"autofield": self.autofield,
"is_repeat_identifier": self.is_repeat_identifier,
"show_as_textarea": self.show_as_textarea,
}

@property
Expand Down Expand Up @@ -319,6 +325,8 @@ def serializeJson(self):
question.update(
{"lead_repeat_group": [lead.id for lead in self.leads_group]}
)
if self.type == QuestionType.input:
question.update({"show_as_textarea": self.show_as_textarea})
return question


Expand Down Expand Up @@ -348,6 +356,7 @@ class QuestionBase(BaseModel):
disableDelete: Optional[bool] = False
autofield: Optional[dict] = None
is_repeat_identifier: Optional[bool] = False
show_as_textarea: Optional[bool] = False

class Config:
orm_mode = True
Expand All @@ -374,6 +383,7 @@ class QuestionJson(BaseModel):
fn: Optional[dict] = None
lead_repeat_group: Optional[int] = None
is_repeat_identifier: Optional[bool] = False
show_as_textarea: Optional[bool] = False

class Config:
orm_mode = True
4 changes: 4 additions & 0 deletions backend/tests/test_012_question.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ async def test_add_question(
"deactivate": False,
"autofield": None,
"is_repeat_identifier": False,
"show_as_textarea": False,
}
res = await client.post(
app.url_path_for("question:create"),
Expand Down Expand Up @@ -88,6 +89,7 @@ async def test_add_question(
"disableDelete": False,
"autofield": None,
"is_repeat_identifier": False,
"show_as_textarea": False,
}

@pytest.mark.asyncio
Expand Down Expand Up @@ -129,6 +131,7 @@ async def test_update_question(
"deactivate": False,
"autofield": None,
"is_repeat_identifier": False,
"show_as_textarea": False,
}
res = await client.put(
app.url_path_for("question:put", id=1),
Expand Down Expand Up @@ -168,4 +171,5 @@ async def test_update_question(
"disableDelete": False,
"autofield": None,
"is_repeat_identifier": False,
"show_as_textarea": False,
}
2 changes: 2 additions & 0 deletions backend/tests/test_015_skip_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ async def test_add_skip_logic(
"deactivate": False,
"autofield": None,
"is_repeat_identifier": False,
"show_as_textarea": False,
}
res = await client.post(
app.url_path_for("question:create"),
Expand Down Expand Up @@ -77,6 +78,7 @@ async def test_add_skip_logic(
"disableDelete": False,
"autofield": None,
"is_repeat_identifier": False,
"show_as_textarea": False,
}
# get question
res = await client.get(app.url_path_for("question:get_by_id", id=2))
Expand Down
16 changes: 16 additions & 0 deletions backend/tests/test_020_advanced_group_and_question.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ async def test_add_question_with_option_and_access(
"deactivate": False,
"autofield": None,
"is_repeat_identifier": False,
"show_as_textarea": False,
"option": [
{
"code": None,
Expand Down Expand Up @@ -137,6 +138,7 @@ async def test_add_question_with_option_and_access(
"disableDelete": False,
"autofield": None,
"is_repeat_identifier": False,
"show_as_textarea": False,
}

@pytest.mark.asyncio
Expand Down Expand Up @@ -180,6 +182,7 @@ async def test_update_question_with_access(
"deactivate": False,
"autofield": None,
"is_repeat_identifier": False,
"show_as_textarea": False,
}
res = await client.put(
app.url_path_for("question:put", id=3),
Expand Down Expand Up @@ -240,6 +243,7 @@ async def test_update_question_with_access(
"disableDelete": False,
"autofield": None,
"is_repeat_identifier": False,
"show_as_textarea": False,
}

@pytest.mark.asyncio
Expand Down Expand Up @@ -288,6 +292,7 @@ async def test_add_question_group_with_question(
"deactivate": False,
"autofield": None,
"is_repeat_identifier": False,
"show_as_textarea": False,
},
{
"form": None,
Expand Down Expand Up @@ -318,6 +323,7 @@ async def test_add_question_group_with_question(
"deactivate": False,
"autofield": None,
"is_repeat_identifier": False,
"show_as_textarea": False,
},
{
"form": None,
Expand All @@ -343,6 +349,7 @@ async def test_add_question_group_with_question(
"deactivate": False,
"autofield": None,
"is_repeat_identifier": False,
"show_as_textarea": False,
},
{
"form": None,
Expand All @@ -368,6 +375,7 @@ async def test_add_question_group_with_question(
"deactivate": False,
"autofield": None,
"is_repeat_identifier": False,
"show_as_textarea": False,
},
{
"form": None,
Expand All @@ -393,6 +401,7 @@ async def test_add_question_group_with_question(
"deactivate": False,
"autofield": None,
"is_repeat_identifier": False,
"show_as_textarea": False,
},
{
"form": None,
Expand Down Expand Up @@ -433,6 +442,7 @@ async def test_add_question_group_with_question(
"deactivate": False,
"autofield": None,
"is_repeat_identifier": False,
"show_as_textarea": False,
},
],
}
Expand Down Expand Up @@ -482,6 +492,7 @@ async def test_add_question_group_with_question(
"disableDelete": False,
"autofield": None,
"is_repeat_identifier": False,
"show_as_textarea": False,
},
{
"cascade": None,
Expand Down Expand Up @@ -514,6 +525,7 @@ async def test_add_question_group_with_question(
"disableDelete": False,
"autofield": None,
"is_repeat_identifier": False,
"show_as_textarea": False,
},
{
"cascade": 1,
Expand Down Expand Up @@ -541,6 +553,7 @@ async def test_add_question_group_with_question(
"disableDelete": False,
"autofield": None,
"is_repeat_identifier": False,
"show_as_textarea": False,
},
{
"cascade": 2,
Expand Down Expand Up @@ -568,6 +581,7 @@ async def test_add_question_group_with_question(
"disableDelete": False,
"autofield": None,
"is_repeat_identifier": False,
"show_as_textarea": False,
},
{
"cascade": None,
Expand Down Expand Up @@ -595,6 +609,7 @@ async def test_add_question_group_with_question(
"disableDelete": False,
"autofield": None,
"is_repeat_identifier": False,
"show_as_textarea": False,
},
{
"cascade": None,
Expand Down Expand Up @@ -639,6 +654,7 @@ async def test_add_question_group_with_question(
"disableDelete": False,
"autofield": None,
"is_repeat_identifier": False,
"show_as_textarea": False,
},
],
}
2 changes: 2 additions & 0 deletions backend/tests/test_053_update_question_cascade_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ async def test_update_question(
"disableDelete": False,
"autofield": None,
"is_repeat_identifier": False,
"show_as_textarea": False,
}
res = await client.put(
app.url_path_for("question:put", id=6),
Expand Down Expand Up @@ -82,4 +83,5 @@ async def test_update_question(
"disableDelete": False,
"autofield": None,
"is_repeat_identifier": False,
"show_as_textarea": False,
}
2 changes: 2 additions & 0 deletions backend/tests/test_060_second_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ async def test_add_default_group(
"disableDelete": False,
"autofield": None,
"is_repeat_identifier": False,
"show_as_textarea": False,
}
],
}
Expand Down Expand Up @@ -162,4 +163,5 @@ async def test_add_default_question(
"disableDelete": False,
"autofield": None,
"is_repeat_identifier": False,
"show_as_textarea": False,
}
2 changes: 2 additions & 0 deletions backend/tests/test_061_third_limited_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ async def test_add_default_group(
"disableDelete": False,
"autofield": None,
"is_repeat_identifier": False,
"show_as_textarea": False,
}
],
}
Expand Down Expand Up @@ -151,6 +152,7 @@ async def test_add_default_question(
"disableDelete": False,
"autofield": None,
"is_repeat_identifier": False,
"show_as_textarea": False,
}

@pytest.mark.asyncio
Expand Down
Loading

0 comments on commit 8e43f36

Please sign in to comment.