Skip to content

Commit

Permalink
fix add edit round and update test data
Browse files Browse the repository at this point in the history
  • Loading branch information
NarenderRajuB committed Oct 8, 2024
1 parent 17f6c19 commit 9fdd317
Show file tree
Hide file tree
Showing 14 changed files with 255 additions and 77 deletions.
4 changes: 3 additions & 1 deletion app/blueprints/fund_builder/forms/round.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,7 @@ class RoundForm(FlaskForm):
mark_as_complete_enabled = RadioField(choices=[("true", "Yes"), ("false", "No")], default="false")
is_expression_of_interest = RadioField(choices=[("true", "Yes"), ("false", "No")], default="false")
feedback_survey_config = TextAreaField("Feedback Survey")
eligibility_config = TextAreaField("Eligibility config")
eligibility_config = RadioField(
"Has eligibility config", choices=[("true", "Yes"), ("false", "No")], default="false"
)
eoi_decision_schema = TextAreaField("EOI Decision schema")
39 changes: 29 additions & 10 deletions app/blueprints/fund_builder/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,12 @@ def populate_form_with_round_data(round):
"mark_as_complete_enabled": "true" if round.mark_as_complete_enabled else "false",
"is_expression_of_interest": "true" if round.is_expression_of_interest else "false",
"feedback_survey_config": round.feedback_survey_config,
"eligibility_config": round.eligibility_config.get("has_eligibility", "false"),
"eoi_decision_schema": round.eoi_decision_schema.get("en", ""),
"eligibility_config": (
"true"
if round.eligibility_config and round.eligibility_config.get("has_eligibility", "") == "true"
else "false"
),
"eoi_decision_schema": round.eoi_decision_schema.get("en", "") if round.eoi_decision_schema else "",
}
return RoundForm(data=round_data)

