Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam-W1 committed Jul 30, 2024
1 parent a250cf1 commit 3db69b8
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 120 deletions.
144 changes: 79 additions & 65 deletions app/blueprints/self_serve/data/data_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,42 @@ def save_page(page: dict):
def get_list_by_id(id: str) -> dict:
return LISTS.get(id, None)

# TODO Implement front end journey that can use the section/form/page/component CRUD operations
# from app.db.queries.application import insert_new_section
# from app.db.queries.application import insert_new_form
# from app.db.queries.application import insert_new_page
# from app.db.queries.application import insert_new_component

def save_template_component(component: dict):
"""
TODO:
Save a template component to the database
Parameters:
component: dict The component to save to the database as a template
Returns:
dict The saved component
"""
""" temp in memory solution """
component_config = {
"page_id": component.get("page_id"),
"theme_id": component.get("theme_id"),
"title": component.get("title"),
"hint_text": component.get("hint"),
"options": component.get("options"),
"type": component.get("question_type"),
"template_name": component.get("template_name"),
"is_template": True,
"audit_info": component.get("audit_info"),
"page_index": component.get("page_index"),
"theme_index": component.get("theme_index"),
"conditions": component.get("conditions"),
"runner_component_name": component.get("runner_component_name"),
"list_id": component.get("list_id"),
}
return insert_new_component(component_config)
"""

# temp in memory solution
COMPONENTS.append(
{
"json_snippet": {
Expand All @@ -93,97 +114,90 @@ def save_template_component(component: dict):
"builder_display_name": component["builder_display_name"],
}
)
""" end temp """

# component_config = {
# "page_id": component.get("page_id"),
# "theme_id": component.get("theme_id"),
# "title": component.get("title"),
# "hint_text": component.get("hint"),
# "options": component.get("options"),
# "type": component.get("question_type"),
# "template_name": component.get("template_name"),
# "is_template": True,
# "audit_info": component.get("audit_info"),
# "page_index": component.get("page_index"),
# "theme_index": component.get("theme_index"),
# "conditions": component.get("conditions"),
# "runner_component_name": component.get("runner_component_name"),
# "list_id": component.get("list_id"),
# }

# return insert_new_component(component_config)



def save_template_page(page: dict):
"""
TODO:
Save a template page to the database
Parameters:
page: dict The page to save to the database as a template
Returns:
dict The saved page
"""
PAGES.append(page) # Temp in memory solution
page_config = {
"form_id": page.get("form_id"),
"name_in_apply_json": {
"en": page.get("form_display_name"),
},
"template_name": page.get("builder_display_name"),
"is_template": True,
"audit_info": page.get("audit_info"),
"form_index": page.get("form_index"),
"display_path": page.get("display_path"),
"controller": page.get("controller"),
}
return insert_new_page(page_config)
"""

# page_config = {
# "form_id": page.get("form_id"),
# "name_in_apply_json": {
# "en": page.get("form_display_name"),
# },
# "template_name": page.get("builder_display_name"),
# "is_template": True,
# "audit_info": page.get("audit_info"),
# "form_index": page.get("form_index"),
# "display_path": page.get("display_path"),
# "controller": page.get("controller"),
# }
# Temp in memory solution
PAGES.append(page)

# return insert_new_page(page_config)


def save_template_form(form: dict):
"""
TODO:
Save a template form to the database
Parameters:
form: dict The form to save to the database as a template
Returns:
dict The saved form
form_config = {
"name_in_apply_json": {
"en": form.get("form_title"),
},
"is_template": True,
"template_name": form.get("builder_display_name"),
"audit_info": form.get("audit_info"),
"section_id": form.get("section_id"),
"section_index": form.get("section_index"),
"runner_publish_name": None # This is a template
}
insert_new_form(form_config)
"""
FORMS.append(form) # Temp in memory solution

