Skip to main content

checkbox-parser

A python module that takes a list object and transforms it to a HTML fieldsets with a question and its answers as checkboxs that can be rendered in flask. The purpose is that the list that is consumed could reside in a noSQL database as a document(MongoDB, Firestore, DynamoDB)

How it works?

first, you need a list in this structured way

[
    {
        'id_question': 'first', 
        'question': 'What is the most important reason for choosing a gym?', 
        'answers': ['The price', 'That it has personalized attention', 'That it has the best facilities', 'That it has a very long schedule'], 
        'position': 1
    }, 
    
    {
        'id_question': 'third', 
        'question': 'What pay period is the best for you to go to a gym?', 
        'answers': ['Annual', 'Bimonthly', 'Monthly'], 
        'position': 3
    }, 
    
    {
        'id_question': 'second', 
        'question': 'What motivates you the most to join a gym?', 
        'answers': ['Physical appearance', 'Physical condition', 'Know another social circle'], 
        'position': 2
    }
        
]

Note:

  • make sure that the id_question value does not repeat itself, this is was intended to map the question with the respectives anwsers

Then you just create a html_parser object. This object just needs the list for work In order to get the html you can use the get_html method, this will return the html as string


from checkbox_parser import html_parser


...


parser = html_parser(data)
parser.get_html()

Use with flask

This is a little snippet of how you can use it with flask

from flask import Flask, render_template
from checkbox_parser import html_parser


app=Flask(__name__)

@app.route("/")
def survey():

    data = [
    {
        'id_question': 'first', 
        'question': 'What is the most important reason for choosing a gym?', 
        'answers': ['The price', 'That it has personalized attention', 'That it has the best facilities', 'That it has a very long schedule'], 
        'position': 1
    }, 
    
    {
        'id_question': 'third', 
        'question': 'What pay period is the best for you to go to a gym?', 
        'answers': ['Annual', 'Bimonthly', 'Monthly'], 
        'position': 3
    }, 
    
    {
        'id_question': 'second', 
        'question': 'What motivates you the most to join a gym?', 
        'answers': ['Physical appearance', 'Physical condition', 'Know another social circle'], 
        'position': 2
    }
        
    ]

    parser = html_parser(data)
    html = parser.get_html()

    return render_template("your_html_template.html", html=html)

if __name__ == "__main__":
    app.run()

Note:

  • I recommend that in your ninja template use the decode method for the html object, in case this prevents bad characters to be rendered.
    <form action="/endpoint_get" method="GET" name="myForm">

        {{ html.decode('utf-8') | safe }}

    <div class="container">
      <div class="center">
        <button id="submit">submit</button>
      </div>
    </div>

    </form>

Release files for checkbox-parser 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for checkbox-parser 0.0.1
File Size Uploaded
checkbox_parser-0.0.1.tar.gz 3.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for checkbox-parser 0.0.1
File Interpreter ABI Platform
checkbox_parser-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 7.6 kB

Release files / checkbox_parser-0.0.1.tar.gz

Download URL checkbox_parser-0.0.1.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
8b8c608bd8585d55705650347ea93f50c6c3879132c86eeb2bb3e9f4aeefdf2c
BLAKE2b-256 checksum
How to use checksums
b6bbd2002b68595d0866b55f0d083b5d2e603be14b1e5cae284479df98b570b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.6.9

Release files / checkbox_parser-0.0.1-py3-none-any.whl

Download URL checkbox_parser-0.0.1-py3-none-any.whl
Size 4.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cbdf8155985984264d111fb6730ba2e5edd4c06f8597e1a19518b73a77760c9b
BLAKE2b-256 checksum
How to use checksums
9ce764bdbf51b49cd46a7f49299efebe7b87acb80c5e125e0ba725b0a22002e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.6.9

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page