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

Render all the fields of a form #95

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
2 changes: 2 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,13 @@ def create_app(config_class=Config):
from app.main import bp as main_bp
from app.categories import bp as categories_bp
from app.find_a_legal_adviser import bp as fala_bp
from app.means_test import bp as means_test_bp
from app.contact import bp as contact_bp

app.register_blueprint(main_bp)
app.register_blueprint(categories_bp)
app.register_blueprint(fala_bp)
app.register_blueprint(means_test_bp)
app.register_blueprint(contact_bp)

return app
13 changes: 13 additions & 0 deletions app/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def _make_request(
Returns:
The parsed JSON response from the server
"""
if not endpoint.endswith("/"): # CLA Backend requires trailing slashes
endpoint = f"{endpoint}/"

if params:
params = self.clean_params(
params
Expand Down Expand Up @@ -102,6 +105,16 @@ def post(self, endpoint: str, json: dict):
"""
return self._make_request(method="POST", endpoint=endpoint, json=json)

def patch(self, endpoint: str, json: dict):
"""Make a PATCH request to CLA Backend.
Args:
endpoint (str): The endpoint to request
json (dict): The data to send to the backend
Returns:
dict: The JSON response from the backend
"""
return self._make_request(method="PATCH", endpoint=endpoint, json=json)

@cache.memoize(timeout=86400) # 1 day
def get_help_organisations(self, category: str):
"""Get help organisations for a given category, each unique set of arguments return value is cached for 24 hours.
Expand Down
46 changes: 35 additions & 11 deletions app/categories/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,58 @@ class Category:
display_text: LazyString
code: str
article_category_name: str | None
chs_code: str | None # One of legalaid_categories.code

def __str__(self):
# Returns the translated display text
return str(self.display_text)


FAMILY = Category(_("Children, families and relationships"), "FAMILY", "Family")
FAMILY = Category(
_("Children, families and relationships"), "FAMILY", "Family", "family"
)
HOUSING = Category(
_("Housing, homelessness, losing your home"), "HOUSING", "Community care"
_("Housing, homelessness, losing your home"), "HOUSING", "Housing", "housing"
)
COMMUNITY_CARE = Category(
_("Community care"), "COMMUNITY_CARE", "Community care", "commcare"
)
DOMESTIC_ABUSE = Category(
_("Domestic abuse"), "DOMESTIC_ABUSE", "Domestic abuse", "family"
)
COMMUNITY_CARE = Category(_("Community care"), "COMMUNITY_CARE", "Community care")
DOMESTIC_ABUSE = Category(_("Domestic abuse"), "DOMESTIC_ABUSE", "Domestic abuse")
BENEFITS = Category(
_("Appeal a decision about your benefits"), "BENEFITS", "Welfare benefits"
_("Appeal a decision about your benefits"),
"BENEFITS",
"Welfare benefits",
"benefits",
)
DISCRIMINATION = Category(
_("Discrimination"), "DISCRIMINATION", "Discrimination", "discrimination"
)
DISCRIMINATION = Category(_("Discrimination"), "DISCRIMINATION", "Discrimination")
MENTAL_CAPACITY = Category(
_("Mental capacity, mental health"), "MENTAL_CAPACITY", "Mental health"
_("Mental capacity, mental health"),
"MENTAL_CAPACITY",
"Mental health",
"mentalhealth",
)
ASYLUM_AND_IMMIGRATION = Category(
_("Asylum and immigration"), "ASYLUM_AND_IMMIGRATION", None
_("Asylum and immigration"), "ASYLUM_AND_IMMIGRATION", None, "immigration"
)
SOCIAL_CARE = Category(
_("Care needs for disability and old age (social care)"), "SOCIAL_CARE", None
_("Care needs for disability and old age (social care)"),
"SOCIAL_CARE",
None,
"commcare",
)
PUBLIC_LAW = Category(
_("Legal action against police and public organisations"), "PUBLIC_LAW", "Public"
_("Legal action against police and public organisations"),
"PUBLIC_LAW",
"Public",
"publiclaw",
)
EDUCATION = Category(
_("Special educational needs and disability (SEND)"), "EDUCATION", "Education"
_("Special educational needs and disability (SEND)"),
"EDUCATION",
"Education",
"education",
)
2 changes: 1 addition & 1 deletion app/categories/x_cat/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AreYouUnder18Form(QuestionForm):
class AntiSocialBehaviourForm(QuestionForm):
title = _("Were you accused by a landlord or the council?")
category = Category(
_("Anti-social behaviour and gangs"), "ANTI_SOCIAL_BEHAVIOUR", None
_("Anti-social behaviour and gangs"), "ANTI_SOCIAL_BEHAVIOUR", None, None
)
next_step_mapping = {
"yes": {
Expand Down
2 changes: 1 addition & 1 deletion app/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ class Config(object):
"https://laa-legal-adviser-api-production.cloud-platform.service.justice.gov.uk",
)
POSTCODES_IO_URL = os.environ.get("POSTCODES_IO_URL", "https://api.postcodes.io")
CLA_BACKEND_URL = os.environ.get("CLA_BACKEND_URL", "http://localhost:8010")
CLA_BACKEND_URL = os.environ.get("CLA_BACKEND_URL", "http://localhost:8000")
8 changes: 8 additions & 0 deletions app/means_test/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from flask import Blueprint

bp = Blueprint("means_test", __name__)

YES = "1"
NO = "0"

from app.means_test import urls # noqa: E402,F401
28 changes: 28 additions & 0 deletions app/means_test/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from app.api import cla_backend
from flask import session, url_for, redirect


def update_means_test(payload):
means_test_endpoint = "checker/api/v1/eligibility_check/"

ec_reference = session.get("reference")

if ec_reference:
print(payload)
response = cla_backend.patch(
f"{means_test_endpoint}{ec_reference}", json=payload
)
return response
else:
print(payload)
response = cla_backend.post(means_test_endpoint, json=payload)
session["reference"] = response["reference"]
session["name"] = "Ben"
print(session)
return redirect(url_for(("categories.results.in_scope")))


def is_eligible(reference):
means_test_endpoint = "checker/api/v1/eligibility_check/"
response = cla_backend.post(f"{means_test_endpoint}{reference}/is_eligible/")
return response["is_eligible"]
Loading
Loading