Expand All @@ -337,14 +341,8 @@ def update_existing_round(round, form):
:param Round round: The round object to update
:param RoundForm form: The form with the new round data
"""
round.title_json["en"] = form.title_en.data
round.title_json = {"en": form.title_en.data if form.title_en.data else ""}
round.short_name = form.short_name.data
round.contact_us_banner_json["en"] = form.contact_us_banner_json.data
round.instructions_json["en"] = form.instructions_json.data
round.application_guidance_json["en"] = form.application_guidance_json.data
round.feedback_survey_config = form.feedback_survey_config.data
round.eligibility_config["has_eligibility"] = form.eligibility_config.data
round.eoi_decision_schema["en"] = form.eoi_decision_schema.data
round.opens = get_datetime(form.opens)
round.deadline = get_datetime(form.deadline)
round.assessment_start = get_datetime(form.assessment_start)
Expand All @@ -366,6 +364,27 @@ def update_existing_round(round, form):
round.display_logo_on_pdf_exports = form.display_logo_on_pdf_exports.data == "true"
round.mark_as_complete_enabled = form.mark_as_complete_enabled.data == "true"
round.is_expression_of_interest = form.is_expression_of_interest.data == "true"
round.short_name = form.short_name.data
round.contact_us_banner_json = {
"en": form.contact_us_banner_json.data if form.contact_us_banner_json.data else "",
"cy": "",
}
round.instructions_json = {"en": form.instructions_json.data if form.instructions_json.data else "", "cy": ""}
round.application_guidance_json = {
"en": form.application_guidance_json.data if form.application_guidance_json.data else "",
"cy": "",
}
round.guidance_url = form.guidance_url.data
round.all_uploaded_documents_section_available = form.all_uploaded_documents_section_available.data == "true"
round.application_fields_download_available = form.application_fields_download_available.data == "true"
round.display_logo_on_pdf_exports = form.display_logo_on_pdf_exports.data == "true"
round.mark_as_complete_enabled = form.mark_as_complete_enabled.data == "true"
round.is_expression_of_interest = form.is_expression_of_interest.data == "true"
round.feedback_survey_config = (
json.loads(form.feedback_survey_config.data) if form.feedback_survey_config.data else {}
)
round.eligibility_config = {"has_eligibility": form.eligibility_config.data == "true"}
round.eoi_decision_schema = {"en": form.eoi_decision_schema.data, "cy": ""}
round.audit_info = {"user": "dummy_user", "timestamp": datetime.now().isoformat(), "action": "update"}
update_round(round)

Expand Down Expand Up @@ -406,7 +425,7 @@ def create_new_round(form):
mark_as_complete_enabled=form.mark_as_complete_enabled.data == "true",
is_expression_of_interest=form.is_expression_of_interest.data == "true",
feedback_survey_config=form.feedback_survey_config.data,
eligibility_config={"has_eligibility": form.eligibility_config.data},
eligibility_config={"has_eligibility": form.eligibility_config.data == "true"},
eoi_decision_schema={"en": form.eoi_decision_schema.data, "cy": None},
)
add_round(new_round)
Expand Down
10 changes: 5 additions & 5 deletions app/blueprints/fund_builder/templates/fund_config.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ <h2 class="govuk-heading-m">Application Rounds</h2>
"text": "Contact us banner json"
},
"value": {
"text": round.contact_us_banner_json
"text": round.contact_us_banner_json["en"]
},
},
{
Expand Down Expand Up @@ -213,7 +213,7 @@ <h2 class="govuk-heading-m">Application Rounds</h2>
"text": "Instructions json"
},
"value": {
"text": round.instructions_json
"text": round.instructions_json["en"]
},
},
{
Expand All @@ -237,7 +237,7 @@ <h2 class="govuk-heading-m">Application Rounds</h2>
"text": "Application Guidance json"
},
"value": {
"text": round.application_guidance_json
"text": round.application_guidance_json["en"]
},
},
{
Expand Down Expand Up @@ -293,15 +293,15 @@ <h2 class="govuk-heading-m">Application Rounds</h2>
"text": "Eligibility config"
},
"value": {
"text": round.eligibility_config
"text": True if round.eligibility_config["has_eligibility"] == "true" else False
},
},
{
"key": {
"text": "EOI decision schema"
},
"value": {
"text": round.eoi_decision_schema
"text": round.eoi_decision_schema["en"]
},
},

Expand Down
2 changes: 1 addition & 1 deletion app/blueprints/fund_builder/templates/round.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ <h1 class="govuk-heading-l">{{ pageHeading }}</h1>
{{ yes_no(form.mark_as_complete_enabled) }}
{{ yes_no(form.is_expression_of_interest) }}
{{ multilineinput(form.feedback_survey_config) }}
{{ multilineinput(form.eligibility_config) }}
{{ yes_no(form.eligibility_config) }}
{{ multilineinput(form.eoi_decision_schema) }}
{{ govukButton({
"text": "Save"
Expand Down
110 changes: 110 additions & 0 deletions app/db/migrations/versions/~2024_10_08_1656-8d6f8ec14e53_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
"""empty message
Revision ID: 8d6f8ec14e53
Revises: 5e2362840f43
Create Date: 2024-10-08 16:56:32.064596
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '8d6f8ec14e53'
down_revision = '5e2362840f43'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('round', schema=None) as batch_op:
batch_op.alter_column('application_reminder_sent',
existing_type=sa.BOOLEAN(),
server_default=None,
existing_nullable=False)
batch_op.alter_column('reference_contact_page_over_email',
existing_type=sa.BOOLEAN(),
server_default=None,
existing_nullable=False)
batch_op.alter_column('support_times',
existing_type=sa.VARCHAR(),
server_default=None,
existing_nullable=False)
batch_op.alter_column('support_days',
existing_type=sa.VARCHAR(),
server_default=None,
existing_nullable=False)
batch_op.alter_column('project_name_field_id',
existing_type=sa.VARCHAR(),
server_default=None,
existing_nullable=False)
batch_op.alter_column('all_uploaded_documents_section_available',
existing_type=sa.BOOLEAN(),
server_default=None,
existing_nullable=False)
batch_op.alter_column('application_fields_download_available',
existing_type=sa.BOOLEAN(),
server_default=None,
existing_nullable=False)
batch_op.alter_column('display_logo_on_pdf_exports',
existing_type=sa.BOOLEAN(),
server_default=None,
existing_nullable=False)
batch_op.alter_column('mark_as_complete_enabled',
existing_type=sa.BOOLEAN(),
server_default=None,
existing_nullable=False)
batch_op.alter_column('is_expression_of_interest',
existing_type=sa.BOOLEAN(),
server_default=None,
existing_nullable=False)

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('round', schema=None) as batch_op:
batch_op.alter_column('is_expression_of_interest',
existing_type=sa.BOOLEAN(),
server_default=sa.text('false'),
existing_nullable=False)
batch_op.alter_column('mark_as_complete_enabled',
existing_type=sa.BOOLEAN(),
server_default=sa.text('false'),
existing_nullable=False)
batch_op.alter_column('display_logo_on_pdf_exports',
existing_type=sa.BOOLEAN(),
server_default=sa.text('false'),
existing_nullable=False)
batch_op.alter_column('application_fields_download_available',
existing_type=sa.BOOLEAN(),
server_default=sa.text('false'),
existing_nullable=False)
batch_op.alter_column('all_uploaded_documents_section_available',
existing_type=sa.BOOLEAN(),
server_default=sa.text('false'),
existing_nullable=False)
batch_op.alter_column('project_name_field_id',
existing_type=sa.VARCHAR(),
server_default=sa.text("''::character varying"),
existing_nullable=False)
batch_op.alter_column('support_days',
existing_type=sa.VARCHAR(),
server_default=sa.text("''::character varying"),
existing_nullable=False)
batch_op.alter_column('support_times',
existing_type=sa.VARCHAR(),
server_default=sa.text("''::character varying"),
existing_nullable=False)
batch_op.alter_column('reference_contact_page_over_email',
existing_type=sa.BOOLEAN(),
server_default=sa.text('false'),
existing_nullable=False)
batch_op.alter_column('application_reminder_sent',
existing_type=sa.BOOLEAN(),
server_default=sa.text('false'),
existing_nullable=False)