# form_config = {
# "name_in_apply_json": {
# "en": form.get("form_title"),
# },
# "is_template": True,
# "template_name": form.get("builder_display_name"),
# "audit_info": form.get("audit_info"),
# "section_id": form.get("section_id"),
# "section_index": form.get("section_index"),
# "runner_publish_name": None # This is a template
# }

# insert_new_form(form_config)

# Temp in memory solution
FORMS.append(form)



def save_template_section(section: dict):
"""
TODO:
Save a template section to the database
Parameters:
section: dict The section to save to the database as a template
Returns:
dict The saved section
section_config = {
"name_in_apply_json": {
"en": section.get("section_display_name"),
},
"is_template": True, # Assuming this remains a constant value
"template_name": section.get("builder_display_name"),
"description": section.get("description"),
"audit_info": section.get("audit_info"),
}
return insert_new_section(section_config)
"""
SECTIONS.append(section) # Temp in memory solution

# section_config = {
# "name_in_apply_json": {
# "en": section.get("section_display_name"),
# },
# "is_template": True, # Assuming this remains a constant value
# "template_name": section.get("builder_display_name"),
# "description": section.get("description"),
# "audit_info": section.get("audit_info"),
# }

# return insert_new_section(section_config)

# Temp in memory solution
SECTIONS.append(section)


86 changes: 40 additions & 46 deletions app/blueprints/self_serve/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,16 @@ def view_section_questions():
# CRUD routes

# Create routes
@self_serve_bp.route("create_section", methods=["GET", "POST"])
def create_section():
@self_serve_bp.route("section", methods=["GET", "POST"])
def crud_section():
# TODO: Create frontend routes and connect to middleware
if request.method == "GET":
pass
if request.method == "PUT":
pass
if request.method == "DELETE":
pass

form = SectionForm()
if form.validate_on_submit():
save_template_section(form.as_dict())
Expand All @@ -139,8 +147,16 @@ def create_section():
# save to db here
return render_template("create_section.html", available_forms=available_forms, form=form)

@self_serve_bp.route("/create_form", methods=["GET", "POST"])
def create_form():
@self_serve_bp.route("/form", methods=["GET", "POST"])
def crud_form():
# TODO: Create frontend routes and connect to middleware
if request.method == "GET":
pass
if request.method == "PUT":
pass
if request.method == "DELETE":
pass

form = FormForm()
if form.validate_on_submit():
new_form = {
Expand Down Expand Up @@ -170,8 +186,16 @@ def create_form():
)
return render_template("create_form.html", available_pages=available_pages, form=form)

@self_serve_bp.route("/create_page", methods=["GET", "POST"])
def create_page():
@self_serve_bp.route("/page", methods=["GET", "POST", "PUT", "DELETE"])
def crud_page():
# TODO: Create frontend routes and connect to middleware
if request.method == "GET":
pass
if request.method == "PUT":
pass
if request.method == "DELETE":
pass

form = PageForm()
if form.validate_on_submit():
new_page = {
Expand All @@ -195,51 +219,21 @@ def create_page():
]
return render_template("create_page.html", form=form, available_questions=available_questions)

@self_serve_bp.route("/create_question", methods=["GET", "POST"])
def create_question():
form = QuestionForm()
question = form.as_dict()
if form.validate_on_submit():
save_template_component(question)
flash(message=f"Question '{question['title']}' was saved")
return redirect(url_for("self_serve_bp.index"))
return render_template("create_question.html", form=form)



# Edit and Delete routes
@self_serve_bp.route("/edit_section", methods=["GET", "PUT", "DELETE"])
def edit_section():
if request.method == "GET":
pass
if request.method == "PUT":
pass
if request.method == "DELETE":
pass

@self_serve_bp.route("/edit_form", methods=["GET", "PUT", "DELETE"])
def edit_form():
@self_serve_bp.route("/question", methods=["GET", "PUT", "POST" "DELETE"])
def crud_question():
# TODO: Create frontend routes and connect to middleware
if request.method == "GET":
pass
if request.method == "PUT":
pass
if request.method == "DELETE":
pass

