Skip to main content

Category Pages

Category pages are the first pages on a user journey through the service. Their purpose is to diagnose the category of law of a users’ problem.

The main category page views are defined in app.category.views.

All views inherit from CategoryPage, a page can be registered to use this view by adding the following to a blueprint:

bp.add_url_rule('/url_endpoint', view_func=CategoryPage.as_view('page_name', template='template.html'))

Index Page

The index page is the first page a user will see once starting their journey, it presents a list of categories of law where a user can select which is most applicable to their problem based on the provided descriptions.

It is found at the /find-your-problem/ endpoint.

Category Landing Page

Category landing pages are typically the first page a user is directed to after selecting a category, they allow the user to select a subcategory. These subcategories may route the user to a different main category entirely.

Here is an example of a category landing page:

from app.categories.housing import bp
from app.categories.views import CategoryLandingPage


class HousingLandingPage(CategoryLandingPage):
    question_title = "Housing, Homelessness, and Eviction"

    category = "Housing"

    routing_map = {
        "homelessness": "categories.results.in_scope",
        "eviction": "contact.contact_us",
        "other": "categories.results.cannot_find_your_problem",
    }


bp.add_url_rule(
    "/housing",
    view_func=HousingLandingPage.as_view(
        "landing", template="categories/housing/landing.html"
    ),
)
HousingLandingPage.register_routes(bp)

The /housing url rule registers the URL for the landing page and calling register_routes creates url rules for the sub categories.

This means the routing logic is handled in the LandingPage class rather than via the template.

These routes are registered to the /housing/answer/{answer_key}/ endpoint where answer_key would be “homelessness”, “eviction”, or “other”.

Routing with additional arguments

If you need to route to a page which accepts additional arguments, such as FALA, then map your route to a dictionary rather than an endpoint.

For example:

routing_map = {
        "community_care": {"endpoint": "find-a-legal-adviser.search", 
                           "category": "mhe",
                           "secondary-category": "com"}
}

The dictionary will be unpacked before being passed into url_for.

This also allows you to route a specific anchor tag on a page by passing in the _anchor key.

Templates

Here is an extract from the housing landing page template. Each list item links to one of the endpoints generated by HousingLandingPage.register_routes, meaning the templates do not need to be updated if the routing changes.

<h1 class="govuk-heading-xl">{% trans %}Housing, homelessness, losing your home{% endtrans %}</h1>

        {{ list_item(_("Homelessness"),
                     _("Help if you’re homeless, or might be homeless in the next 2 months. This could be because of rent arrears, debt, the end of a relationship, or because you have nowhere to live."),
                     url_for("categories.housing.homelessness")) }}

        {{ list_item(_("Eviction, told to leave your home"),
             _("Landlord has told you to leave or is trying to force you to leave. Includes if you’ve got a Section 21 or a possession order."),
             url_for("categories.housing.eviction")) }}

Category Answer Pages

A category answer page is created by the register_routes method of the CategoryLandingPage, this provides the endpoint you can generate a url for in your templates.

This page redirects the user to the onward page based on the routing_map.

They do not need to be generated directly.

Question Pages

Question pages are used to display a WTForms form and route the user to the next page based on their response.

A question page requires a question page url rule and a question page form.

The form should inherit from QuestionForm and either set the next_step_mapping or overwrite the get_next_page method.

Here is an example of a question form:


class DiscriminationWhereForm(QuestionForm):
    title = "Where did the discrimination happen?"

    category = "Discrimination"

    next_step_mapping = {
        "work": "categories.discrimination.why",
        "school": "categories.discrimination.why",
        "business": "categories.discrimination.why",
        "healthcare": "categories.discrimination.why",
        "housing": "categories.discrimination.why",
        "public": "categories.discrimination.why",
        "club": "categories.discrimination.why",
        "notsure": "categories.alternative_help",
    }

    question = RadioField(
        title,
        widget=CategoryRadioInput(show_divider=True),
        validators=[InputRequired(message="Select where the discrimination happened")],
        choices=[
            ("work", "Work - including colleagues, employer or employment agency"),
            ("school", "School, college, university or other education settings"),
            (
                "business",
                "Businesses or service provision - like a shop, restaurant, train, hotel, bank, law firm",
            ),
            ("healthcare", "Health or care - like a hospital or care home"),
            ("housing", "Housing provision - like a landlord or estate agent"),
            (
                "public",
                "Public services and authorities - like the police, social services, council or local authority, jobcentre, government",
            ),
            ("club", "Clubs and associations - like a sports club"),
            ("", ""),
            ("notsure", "Not sure"),
        ],
    )

This form can be given a url route and endpoint using the following:

bp.add_url_rule(
    "/discrimination/where",
    view_func=QuestionPage.as_view("where", form_class=DiscriminationWhereForm),
)