# ### end Alembic commands ###
11 changes: 5 additions & 6 deletions app/db/models/round.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from sqlalchemy import inspect
from sqlalchemy.dialects.postgresql import JSON
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.ext.mutable import MutableDict
from sqlalchemy.ext.orderinglist import ordering_list
from sqlalchemy.orm import Mapped
from sqlalchemy.orm import relationship
Expand All @@ -37,7 +36,7 @@ class Round(BaseModel):
ForeignKey("fund.fund_id"),
nullable=False,
)
title_json = Column(MutableDict.as_mutable(JSON(none_as_null=True)), nullable=False, unique=False)
title_json = Column(JSON(none_as_null=True), nullable=False, unique=False)
short_name = Column(db.String(), nullable=False, unique=False)
opens = Column(DateTime())
deadline = Column(DateTime())
Expand All @@ -59,25 +58,25 @@ class Round(BaseModel):
criteria: Mapped[list["Criteria"]] = relationship("Criteria")
# several other fields to add
application_reminder_sent = Column(Boolean, default=False, nullable=False)
contact_us_banner_json = Column(MutableDict.as_mutable(JSON(none_as_null=True)), nullable=True, unique=False)
contact_us_banner_json = Column(JSON(none_as_null=True), nullable=True, unique=False)
reference_contact_page_over_email = Column(Boolean, default=False, nullable=False)
contact_email = Column(db.String(), nullable=True, unique=False)
contact_phone = Column(db.String(), nullable=True, unique=False)
contact_textphone = Column(db.String(), nullable=True, unique=False)
support_times = Column(db.String(), nullable=False, unique=False)
support_days = Column(db.String(), nullable=False, unique=False)
instructions_json = Column(MutableDict.as_mutable(JSON(none_as_null=True)), nullable=True, unique=False)
instructions_json = Column(JSON(none_as_null=True), nullable=True, unique=False)
feedback_link = Column(db.String(), unique=False)
project_name_field_id = Column(db.String(), unique=False, nullable=False)
application_guidance_json = Column(MutableDict.as_mutable(JSON(none_as_null=True)), nullable=True, unique=False)
application_guidance_json = Column(JSON(none_as_null=True), nullable=True, unique=False)
guidance_url = Column(db.String(), nullable=True, unique=False)
all_uploaded_documents_section_available = Column(Boolean, default=False, nullable=False)
application_fields_download_available = Column(Boolean, default=False, nullable=False)
display_logo_on_pdf_exports = Column(Boolean, default=False, nullable=False)
mark_as_complete_enabled = Column(Boolean, default=False, nullable=False)
is_expression_of_interest = Column(Boolean, default=False, nullable=False)
feedback_survey_config = Column(JSON(none_as_null=True), nullable=True, unique=False)
eligibility_config = Column(MutableDict.as_mutable(JSON(none_as_null=True)), nullable=True, unique=False)
eligibility_config = Column(JSON(none_as_null=True), nullable=True, unique=False)
eoi_decision_schema = Column(JSON(none_as_null=True), nullable=True, unique=False)

def __repr__(self):
Expand Down
2 changes: 1 addition & 1 deletion app/templates/macros/wtfToGovUk.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"id": form_field.id,
"name": form_field.name ,
"value": form_field.data,
"value": form_field.data if form_field.data else "",
"errorMessage": {"text": form_field.errors[0]} if (form_field.errors | length > 0) else None,
"hint":{"text":form_field.description}
}) }}
Expand Down
2 changes: 1 addition & 1 deletion config/envs/development.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ class DevelopmentConfig(Config):

SQLALCHEMY_DATABASE_URI = getenv(
"DATABASE_URL",
"postgresql://postgres:password@fab-db:5432/fab", # pragma: allowlist secret
"postgresql://postgres:password@fab-db:5435/fund_builder", # pragma: allowlist secret
)
2 changes: 1 addition & 1 deletion config/envs/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ class UnitTestConfig(Config):

SQLALCHEMY_DATABASE_URI = getenv(
"DATABASE_URL_UNIT_TEST",
"postgresql://postgres:[email protected]:5432/fab_unit_test", # pragma: allowlist secret
"postgresql://postgres:password@localhost:5435/fund_builder", # pragma: allowlist secret
)
13 changes: 7 additions & 6 deletions tasks/db_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
import sys
from os import getenv

from flask_migrate import upgrade
from invoke import task # noqa:E402
sys.path.insert(1, ".")

from app import app
from app.import_config.load_form_json import load_form_jsons
os.environ.update({"FLASK_ENV": "development"})

sys.path.insert(1, ".")
os.environ.update({"FLASK_ENV": "tasks"})
from flask_migrate import upgrade # noqa: E402
from invoke import task # noqa:E402

from app import app # noqa: E402
from app.import_config.load_form_json import load_form_jsons # noqa: E402

from .test_data import init_salmon_fishing_fund # noqa:E402
from .test_data import insert_test_data # noqa:E402
Expand Down
Loading

0 comments on commit 9fdd317

Please sign in to comment.