Writeback
Writeback is a pluggable customizable Django app to collect feedback from site visitors using AJAX.
Installation
Install using pip::
pip install django-writeback
Quick start
-
Add "writeback" to your INSTALLED_APPS setting like this::
INSTALLED_APPS += ('writeback', )
-
Add context processor to your TEMPLATE_CONTEXT_PROCESSORS setting like this::
TEMPLATE_CONTEXT_PROCESSORS += ('writeback.context.add_form', )
-
Specify email settings WRITEBACK_EMAIL_NOTIFICATION_SUBJECT, WRITEBACK_EMAIL_NOTIFICATION_FROM and WRITEBACK_EMAIL_NOTIFICATION_TO_LIST. These will be used in email notifications.
-
Run python manage.py syncdb
to synchronize the database.
-
Run python manage.py collectstatic
or python manage.py collectstatic -i admin
, if you want to omit collecting static for the admin app.
-
Include the writeback URLconf in your project urls.py like this::
url(r'^writeback/', include('writeback.urls')),
-
Modify your base template::
<!-- in header block -->
{% include "writeback/header.html" %}
<!-- in body block -->
{% include "writeback/button.html" %}
-
Override email_notification.html
and button.html
templates.
Model customization
The Message
model, which is used for collecting feedback, can be extended:
-
Create an app, for example custom_writeback
with a file, which shall contain class declaration, name it, models.py
, for example.
-
Add this newly created app to your INSTALLED_APPS
setting like this::
INSTALLED_APPS += ('custom_writeback', )
-
Declare your abstract model class anew or, if you want to extend the base model, inherit it from writeback.models.MessageAbstract
like so::
from writeback.models import MessageAbstract
class MyMessageAbstract(MessageAbstract):
# define your custom fields
class Meta(MessageAbstract.Meta):
pass
-
Register your class in the project's settings.py
::
WRITEBACK_MESSAGE_BASE_MODEL = 'custom_writeback.models.MyMessageAbstract'
-
Define a new form, which shall be used for the new model.
Form customization
If you have overriden or customized the Message
model, you most probably need to customize the form. But even if you use the original model, you may want to change the form clean()
method.
-
Create an app, for example custom_writeback
(if you haven't already) with a file, which shall contain class declaration, name it, forms.py
, for example.
-
Add this newly created app to your INSTALLED_APPS
setting like this::
INSTALLED_APPS += ('custom_writeback', )
-
Declare your new form-class like so::
from django.utils.translation import ugettext_lazy as _
from django.forms import ValidationError
from writeback.forms import MessageCreateFormBase
from writeback.models import Message
class MessageCreateForm(MessageCreateFormBase):
class Meta:
model = Message
exclude = ['date_created', 'middle_name', 'company', 'info']
def clean(self):
cleaned_data = super(MessageCreateFormBase, self).clean()
name = cleaned_data.get("name")
family_name = cleaned_data.get("family_name")
phone = cleaned_data.get("phone")
email = cleaned_data.get("email")
if not (name or family_name or phone or email):
raise ValidationError(_("Please, fill out at least one field."))
return super(MessageCreateFormBase, self).clean()
-
Register your class in the project's settings.py
::
WRITEBACK_MESSAGE_BASE_FORM = 'custom_writeback.forms.MessageCreateForm'