Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1359 Can mark questions as longform question as shop owner #1360

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""add is_longform_question to question

Revision ID: 3447b58b5c69
Revises: da154873f3ab
Create Date: 2024-06-17 21:31:27.252460

"""

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "3447b58b5c69"
down_revision = "da154873f3ab"
branch_labels = None
depends_on = None


def upgrade():

with op.batch_alter_table("question", schema=None) as batch_op:
batch_op.add_column(
sa.Column(
"is_longform_question", sa.Boolean(), nullable=True, default=False
)
)


def downgrade():
pass
9 changes: 9 additions & 0 deletions subscribie/blueprints/admin/choice_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ def add_question():
if form.validate_on_submit():
question = Question()
question.title = request.form["title"]
if request.form.get("is_longform_question"):
question.is_longform_question = True
else:
question.is_longform_question = False

database.session.add(question)
database.session.commit()
flash("Added new question")
Expand All @@ -122,6 +127,10 @@ def edit_question(id):
question = Question.query.get(id)
if request.method == "POST":
question.title = request.form["title"]
if request.form.get("is_longform_question"):
question.is_longform_question = True
else:
question.is_longform_question = False
database.session.commit()
flash("Question updated")
return render_template("admin/question/edit_question.html", question=question)
Expand Down
5 changes: 5 additions & 0 deletions subscribie/blueprints/admin/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -11601,3 +11601,8 @@ h3{
margin: .5em;
padding: 0;
}


.text-muted {
color: #717d84 !important;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ <h3>Add Question</h3>
<input class="form-control" type="title" name="title" required>
</div>
</div>

<div class="form-group row mt-4 mb-4" style="padding-left: 1.25rem;">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="is_longform_question" name="is_longform_question">
<label class="form-check-label" for="is_longform_question">
Is this a longform question?
</label>
</div>
<p class="text-muted">A long-form question shows as a large text box rather than a small box.</p>
</div>

<button type="submit" class="btn btn-primary btn-block mb-3">Save</button>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h2 class="text-center text-dark mb-3">Edit Question</h2>
<ul class="breadcrumb">
<li class="breadcrumb-item"><a href="/">Shop</a></li>
<li class="breadcrumb-item"><a href="{{ url_for('admin.dashboard') }}">Manage My Shop</a></li>
<li class="breadcrumb-item"><a href="{{ url_for('admin.list_questions') }}">Questions</a></li>
<li class="breadcrumb-item"><a href="{{ url_for('admin.list_questions') }}">Questions</a></li>
<li class="breadcrumb-item active" aria-current="page">Edit Question</li>
</ul>
</div>
Expand All @@ -19,23 +19,38 @@ <h2 class="text-center text-dark mb-3">Edit Question</h2>
<div class="container">

<h3>Edit Question</h3>
<p class="card-subtitle mb-3 text-muted">Edit the Question below.</p>

<hr>

<form action="#" method="POST">
<div class="form-group row py-md-3">
<label for="title" class="col-sm-2 col-form-label">Question:</label>
<div class="col-sm-10">
<input name="title" id="title" type="text" value="{{ question.title }}" autofocus class="form-control">
<form action="" method="POST" action="/" class="col-md-7 py-3">
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="title">Title:</label>
<div class="col-sm-9">
<input class="form-control" type="title" name="title" value="{{ question.title }}" required>
</div>
</div>

<input type="submit" value="Save" class="btn btn-primary btn-block col-md-6 my-3 mx-auto">
<div class="form-group row mt-4 mb-4" style="padding-left: 1.25rem;">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="is_longform_question" name="is_longform_question"
{% if question.is_longform_question %}
checked
{% endif %}
/>
<label class="form-check-label" for="is_longform_question">
Is this a longform question?
</label>
</div>
<p class="text-muted">A long-form question shows as a large text box rather than a small box.</p>
</div>

<button type="submit" class="btn btn-primary btn-block mb-3">Save</button>
</form>

</div><!--end container-->
</div><!--end section-->
</div> <!-- end container-->
</div> <!-- end section-->
</main>

{% endblock body %}


{% endblock %}
3 changes: 3 additions & 0 deletions subscribie/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,9 @@ class Question(database.Model):
database.DateTime, default=datetime.datetime.now(datetime.UTC)
)
options = relationship("QuestionOption", back_populates="question")
is_longform_question = database.Column(
database.Boolean(), default=False
)
title = database.Column(database.String())


Expand Down
6 changes: 5 additions & 1 deletion subscribie/themes/theme-jesmond/jesmond/set_questions.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ <h3 class="body">{{ _('The') }} <span class="body-lg">{{ plan.title }}</span> {{
{% endfor %}
</select>
{% else %}
<input class="form-control" type="text" name="question-{{ plan_question_assoc.question.id }}" placeholder="Please enter..." id="{{ plan_question_assoc.question.id }}" required>
{% if plan_question_assoc.question.is_longform_question %}
<textarea cols="30" rows="10" name="question-{{ plan_question_assoc.question.id }}" placeholder="Please enter..." id="{{ plan_question_assoc.question.id }}" required></textarea>
{% else %}
<input class="form-control" type="text" name="question-{{ plan_question_assoc.question.id }}" placeholder="Please enter..." id="{{ plan_question_assoc.question.id }}" required>
{% endif %}
{% endif %}
</div>
{% endfor %}
Expand Down
Loading