Skip to content

Commit

Permalink
edited
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiny49 committed Jul 23, 2024
2 parents 8f6e781 + 6c73dd2 commit 613a081
Show file tree
Hide file tree
Showing 23 changed files with 1,020 additions and 155 deletions.
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,11 @@
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
"python.testing.pytestEnabled": true,
"editor.quickSuggestions": {
"other": true,
"comments": false,
"strings": false
},
"editor.quickSuggestionsDelay": 10,
}
2 changes: 1 addition & 1 deletion app/blueprints/fund_builder/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def view_all_questions(round_id):
section_data = []
for section in sections_in_round:
forms = [{"name": form.runner_publish_name, "form_data": build_form_json(form)} for form in section.forms]
section_data.append({"section_title": section.name_in_apply["en"], "forms": forms})
section_data.append({"section_title": section.name_in_apply_json["en"], "forms": forms})

print_data = generate_print_data_for_sections(
section_data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ <h2 class="govuk-heading-m">{{ fund.short_name }} - {{ round.short_name }}</h2>
{% for section in round.sections %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
<h3 class="govuk-heading-s">{{ section.index }}. {{ section.name_in_apply["en"] }}</h3>
<h3 class="govuk-heading-s">{{ section.index }}. {{ section.name_in_apply_json["en"] }}</h3>
{% for form in section.forms %}
<h4 class="govuk-heading-s">Form {{ form.section_index }}. {{ form.name_in_apply["en"] }}</h4>
<h4 class="govuk-heading-s">Form {{ form.section_index }}. {{ form.name_in_apply_json["en"] }}</h4>
{{ govukButton({
"text": "Preview Form",
"href": url_for("build_fund_bp.preview_form", form_id=form.form_id),
Expand All @@ -36,7 +36,7 @@ <h4 class="govuk-heading-s">Form {{ form.section_index }}. {{ form.name_in_apply
}}
{% for page in form.pages %}
<div class="section_page">
<span class="govuk-body">{{ page.form_index }}. {{ page.name_in_apply["en"] }}</span>
<span class="govuk-body">{{ page.form_index }}. {{ page.name_in_apply_json["en"] }}</span>
<ul class="govuk-list--bullet">
{% for component in page.components %}
{% set list_details %}
Expand Down
32 changes: 32 additions & 0 deletions app/db/migrations/versions/~2024_07_16_0850-eb66c0e87001_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""Adding is_template to list table
Revision ID: eb66c0e87001
Revises: 4247b8f71cff
Create Date: 2024-07-16 08:50:01.637018
"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "eb66c0e87001"
down_revision = "4247b8f71cff"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("lizt", schema=None) as batch_op:
batch_op.add_column(sa.Column("is_template", sa.Boolean(), nullable=False))

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("lizt", schema=None) as batch_op:
batch_op.drop_column("is_template")

# ### end Alembic commands ###
33 changes: 33 additions & 0 deletions app/db/migrations/versions/~2024_07_16_0921-e58b1e674060_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Add unique index on Page.display_path when is_template is true
Revision ID: e58b1e674060
Revises: eb66c0e87001
Create Date: 2024-07-16 09:21:52.877957
"""

from alembic import op

# revision identifiers, used by Alembic.
revision = "e58b1e674060"
down_revision = "eb66c0e87001"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("page", schema=None) as batch_op:
batch_op.create_index(
"ix_template_page_name", ["display_path"], unique=True, postgresql_where="Page.is_template = true"
)

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("page", schema=None) as batch_op:
batch_op.drop_index("ix_template_page_name", postgresql_where="Page.is_template = true")

# ### end Alembic commands ###
58 changes: 58 additions & 0 deletions app/db/migrations/versions/~2024_07_17_1202-5c63de4e4e49_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""Rename template name columns
Revision ID: 5c63de4e4e49
Revises: e58b1e674060
Create Date: 2024-07-17 12:02:11.799787
"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "5c63de4e4e49"
down_revision = "e58b1e674060"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("component", schema=None) as batch_op:
batch_op.add_column(sa.Column("template_name", sa.String(), nullable=True))
batch_op.drop_column("Template Name")

with op.batch_alter_table("form", schema=None) as batch_op:
batch_op.add_column(sa.Column("template_name", sa.String(), nullable=True))
batch_op.drop_column("Template Name")

with op.batch_alter_table("page", schema=None) as batch_op:
batch_op.add_column(sa.Column("template_name", sa.String(), nullable=True))
batch_op.drop_column("Template Name")

with op.batch_alter_table("section", schema=None) as batch_op:
batch_op.add_column(sa.Column("template_name", sa.String(), nullable=True))
batch_op.drop_column("Template Name")

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("section", schema=None) as batch_op:
batch_op.add_column(sa.Column("Template Name", sa.VARCHAR(), autoincrement=False, nullable=True))
batch_op.drop_column("template_name")

with op.batch_alter_table("page", schema=None) as batch_op:
batch_op.add_column(sa.Column("Template Name", sa.VARCHAR(), autoincrement=False, nullable=True))
batch_op.drop_column("template_name")

with op.batch_alter_table("form", schema=None) as batch_op:
batch_op.add_column(sa.Column("Template Name", sa.VARCHAR(), autoincrement=False, nullable=True))
batch_op.drop_column("template_name")

with op.batch_alter_table("component", schema=None) as batch_op:
batch_op.add_column(sa.Column("Template Name", sa.VARCHAR(), autoincrement=False, nullable=True))
batch_op.drop_column("template_name")

# ### end Alembic commands ###
69 changes: 43 additions & 26 deletions app/db/models/application_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
from flask_sqlalchemy.model import DefaultMeta
from sqlalchemy import Column
from sqlalchemy import ForeignKey
from sqlalchemy import Index
from sqlalchemy import Integer
from sqlalchemy import String
from sqlalchemy import inspect
from sqlalchemy.dialects.postgresql import ENUM
from sqlalchemy.dialects.postgresql import JSON
from sqlalchemy.dialects.postgresql import UUID
Expand Down Expand Up @@ -38,47 +40,49 @@ class ComponentType(Enum):
class Section(BaseModel):

round_id = Column(
"round_id",
UUID(as_uuid=True),
ForeignKey("round.round_id"),
nullable=True, # will be null where this is a template and not linked to a round
)
section_id = Column(
"section_id",
UUID(as_uuid=True),
primary_key=True,
default=uuid.uuid4,
)
name_in_apply = Column("name_in_apply_json", JSON(none_as_null=True), nullable=False, unique=False)
template_name = Column("Template Name", String(), nullable=True)
is_template = Column("is_template", Boolean, default=False, nullable=False)
audit_info = Column("audit_info", JSON(none_as_null=True))
name_in_apply_json = Column(JSON(none_as_null=True), nullable=False, unique=False)
template_name = Column(String(), nullable=True)
is_template = Column(Boolean, default=False, nullable=False)
audit_info = Column(JSON(none_as_null=True))
forms: Mapped[List["Form"]] = relationship(
"Form", order_by="Form.section_index", collection_class=ordering_list("section_index")
)
index = Column(Integer())
source_template_id = Column(UUID(as_uuid=True), nullable=True)

def __repr__(self):
return f"Section({self.name_in_apply_json['en']}, Forms: {self.forms})"

def as_dict(self):
return {col.name: self.__getattribute__(col.name) for col in inspect(self).mapper.columns}


@dataclass
class Form(BaseModel):

section_id = Column(
"section_id",
UUID(as_uuid=True),
ForeignKey("section.section_id"),
nullable=True, # will be null where this is a template and not linked to a section
)
form_id = Column(
"form_id",
UUID(as_uuid=True),
primary_key=True,
default=uuid.uuid4,
)
name_in_apply = Column("name_in_apply_json", JSON(none_as_null=True), nullable=False, unique=False)
template_name = Column("Template Name", String(), nullable=True)
is_template = Column("is_template", Boolean, default=False, nullable=False)
audit_info = Column("audit_info", JSON(none_as_null=True))
name_in_apply_json = Column(JSON(none_as_null=True), nullable=False, unique=False)
template_name = Column(String(), nullable=True)
is_template = Column(Boolean, default=False, nullable=False)
audit_info = Column(JSON(none_as_null=True))
section_index = Column(Integer())
pages: Mapped[List["Page"]] = relationship(
"Page", order_by="Page.form_index", collection_class=ordering_list("form_index")
Expand All @@ -87,37 +91,45 @@ class Form(BaseModel):
source_template_id = Column(UUID(as_uuid=True), nullable=True)

def __repr__(self):
return f"Form({self.runner_publish_name} - {self.name_in_apply['en']}, Pages: {self.pages})"
return f"Form({self.runner_publish_name} - {self.name_in_apply_json['en']}, Pages: {self.pages})"

def as_dict(self):
return {col.name: self.__getattribute__(col.name) for col in inspect(self).mapper.columns}


@dataclass
class Page(BaseModel):

form_id = Column(
"form_id",
UUID(as_uuid=True),
ForeignKey("form.form_id"),
nullable=True, # will be null where this is a template and not linked to a form
)
page_id = Column(
"page_id",
UUID(as_uuid=True),
primary_key=True,
default=uuid.uuid4,
)
name_in_apply = Column("name_in_apply_json", JSON(none_as_null=True), nullable=False, unique=False)
template_name = Column("Template Name", String(), nullable=True)
is_template = Column("is_template", Boolean, default=False, nullable=False)
audit_info = Column("audit_info", JSON(none_as_null=True))
name_in_apply_json = Column(JSON(none_as_null=True), nullable=False, unique=False)
template_name = Column(String(), nullable=True)
is_template = Column(Boolean, default=False, nullable=False)
audit_info = Column(JSON(none_as_null=True))
form_index = Column(Integer())
display_path = Column("display_path", String())
display_path = Column(String())
components: Mapped[List["Component"]] = relationship(
"Component", order_by="Component.page_index", collection_class=ordering_list("page_index")
)
source_template_id = Column(UUID(as_uuid=True), nullable=True)

def __repr__(self):
return f"Page(/{self.display_path} - {self.name_in_apply['en']}, Components: {self.components})"
return f"Page(/{self.display_path} - {self.name_in_apply_json['en']}, Components: {self.components})"

def as_dict(self):
return {col.name: self.__getattribute__(col.name) for col in inspect(self).mapper.columns}


# Ensure we can only have one template with a particular display_path value
Index("ix_template_page_name", Page.display_path, unique=True, postgresql_where="Page.is_template = true")


class Lizt(BaseModel):
Expand All @@ -129,19 +141,21 @@ class Lizt(BaseModel):
name = Column(String())
type = Column(String())
items = Column(JSON())
is_template = Column(Boolean, default=False, nullable=False)

def as_dict(self):
return {col.name: self.__getattribute__(col.name) for col in inspect(self).mapper.columns}


@dataclass
class Component(BaseModel):

component_id = Column(
"component_id",
UUID(as_uuid=True),
primary_key=True,
default=uuid.uuid4,
)
page_id = Column(
"page_id",
UUID(as_uuid=True),
ForeignKey("page.page_id"),
nullable=True, # will be null where this is a template and not linked to a page
Expand All @@ -156,9 +170,9 @@ class Component(BaseModel):
hint_text = Column(String(), nullable=True)
options = Column(JSON(none_as_null=False))
type = Column(ENUM(ComponentType))
template_name = Column("Template Name", String(), nullable=True)
is_template = Column("is_template", Boolean, default=False, nullable=False)
audit_info = Column("audit_info", JSON(none_as_null=True))
template_name = Column(String(), nullable=True)
is_template = Column(Boolean, default=False, nullable=False)
audit_info = Column(JSON(none_as_null=True))
page_index = Column(Integer())
theme_index = Column(Integer())
conditions = Column(JSON(none_as_null=True))
Expand All @@ -177,6 +191,9 @@ class Component(BaseModel):
def __repr__(self):
return f"Component({self.title}, {self.type.value})"

def as_dict(self):
return {col.name: self.__getattribute__(col.name) for col in inspect(self).mapper.columns}

@property
def assessment_display_type(self):
# TODO extend this to account for what's in self.options eg. if prefix==£, return 'currency'
Expand Down
4 changes: 2 additions & 2 deletions app/db/models/assessment_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

from flask_sqlalchemy.model import DefaultMeta
from sqlalchemy import Column
from sqlalchemy import Float
from sqlalchemy import ForeignKey
from sqlalchemy import Integer
from sqlalchemy import String
from sqlalchemy.dialects.postgresql import JSON
from sqlalchemy.dialects.postgresql import REAL
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import Mapped
from sqlalchemy.orm import relationship
Expand All @@ -33,7 +33,7 @@ class Criteria(BaseModel):
nullable=True,
)
name = Column(String())
weighting = Column(Float(precision=2))
weighting = Column(REAL(precision=2))
template_name = Column("Template Name", String(), nullable=True)
is_template = Column("is_template", Boolean, default=False, nullable=False)
audit_info = Column("audit_info", JSON(none_as_null=True))
Expand Down
Loading

0 comments on commit 613a081

Please sign in to comment.