Skip to main content

Django Form Creator

coverage: 100%

A Django application that lets users create forms. This is achieved firstly setting up a form and form questions. The user is able to select the field type per question and thus create a form that supports various field types.

Sections

What's in the box?

The package contains the following:

  • Models to store forms, form questions and responses.
  • Views to create, edit, delete and submit forms.
  • Templates to render each of the views (can be overwritten with your own).
  • Ability to manage forms via the admin panel.
  • Endpoints to download questions and responses both directly via views and via the admin panel.

Installation

PIP install and settings.py

The application can be installed by running the following command:

pip install django-form-creator

Once installed, add the following to your settings.py file:

INSTALLED_APPS = [
    ...
    "form_creator",
    ...
]

Run migrations:

python manage.py migrate

Registering URLs

In your root urls.py file, add the following:

from django.urls import path, include

urlpatterns = [
    ...
    path('form-creator/', include('form_creator.urls')),
]

(Note: you don't need to call the path "form-creator/", rename this to whatever you want.)

This will add the following URLs to your root urls.py file:

URL Description
forms/ Forms list view
forms/create/ Form create view
forms/<int:pk>-<slug:slug>/ Form detail view
forms/<int:pk>-<slug:slug>/edit/ Form edit view
forms/<int:pk>-<slug:slug>/delete/ Form delete view
forms/<int:pk>-<slug:slug>/questions/edit/ Form questions edit view
forms/<int:pk>-<slug:slug>/response/ Form for users to submit responses
forms/<int:pk>-<slug:slug>/export/questions/ Export form questions as CSV
forms/<int:pk>-<slug:slug>/export/responses/ Export form responses as CSV

If you want to limit the available views, you can import each of the views directly. The views are located in form_creator.views. If you want more control over the views, you inherit from the views in form_creator.views and override the methods you want to change.

This might be useful when overriding templates and defining permissions.

Using out of the box templates

The package comes with some templates to allows uses to manage and complete forms. If you wish to use these templates, you will need to download django-crispy-forms and update your settings.py file. Follow the instructions below:

pip install django-crispy-forms

In your settings.py:

INSTALLED_APPS = [
    ...
    "crispy_forms",
    "form_creator",
    ...
]

CRISPY_TEMPLATE_PACK = "bootstrap4"

The included templates also make use of messages. Add the following to your settings.py file:

from django.contrib.messages import constants as messages

MESSAGE_TAGS = {
    messages.DEBUG: "alert-secondary",
    messages.INFO: "alert-info",
    messages.SUCCESS: "alert-success",
    messages.WARNING: "alert-warning",
    messages.ERROR: "alert-danger",
}

Usage

Once you have installed the application, it's time to create your first form. You can either go to the admin panel or access the form_creator:form_list view to start creating your first form. The default requirement is that you are logged in as a staff member in order to create a form.

In our example, we will create a sample form via the admin panel, and then complete it via the front end.

Creating the form

The first time to do is give your form a title and a description.

Owner The form will need to have an owner. This is to allow a person to have control of the form via the form_creator:form_detail and form_creator:form_edit views. This is useful if the owner of the form is not a staff user who can manage the form via the admin panel. If this is not applicable, you can set the owner to yourself.

Status There are 3 statuses to pick form: draft, active and inactive.

Setting the status to either draft or inactive would mean that users are not able to complete the form.

Setting the status to active would allow users to complete the form only if the form is within the start and end date.

Start and end dates Form creating in the admin panel The form must have a start date and can have an end date. The start date is the date from which the form will become live. Users will only be able to complete the form from the start date if the from status is set to active.

The end date is an optional configuration. If the value is set, it means that the form has no end date. Otherwise, the form will be live until the end date.

Editors Form editors The editors section is allowed to assigns users who can edit the form details and questions. They are not however able to delete the form itself.

Setting Questions The next section is where you will be able to set the questions for your form. You are able to set question, any applicable choices and the field type.

Form questions

Completing the form

Users are able to navigate to the URL for forms_creator:form_response to complete the form.

The form generated will respect the form fields selected and any choices allowed.

Once the form is completed, they are able to press submit to submit the form.

Form being completed

Contributing

If you would like to help develop this application here are a couple of things you can do:

  • Raise an issue/suggestion on the GitHub repository.
  • Find an issue/suggestion on the GitHub repository that you would like to work on, fork the repository and start working on it! When you're ready, create a pull request on GitHub.

Contributing to the code

  1. Fork the repository and clone it to your local machine.
  2. Create a new branch for your changes.
  3. Create a virtual environment and install the dependencies.
python3 -m venv venv
. venv/bin/activate
pip install -r requirements.txt
  1. example contains a Django project for development. Move into that directory: cd example
  2. Run migrations: python manage.py migrate. As we are using an sqlite3 database, there is no need to create a database yourself.
  3. Create yourself a superuser: python manage.py createsuperuser.
  4. Run the development server: python manage.py runserver.
  5. Write some code, don't forget to write tests.
  6. Run the formatter/linter to format and lint your code:
make format
make lint
  1. Run tests - let's try to stick to 100% coverage.
cd ..
make test-coverage
  1. Update the coverage on the README.md file: make update_readme_cov.
  2. Commit your changes, push them to your repository and merge into master.
  3. Create a pull request to merge into the remote repository.

Metadata

Release files for django-form-creator 1.0.0

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

Source distribution (sdist)

Source distribution for django-form-creator 1.0.0
File Size Uploaded Provenance
django-form-creator-1.0.0.tar.gz 26.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-form-creator 1.0.0
File Interpreter ABI Platform
django_form_creator-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 64.2 kB

Release files / django-form-creator-1.0.0.tar.gz

Download URL django-form-creator-1.0.0.tar.gz
Size 26.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1e903b97a85488faf90b228022ff39e9cc68f4207b81ac317e1b8c330537469a
BLAKE2b-256 checksum
How to use checksums
f0e8128b97acebe459dfa8ab13ad0bce413c1cf384d53534d615e47f7a5a5d7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.10

Release files / django_form_creator-1.0.0-py3-none-any.whl

Download URL django_form_creator-1.0.0-py3-none-any.whl
Size 37.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1ce6cce4b3c8c34b7cd34a5ed62667b27021c7ac1185f3aad2eabb259be604e7
BLAKE2b-256 checksum
How to use checksums
b62dae93e59a284d0f013eb1be5f1012bb9e53c9b0f69c1a85702b2d3be78602
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.10

Security for django-form-creator 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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