@self_serve_bp.route("/edit_page", methods=["GET", "PUT", "DELETE"])
def edit_page():
if request.method == "GET":
pass
if request.method == "PUT":
pass
if request.method == "DELETE":
pass
form = QuestionForm()
question = form.as_dict()
if form.validate_on_submit():
save_template_component(question)
flash(message=f"Question '{question['title']}' was saved")
return redirect(url_for("self_serve_bp.index"))
return render_template("create_question.html", form=form)

@self_serve_bp.route("/edit_question", methods=["GET", "PUT", "DELETE"])
def edit_question():
if request.method == "GET":
pass
if request.method == "PUT":
pass
if request.method == "DELETE":
pass
2 changes: 1 addition & 1 deletion app/blueprints/self_serve/templates/create_section.html
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ <h3 class="govuk-heading-s">
}
function saveSection() {
section_form = document.getElementById("section_form")
section_form.setAttribute("action", "{{url_for('self_serve_bp.create_section')}}")
section_form.setAttribute("action", "{{url_for('self_serve_bp.section')}}")
section_form.submit()
}

Expand Down
16 changes: 8 additions & 8 deletions app/blueprints/self_serve/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@
<h1 class="govuk-heading-m">What do you want to do?</h1>
<h2 class="govuk-heading-s">Template Setup</h2>
<ul class="govuk-body">
<li class="govuk-body"><a class="govuk-link" href="{{ url_for('self_serve_bp.create_question')}}">Add a
<li class="govuk-body"><a class="govuk-link" href="{{ url_for('self_serve_bp.question')}}">Add a
Question</a></li>
<li class="govuk-body"><a class="govuk-link" href="{{ url_for('self_serve_bp.edit_question')}}">Edit/Delete a
<li class="govuk-body"><a class="govuk-link" href="{{ url_for('self_serve_bp.question?edit=true')}}">Edit/Delete a
Question</a></li>
<li class="govuk-body"><a class="govuk-link" href="{{ url_for('self_serve_bp.create_page')}}">Create a
<li class="govuk-body"><a class="govuk-link" href="{{ url_for('self_serve_bp.page')}}">Create a
Page</a></li>
<li class="govuk-body"><a class="govuk-link" href="{{ url_for('self_serve_bp.edit_page')}}">Edit/Delete a
<li class="govuk-body"><a class="govuk-link" href="{{ url_for('self_serve_bp.page?edit=true')}}">Edit/Delete a
Page</a></li>
<li class="govuk-body"><a class="govuk-link" href="{{ url_for('self_serve_bp.create_form')}}">Create an
<li class="govuk-body"><a class="govuk-link" href="{{ url_for('self_serve_bp.form')}}">Create an
Application Form</a></li>
<li class="govuk-body"><a class="govuk-link" href="{{ url_for('self_serve_bp.edit_form')}}">Edit/Delete an
<li class="govuk-body"><a class="govuk-link" href="{{ url_for('self_serve_bp.form?edit=true')}}">Edit/Delete an
Application Form</a></li>
<li class="govuk-body"><a class="govuk-link" href="{{ url_for('self_serve_bp.create_section')}}">Create a
<li class="govuk-body"><a class="govuk-link" href="{{ url_for('self_serve_bp.section')}}">Create a
Section (Group Forms)</a></li>
<li class="govuk-body"><a class="govuk-link" href="{{ url_for('self_serve_bp.edit_section')}}">Edit/Delete a
<li class="govuk-body"><a class="govuk-link" href="{{ url_for('self_serve_bp.section?edit=true')}}">Edit/Delete a
Section</a></li>
</ul>
<h2 class="govuk-heading-s">Fund Metadata</h2>
Expand Down

0 comments on commit 3db69b8

Please sign in to comment.