Does this rag smells like chloroform?
A customizable contact form app. Chloroform proposes a configuration model for
a contact form. A contact form is defined by a Configuration
object which
links a set of Metadata
through Requirement
objects. Metadata
define
fields for the contact form. They define the field type, name, and description.
Requirement
link the configuration and the metadata and define if the field
is required. Metadata
instances can be shared by multiple configuration.
The form is generated by Chloroform according to the configuration. Chloroform
has a default
configuration. The form is generated by a view or by a template tag.
Install the app
pip install -i https://pi.emencia.net/jenkins/release chloroform
Add chloroform
to the INSTALLED_APPS
and include chloroform.urls
. Create
a default
configuration, and add some metadata.
Chloroform will use these settings:
CHLOROFORM_DOMAIN
which is an URL as a string. It must have a scheme and no path.CHLOROFORM_FROM_EMAIL
is the default from email for the notification sent by Chloroform. If its not set,DEFAULT_FROM_EMAIL
is used instead.CHLOROFORM_TARGET_EMAILS
is a list of target emails when no target is defined in the configuration.
Chloroform can be called by the views named chloroform
and
default-chloroform
and the template tag {% chloroform %}
.
- Models may be sorted by adminsortable2 if it's in the
INSTALLED_APPS
- captcha if it's in
INSTALLED_APPS
- Model Translation through django-modeltranslation if its installed, for
models
Configuration
,Metadata
andAlternative
ckeditor
forsuccess_message
- Export from the admin if
import_export
is in installed apps
Chloroform will use in all forms a field named message and a field named email.
They are used internally by chloroform and cannot be removed. They can be
renamed and customized by creating a metadata named respectively message
and
email
and adding them to the configuration.
Chloroform uses Crispy form helpers. There is a default form helper generated
from the form. It's customizable by using the setting CHLOROFORM_HELPERS_MODULE
.
CHLOROFORM_HELPERS_MODULE = 'project.chloroform_helpers'
This module may define ChloroformHelper
or ChloroformTagHelper
being
used respectively for the view and the template tag. Those have to be
FormHelper
subclasses. They take the form for which the form helper is
generated as constructor argument. If this form is passed to the parent
constructor, the defined layout is discarded and one is generated from the form.
class ChloroformHelper(FormHelper):
layout = Layout( ... )
def __init__(self, form):
# Discard the form in order to avoid layout to be overwritten
super().__init__(None)
The form Meta contains the Configuration
instance for which it is generated.
class ChloroformHelper(FormHelper):
layout = Layout( ... )
def __init__(self, form):
if form.Meta.configuration.name == 'default':
# Use the layout for default configuration,
# let crispy generate a new one for other configurations
form = None
super().__init__(form)
The property form_action
is not required as it will always be overwritten by
the view.
The order of fields depends on the order defined in the model. Extra fields
will throw an ImproperlyConfigured
exception as will missing required fields.