questions

Questions is a form library for Python that uses the power of SurveyJS for the UI.

https://github.com/cguardia/questions

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (15.3%) to scientific vocabulary

Keywords

form-generator forms python python3 web-development
Last synced: 6 months ago · JSON representation

Repository

Questions is a form library for Python that uses the power of SurveyJS for the UI.

Basic Info
Statistics
  • Stars: 34
  • Watchers: 2
  • Forks: 11
  • Open Issues: 47
  • Releases: 0
Topics
form-generator forms python python3 web-development
Created over 5 years ago · Last pushed about 1 year ago
Metadata Files
Readme Changelog Contributing License Authors

README.rst

=========
Questions
=========


.. image:: https://img.shields.io/pypi/v/questions.svg
        :target: https://pypi.python.org/pypi/questions

.. image:: https://github.com/cguardia/questions/workflows/continuous-integration/badge.svg
        :target: https://github.com/cguardia/questions/actions?query=workflow%3Acontinuous-integration

.. image:: https://readthedocs.org/projects/questions/badge/?version=latest
        :target: https://questions.readthedocs.io/en/latest/?badge=latest
        :alt: Documentation Status




Questions is a Python form library that uses the power of SurveyJS_ for the UI.
The philosophy behind Questions is that modern form rendering usually requires
integrating some complex Javascript widgets anyway, so why not skip the markup
generation completely? 

.. image:: https://www.delaguardia.com.mx/questions.gif

In Questions, forms are defined in Python similarly to other form frameworks,
but everything on the front end is handled by SurveyJS. This provides a lot of
benefits:

* Nice, integrated UI, with powerful Javascript widgets.
* SurveyJS is compatible with Angular2, JQuery, KnockoutJS, React and VueJS.
  Questions makes sure that you get the right files for each version.
* More than 20 question types, from simple text inputs and dropdowns to
  elaborate widgets like dynamic panels and checkbox matrices.
* Multiple look and feel options (themes), including Bootstrap_ CSS support.
* Full client side validation (plus server side checking, too).
* Use simple text expressions in question declarations to control which
  questions to show depending on the answers to previous ones.
* Complex forms can be defined easily using class composition.
* Easy multi-page forms, with no state-keeping headaches.
* Create forms directly from JSON definitions using SurveyJS form creator.
* Generate Python code from dynamic JSON import.
* Minimal code for simple apps. If you just need a form or two, you are set.
* Zero Javascript code option. If you can use a CDN, no need to install or
  download any javascript.
* Out of the box integration with popular third party widgets, like select2_
  and ckeditor_.
* Supports the creation of tests and quizzes, by defining "correct" answers to
  the questions, and optionally setting a maximum time to finish.

.. _SurveyJS: https://surveyjs.io
.. _Bootstrap: https://getbootstrap.com
.. _select2: https://select2.org/
.. _ckeditor: https://ckeditor.com/ckeditor-4/


How the Code Looks
------------------

To get a feel for how Questions works, nothing better than looking at a simple
example::

    from questions import Form
    from questions import TextQuestion
    from questions import RadioGroupQuestion


    class SimpleForm(Form):
        name = TextQuestion()
        email = TextQuestion(input_type="email", required="True")
        favorite_number = TextQuestion(title="What is your favorite number?",
            input_type="number")
        language = RadioGroupQuestion(title="Favorite Language",
            choices=["Python", "Other"])
        version = RadioGroupQuestion(title="Preferred Python Version",
            choices=["Python 2", "Python 3"],
            visible_if="{language} = 'Python'")

This is a fairly conventional way to define forms, so no surprises here, but
look at the way the ``input_type`` parameter allows us to use different HTML5
text input methods. Pay special attention to the last line, where we use the
``visible_if`` parameter to only show the Python version question if the
answer to the ``language`` question is "Python". Defining "live" form behavior
in this way is something that is usually out of scope for server side code,
but Questions' SurveyJS integration allows us to do it.


Full Working Multi-page Flask Application
-----------------------------------------

Let's show how easy things can be if your applications needs are simple. The
following is a complete application using the popular Flask_ web framework::

    from flask import Flask
    from flask import redirect
    from flask import request

    from questions import Form
    from questions import FormPage
    from questions import TextQuestion
    from questions import DropdownQuestion


    class PageOne(Form):
        name = TextQuestion()
        email = TextQuestion(input_type="email", required="True")


    class PageTwo(Form):
        country = DropdownQuestion(choices_by_url={"value_name": "name",
            "url": "https://restcountries.eu/rest/v2/all"})
        birthdate = TextQuestion(input_type="date")


    class Profile(Form):
        page_one = FormPage(PageOne, title="Identification Information")
        page_two = FormPage(PageTwo, title="Additional Information")


    app = Flask(__name__)

    @app.route("/", methods=("GET",))
    def form():
        form = Profile()
        return form.render_html()

    @app.route("/", methods=("POST",))
    def post():
        form_data = request.get_json()
        # Here, we would save to a database or something
        print(form_data)
        return redirect("/thanks")

    @app.route("/thanks")
    def thanks():
        return "Thanks for your information"

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

