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:
- Subclass the
AnswerDisplayer
abstract base class, name related to the component you want to render. - Implement all existing rendering methods, and add any new ones you need.
- Ensure unit tests are updated to cover your new methods, showing input and expected output.
- Ensure any new methods have concrete implementations in relevant subclasses.
- Ensure your new class is imported in the
answer_displayers/__init__.py
file. - 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
Hashes for funding-service-design-digital-form-builder-tools-0.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d44a3446c8915ea1fa8e8c8c58a467134de94dc8c1928c3bfbc0c3dd79cd08ea |
|
MD5 | 43083c33f2145c363eca2993ab9f6d2d |
|
BLAKE2b-256 | eeb85aea9b6fd4c3c7ab4e5d0e94b91492b10a2edccf418dd4eb0b294ee8b155 |
Hashes for funding_service_design_digital_form_builder_tools-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 112a6f266d005096eecd399dda9eb930b18ce10573b082af79697e20c5f9a0c4 |
|
MD5 | 0eb257618f7aec26f968929e031b0c8f |
|
BLAKE2b-256 | 806dee9d5dda85f078e50d4e9e30f9b3d43c1218b1ddc41fe4ff322743f4a0cd |