Skip to main content

A Django app for building custom web forms and collecting submissions.

Project description

Django Formulaic

Django Formulaic allows Django Admin users to create custom forms. The generated forms are rendered using an extension of Django's Form class. Form submission data is collected by the app and accessible via its admin interface.

The app was originally developed for internal use. We hope others will find it useful, but it definitely lacks polish at this point in its development.

Implementation

Configuration

# settings.py
INSTALLED_APPS = [
    # ...
    'django_filters',
    'rest_framework',
    'formulaic',
    'admin_ordering',
    # ...
]
# urls.py
urlpatterns = [
    # ...

    path('formulaic/', include('formulaic.urls')),
    path('admin/', admin.site.urls),
]
# settings.py
FORMULAIC_EXPORT_STORAGE_LOCATION = '/data/shared/assets/formulaic_exports'

Example Usage

The CustomForm class extends Django's forms.Form class, so you can expect a lot of the same behavior you see in Django's documentation.

# urls.py
from django.contrib import admin
from django.urls import path, include

from formulaic_demo import views as fd_views

urlpatterns = [
    path('form-test/', fd_views.test_formulaic_form),
    path(
        'form-test/completed/',
        fd_views.test_formulaic_form_complete,
        name='form-complete'
    ),

    path('formulaic/', include('formulaic.urls')),
    path('admin/', admin.site.urls),
]
# formulaic_demo/views.py
from django.shortcuts import redirect, render

from formulaic.forms import CustomForm
from formulaic.models import Form


def test_formulaic_form(request):
    formulaic_form = Form.objects.get(slug='robot-form')

    if request.method == 'POST':
        form = CustomForm(
            request.POST,
            request=request,
            # page-specific name for form. will be stored with each submission in the
            # `source` field.
            instance_id='form-page-a',
            form=formulaic_form
        )

        if form.is_valid():
            formulaic_form.create_submission(
                form.cleaned_data,
                source=form.instance_id,
                metadata={
                    'extra-data-1': 'some data',
                    'extra-data-2': 'more data',
                }
            )

            return redirect('form-complete')

        elif not form.is_valid():
            errors = form.errors
            # raise Exception('Not valid {}'.format(form.errors))
            return render(request, 'formulaic_demo/formulaic-form.html', {
                'form': form
            })
    else:
        form = CustomForm(
            request=request,
            # page-specific name for form. will be stored with each submission in the
            # `source` field.
            instance_id='form-page-a',
            form=formulaic_form
        )

    return render(request, 'formulaic_demo/formulaic-form.html', {
        'form': form
    })


def test_formulaic_form_complete(request):
    formulaic_form = Form.objects.get(slug='robot-form')

    return render(request, 'formulaic_demo/formulaic-form-complete.html', {
        'message': formulaic_form.success_message,
    })
<!-- templates/formulaic_demo/formulaic-form.html -->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Test Formulaic Form</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
  </head>
  <body>
    {{ form }}
  </body>
</html>
<!-- templates/formulaic_demoformulaic-form-complete.html -->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Test Formulaic Form</title>
  </head>
  <body>
    <p>{{ message }}</p>
  </body>
</html>

Dependencies

Python

  • Django 3.1 [wip: expanding to a wider range]
  • Python 3.8 [wip: expanding to a wider range]
  • django-rest-framework 3.11.2 [wip: any breaking changes in 4.x?]
  • django-filter 0.9.2
  • nameparser 0.3.16
  • pyzipcode 2.0.0
  • us 0.9.1
  • tzlocal 1.2.2

We would like to phase these out or make them optional

  • beautifulsoup4 4.4.1
  • raven 6.10.0
  • django-ckeditor 5.9.0

JavaScript

  • jQuery must be included (for now) for the public-facing forms.
  • The admin interface was built mostly using EmberJS. You'll find setup instructions in the README.md at the root of that project: /formulaic/static/admin/ember-formulaic. This should only be important if you wish to make changes to the admin.

License

Formulaic is licensed under the MIT License. View the LICENSE file in the root directory for more information.

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

django-formulaic-1.0.0.tar.gz (2.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_formulaic-1.0.0-py3-none-any.whl (2.6 MB view details)

Uploaded Python 3

File details

Details for the file django-formulaic-1.0.0.tar.gz.

File metadata

  • Download URL: django-formulaic-1.0.0.tar.gz
  • Upload date:
  • Size: 2.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for django-formulaic-1.0.0.tar.gz
Algorithm Hash digest
SHA256 20e73649543b7833f7f8798f41268456a8c520a9ad1520790271abc4bd3b6b01
MD5 f81ab97e5a341218e35b41c690b74e59
BLAKE2b-256 7c64ed9d41e2a6408032a59f0523f928c513be236757862dafd622b90c651891

See more details on using hashes here.

File details

Details for the file django_formulaic-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_formulaic-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a82801a3a85ac56199f3302d91f67166db9ad4bd5714220afc26938d248b2a0b
MD5 d13bc1145d0ee943457c9ba0bc62af29
BLAKE2b-256 909c59bd5617695d38f2e3112a8515aa98d80b7e0e6026d902cc7f55073bdbb1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page