By default, Questions uses a CDN for fetching the Javascript resources, which
is why all that is needed to run the above code is installing Flask and
Questions. Of course, it is possible to install all the dependencies yourself
and configure Questions to use your installation, but sometimes this is all
that's required to get a full working application.

Admittedly, our application doesn't do much, but we get a working form that you
can fill and submit in your browser. See how easy it is to get a multi-page
form with navigation buttons. Also, notice how ``get_json`` is the only Flask
request call we need to get the form data. 

As the code shows, defining a multiple page form is very simple, and allows us
to keep the form pages logically separated, and even using them independently
or in combination with other forms with little additional work.

Finally, take a look at the ``choices_by_url`` parameter in the
DropdownQuestion, which allows us to get the dropdown choices from separate,
restful web services.

.. _Flask: https://flask.palletsprojects.com/


License and Documentation
-------------------------

* Free software: MIT license
* Documentation: https://questions.readthedocs.io.


Credits
-------

This package was created with Cookiecutter_ and the
`audreyr/cookiecutter-pypackage`_ project template.

.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage

Owner

  • Name: Carlos de la Guardia
  • Login: cguardia
  • Kind: user
  • Location: México

GitHub Events

Total
  • Watch event: 2
  • Delete event: 18
  • Issue comment event: 17
  • Push event: 29
  • Pull request event: 40
  • Fork event: 1
  • Create event: 23
Last Year
  • Watch event: 2
  • Delete event: 18
  • Issue comment event: 17
  • Push event: 29
  • Pull request event: 40
  • Fork event: 1
  • Create event: 23

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 337
  • Total Committers: 3
  • Avg Commits per committer: 112.333
  • Development Distribution Score (DDS): 0.258
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
pyup-bot g****t@p****o 250
Carlos de la Guardia c****a@y****m 86
joan-qida j****a@q****s 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 9 months ago

All Time
  • Total issues: 10
  • Total pull requests: 325
  • Average time to close issues: 27 days
  • Average time to close pull requests: 26 days
  • Total issue authors: 6
  • Total pull request authors: 2
  • Average comments per issue: 1.6
  • Average comments per pull request: 0.65
  • Merged pull requests: 56
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 2
  • Pull requests: 96
  • Average time to close issues: N/A
  • Average time to close pull requests: 21 days
  • Issue authors: 2
  • Pull request authors: 1
  • Average comments per issue: 1.0
  • Average comments per pull request: 0.7
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • rilshok (4)
  • Irtazaraza (2)
  • guy1ziv2 (1)
  • jhelvy (1)
  • ianchov (1)
  • carlosandujar (1)
Pull Request Authors
  • pyup-bot (440)
  • joan-qida (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 505 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 9
  • Total versions: 8
  • Total maintainers: 1
pypi.org: questions

Questions is a form library that uses the power of SurveyJS for the UI.

  • Versions: 8
  • Dependent Packages: 0
  • Dependent Repositories: 9
  • Downloads: 505 Last month
Rankings
Dependent repos count: 4.8%
Downloads: 9.8%
Average: 9.9%
Dependent packages count: 10.1%
Stargazers count: 12.3%
Forks count: 12.5%
Maintainers (1)
Last synced: 6 months ago

Dependencies

docs/requirements.txt pypi
  • Click ==8.0.3
  • Sphinx ==4.3.2
  • email_validator ==1.1.3
  • pydantic ==1.9.0
  • simpleeval ==0.9.12
  • sphinx-autodoc-typehints ==1.15.3
  • sphinxcontrib.spelling ==5.4.0
  • typing-extensions ==4.0.0
requirements.txt pypi
  • Jinja2 ==3.0.3
  • email_validator ==1.1.3
  • pydantic ==1.9.0
  • requests ==2.27.1
  • simpleeval ==0.9.12
  • typing-extensions ==4.0.0
requirements_dev.txt pypi
  • Click ==8.0.3
  • Sphinx ==4.3.2
  • black ==21.12b0
  • bump2version ==1.0.1
  • coverage ==6.2
  • flake8 ==4.0.1
  • pip ==21.3.1
  • pytest ==6.2.5
  • pytest-runner ==5.3.1
  • sphinx-autodoc-typehints ==1.15.3
  • sphinxcontrib.spelling ==5.4.0
  • tox ==3.24.5
  • twine ==3.7.1
  • watchdog ==2.1.6
  • wheel ==0.37.1
.github/workflows/continuous.yml actions
  • actions/checkout v2 composite
  • actions/setup-python v2 composite