Package: feed-gov-back
A small API enabled framework for adding user feedback forms to existing applications within GOV.uk (or other apps).Quick startInstall the package:pip install feed-gov-backAddfeedbackto yourINSTALLED_APPSin yoursettings:INSTALLED_APPS = [
    ...
    'feedback',
]Include the feedback URLconf in your project urls.py like this:path('feedback/', include('feedback.services.urls'))

or if not using the Api:

path('feedback/', include('feedback.urls'))Run migrations and load fixtures:./manage.py migrate
./manage.py loaddata path/to/fedback/fixtures/*.jsonUsing MakeTheMakefileprovides some handy commands:make test  # run all tests
make sdist  # run python setup.py sdist to create a local installableHow it worksAFeedbackFormcontains one or moreFormElementmodels of differentElementType. These
models represent the form and it’s elements.
The data is collected for each submission intoFeedbackCollectionwhich containFeedbackDatarecords for
each form element submitted.As a form can be placed in different parts of a web resource,Placementrecords can be created to
group together form data submitted for different parts of the application. Placements do not have
to be created upfront, and can be generated on the fly by providing a unique placement key with the form.A REST Api is exposed to allow manipulating the models externally, which is useful when this is deployed
into a backend service.In addition, a view to accept form submissions is provided, as well as template tags to render a complete form
or part of it.Forms can be built via the Api, Models or simply created via the Django admin or even fixtures.Element TypesThere are 3 element types defined: scale, large text area and text input. Scale elements can receiveoptionsto override defaults. The options and defaults are:{
    "min": 1,
    "max": 5,
    "min_label": "Poor",
    "max_label": "Excellent",
    "type": int
}

It is also possible to explicitly define the scale labels by providing a list of labels instead of the min/max
combination

``labels: ["great", "indifferent", "poor"]``

In this case the "type" property of the options should be changed to ``str``Fields can be rendered by theform_elementtemplate tag provided or manually in your templates.Data collectionData is collected into theFeedbackDatamodel, grouped intoFeedbackCollectionentries.
As feedback forms can be used in different parts of an application, the model expects aPlacementto tell
it which part of the application or website this form relates to. If a placement is not provided explicitly,
a default one will be used. Placement ids can also be provided in runtime by simply providing it as a string.
NewPlacementrecords will be created.SettingsThe following settings are expected in your Django applicationSettingDescriptionAUTH_USER_MODELA path to the User model. Defaults toauth.UserDEFAULT_PLACEMENT_KEYA key to use as default placement if one is not provided. Defaults toDEFAULTANONYMOUS_COLLECTIONA boolean to determine if to force anonymous collection or retain the user if available. Defaults toTrueMANAGED_FEEDBACK_MODELSSet to False to prevent the creation of database models. Defaults toTrueUsageTo include a complete feedback form:{% load feedback_form %}
{% feedback_form request 'FORM_REFERENCE' %}or to include a specific placement:{% feedback_form request 'FORM_REFERENCE' 'PLACEMENT_ID' %}Note that the feedback_form tag requires the request to pass through it in order toe generate the csrf_token.One important noteregarding FORM_REFERENCE shown in the tag example above: FORM_REFERENCE can be either a
Feedback form unique key, it’s unique UUID, the form Model instance itself, or a dict representation of the form.
This allows for different usage pattern, depending on where this package is installed.
For example, if Feedback forms are to be used across a service which is made of an API and a UI layer as separate
applications, the API can install the package allowing for model creation but obviously not using the templatetags
as it has no rendering responsibility. The UI however can install the package, disabling model management and only
use the tags, by passing the dict returned from the API call. Note that in the case of passing a form model or dict
the single quotes should be omitted. The example application demonstrates this concept.StylingThe implemented template tags wrap the entire form in a div with idfeedback-form.
Subsequently, each element is div wrapped with a classfeedback-form-element.
The submit button is classed withfeedback-form-button.
Within each element the following divs wrap the name, label and description fields:feedback-form-element-name,feedback-form-element-labelandfeedback-form-element-descriptionExample AppTheexampledirectory contains a simple django project that utilises the feedback lib.
It provides a docker contained postgres db which can be built to isolate the example.
The make file allows for installation of the library based on a local sdist build.To run it, create a virtual environment and activate it.
Then either provide your own database ordocker-composeupto use the docker one.
Start with:./manage.py migrate
./manage.py loaddata ./feed/fixtures/*.json
./manage.py runserverYou can create your form viahttp://localhost:8000/admin(create a superuser to access the admin)interact with the form viahttp://localhost:8000load the form using a key only:http://localhost:8000/keyload the form using a dict representation of it:http://localhost:8000/dict