Skip to main content

Python tools for our fork of the digital-form-builder

Project description

# Digital Form Runner Python Tools

This Python package provides essential tools for seamless integration with the Digital Form Runner, allowing you to handle and render data stored and persisted by the runner. These tools simplify data rendering tasks, making it easy to work with various form components and render data in different formats.

## Installation

You can install this package using pip:

```bash
pip install funding-service-design-digital-form-builder-tools

To get started, set up a virtual environment and install the required dependencies:

python -m venv .venv
source .venv/bin/activate  # On Windows, use .venv\Scripts\activate.bat
pip install -r requirements.txt

Usage

Answer Displayers

The core functionality of this package is provided by "Answer Displayers." These classes allow you to render data from various form components. To use an Answer Displayer, simply import it and create an instance:

from answer_displayers import CheckboxesFieldDisplayer

# answer typically comes from a database, written to by form-runner
answer = ["community-pride", "delivering-positive"]

displayer = CheckboxesFieldDisplayer(answer)

formatted_answer = displayer.as_csv

Extending Functionality

You can extend this package's functionality by creating custom rendering methods or customizing existing ones. To do so:

  1. Subclass the AnswerDisplayer abstract base class, name related to the component you want to render.
  2. Implement all existing rendering methods, and add any new ones you need.
  3. Ensure unit tests are updated to cover your new methods, showing input and expected output.
  4. Ensure any new methods have concrete implementations in relevant subclasses.
  5. Ensure your new class is imported in the answer_displayers/__init__.py file.
  6. Update the dictionaries.py file to include your new class.

For example, to create a custom renderer for a new data format:

from answer_displayers import AnswerDisplayer

class NewComponentDisplayer(AnswerDisplayer):
    def __init__(self, answer: str):
        self.raw_answer = answer

    @property
    def as_csv(self):
        ... # custom implementation

    @property
    def as_txt(self):
        ... # custom implementation

    @property
    def as_pdf(self):
        ... # custom implementation

Testing

Unit tests are available in the tests folder. You can run the tests using pytest:

python -m pytest

These tests focus on unit testing and do not rely on external databases or resources.

Versioning

This package follows semantic versioning. If there are changes that break the API or introduce new features, update the version accordingly in the pyproject.toml file.

Purpose

This package simplifies the process of rendering data from the Digital Form Runner's various components. By using Answer Displayers, you can easily adapt data for different output formats, saving time and effort in data handling and rendering.

For more details, documentation, and updates, visit the GitHub repository for this project.

Feel free to contribute and extend this package with additional tools and functionalities as needed.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

File details

Details for the file funding-service-design-digital-form-builder-tools-1.0.2.tar.gz.

File metadata

File hashes

Hashes for funding-service-design-digital-form-builder-tools-1.0.2.tar.gz
Algorithm Hash digest
SHA256 e8740149985f2a37d5680c16a9ef79339791e778e603fd30d4204de814dbbacf
MD5 0ede6efa3594b6e633852bc87525543e
BLAKE2b-256 840dcb9a823e4534bdcf689b83079b375d00a82741db30252a33f073986a6e6c

See more details on using hashes here.

File details

Details for the file funding_service_design_digital_form_builder_tools-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for funding_service_design_digital_form_builder_tools-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 193930f9eaa73bfc94f82102e33461ff0837f04d1f8b8fe924e9cdf7128b6841
MD5 d4b8788969d7a3f23174a4e1856853f5
BLAKE2b-256 7b83b754eaa44d31e51cba8a0a46d1fe7062f06bf71f6e2221ca7f80f3363078

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page