Skip to content

Commit acb4629

Browse files
authored
Merge pull request #55 from LeanderCS/48
48 | Migrate methods in docs to snake case
2 parents bad3481 + e0c77a6 commit acb4629

File tree

120 files changed

+2845
-3322
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+2845
-3322
lines changed

README.md

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# flask-inputfilter
2+
3+
4+
[![](https://img.shields.io/pypi/v/flask-inputfilter?style=flat-square&label=version)](https://pypi.org/project/flask-inputfilter/)
5+
[![](https://img.shields.io/pypi/pyversions/flask-inputfilter)](https://pypi.org/project/flask-inputfilter/)
6+
[![](https://img.shields.io/github/license/LeanderCS/flask-inputfilter)](https://github.com/LeanderCS/flask-inputfilter/blob/main/LICENSE)
7+
[![](https://img.shields.io/github/actions/workflow/status/LeanderCS/flask-inputfilter/test.yaml?branch=main&style=flat-square&label=tests)](https://github.com/LeanderCS/flask-inputfilter/actions)
8+
[![](https://img.shields.io/coveralls/LeanderCS/flask-inputfilter/main.svg?style=flat-square&label=coverage)](https://coveralls.io/r/LeanderCS/flask-inputfilter)
9+
[![](https://static.pepy.tech/badge/flask-inputfilter/month)](https://pypi.org/project/flask-inputfilter/)
10+
[![](https://static.pepy.tech/badge/flask-inputfilter)](https://pypi.org/project/flask-inputfilter/)
11+
12+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=LeanderCS_flask-inputfilter&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=LeanderCS_flask-inputfilter)
13+
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=LeanderCS_flask-inputfilter&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=LeanderCS_flask-inputfilter)
14+
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=LeanderCS_flask-inputfilter&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=LeanderCS_flask-inputfilter)
15+
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=LeanderCS_flask-inputfilter&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=LeanderCS_flask-inputfilter)<br/>
16+
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=LeanderCS_flask-inputfilter&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=LeanderCS_flask-inputfilter)
17+
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=LeanderCS_flask-inputfilter&metric=bugs)](https://sonarcloud.io/summary/new_code?id=LeanderCS_flask-inputfilter)
18+
[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=LeanderCS_flask-inputfilter&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=LeanderCS_flask-inputfilter)
19+
[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=LeanderCS_flask-inputfilter&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=LeanderCS_flask-inputfilter)
20+
21+
22+
## Description
23+
24+
This library is a Flask extension that provides a simple way to validate and filter input data.
25+
It allows you to define a set of rules for each field in your input data, including filters and validators.
26+
The library also supports conditions that can be used to enforce complex validation rules.
27+
It is designed to be straightforward to use and flexible, allowing you to create custom filters and validators as needed.
28+
29+
30+
## Quickstart
31+
32+
To use the `InputFilter` class, create a new class that inherits from it and define the
33+
fields you want to validate and filter.
34+
35+
There are many filters and validators available, but you can also create your [own](https://leandercs.github.io/flask-inputfilter/guides/create_own.html).
36+
37+
38+
## Installation
39+
40+
Using [pip](https://pip.pypa.io/en/stable/getting-started/):
41+
```bash
42+
pip install flask-inputfilter
43+
```
44+
45+
Using [UV](https://docs.astral.sh/uv/):
46+
```shell
47+
uv add flask-inputfilter
48+
```
49+
50+
Using [Poetry](https://python-poetry.org/docs/):
51+
```shell
52+
poetry add flask-inputfilter
53+
```
54+
55+
There are plenty of wheels for all major environments and all supported python versions.
56+
But if you happen to use an environment where there is no wheel prebuilt, you can use either
57+
the python implementation or you can install ``flask-inputfilter`` with the dependencies needed
58+
for compilation by appending ``[compile]`` to the installation commands above.
59+
60+
_**Note:**_ If you do decide to recompile PQA binaries, you will need to install platform-specific `C/C++` build
61+
tools like [Visual Studio](https://visualstudio.microsoft.com/), [Xcode](https://developer.apple.com/xcode/) or
62+
[GNU Make](https://www.gnu.org/software/make/) _(non-exhaustive list)_.
63+
64+
A more detailed guide can be found [in the docs](https://leandercs.github.io/flask-inputfilter/guides/compile.html).
65+
66+
67+
### Definition
68+
69+
```python
70+
from flask_inputfilter import InputFilter
71+
from flask_inputfilter.conditions import ExactlyOneOfCondition
72+
from flask_inputfilter.enums import RegexEnum
73+
from flask_inputfilter.filters import StringTrimFilter, ToIntegerFilter, ToNullFilter
74+
from flask_inputfilter.validators import IsIntegerValidator, IsStringValidator, RegexValidator
75+
76+
class UpdateZipcodeInputFilter(InputFilter):
77+
def __init__(self):
78+
super().__init__()
79+
80+
self.add(
81+
'id',
82+
required=True,
83+
filters=[ToIntegerFilter(), ToNullFilter()],
84+
validators=[
85+
IsIntegerValidator()
86+
]
87+
)
88+
89+
self.add(
90+
'zipcode',
91+
filters=[StringTrimFilter()],
92+
validators=[
93+
RegexValidator(
94+
RegexEnum.POSTAL_CODE.value,
95+
'The zipcode is not in the correct format.'
96+
)
97+
]
98+
)
99+
100+
self.add(
101+
'city',
102+
filters=[StringTrimFilter()],
103+
validators=[
104+
IsStringValidator()
105+
]
106+
)
107+
108+
self.add_condition(
109+
ExactlyOneOfCondition(['zipcode', 'city'])
110+
)
111+
```
112+
113+
114+
### Usage
115+
116+
To use the `InputFilter` class, call the `validate` method on the class instance.
117+
After calling `validate`, the validated data will be available in `g.validated_data`.
118+
If the data is invalid, a 400 response with an error message will be returned.
119+
120+
```python
121+
from flask import Flask, g
122+
from your-path import UpdateZipcodeInputFilter
123+
124+
app = Flask(__name__)
125+
126+
@app.route('/update-zipcode', methods=['POST'])
127+
@UpdateZipcodeInputFilter.validate()
128+
def updateZipcode():
129+
data = g.validated_data
130+
131+
# Do something with validated data
132+
id = data.get('id')
133+
zipcode = data.get('zipcode')
134+
city = data.get('city')
135+
```
136+
137+
138+
## See also
139+
140+
For further instructions please view the [documentary](https://leandercs.github.io/flask-inputfilter).
141+
142+
For ideas, suggestions or questions, please open an issue on [GitHub](https://github.com/LeanderCS/flask-inputfilter).

README.rst

Lines changed: 0 additions & 136 deletions
This file was deleted.

docs/source/_static/style.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,11 @@ footer {
2828
display: none;
2929
}
3030
}
31+
32+
.sig-object {
33+
width: 100%;
34+
}
35+
36+
.attribute, .method, .class dd>p:first-of-type, .class dd dl.field-list.simple {
37+
display: none;
38+
}

docs/source/conf.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1+
import os
2+
import sys
3+
14
project = "flask-inputfilter"
25
copyright = "2025, Leander Cain Slotosch"
36
author = "Leander Cain Slotosch"
4-
release = "0.5.3"
57

6-
extensions = ["sphinx_rtd_theme", "sphinx_design"]
8+
extensions = [
9+
"sphinx_rtd_theme",
10+
"sphinx_design",
11+
"sphinx.ext.autodoc",
12+
"sphinx.ext.napoleon",
13+
]
14+
15+
autodoc_member_order = "bysource"
16+
autodoc_typehints = "description"
17+
autoclass_content = "both"
18+
19+
sys.path.insert(0, os.path.abspath("../.."))
720

821
templates_path = []
922
exclude_patterns = []

docs/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Definition
9393
]
9494
)
9595
96-
self.addCondition(
96+
self.add_condition(
9797
ExactlyOneOfCondition(['zipcode', 'city'])
9898
)
9999

0 commit comments

Comments
 (0)