Skip to content

Commit 099b457

Browse files
authored
Merge pull request #21 from finmaster19/add-cover-text
Add mail cover text
2 parents 099a97f + 85d3866 commit 099b457

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

form_designer/admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class FormDefinitionAdmin(admin.ModelAdmin):
3131
fieldsets = [
3232
(_('Basic'), {'fields': ['name', 'require_hash', 'method', 'action', 'title', 'body']}),
3333
(_('Settings'), {'fields': ['allow_get_initial', 'log_data', 'success_redirect', 'success_clear', 'display_logged', 'save_uploaded_files'], 'classes': ['collapse']}),
34-
(_('Mail form'), {'fields': ['mail_to', 'mail_from', 'mail_subject', 'mail_uploaded_files'], 'classes': ['collapse']}),
34+
(_('Mail form'), {'fields': ['mail_to', 'mail_from', 'mail_subject', 'mail_uploaded_files', 'mail_cover_text'], 'classes': ['collapse']}),
3535
(_('Templates'), {'fields': ['message_template', 'form_template_name'], 'classes': ['collapse']}),
3636
(_('Messages'), {'fields': ['success_message', 'error_message', 'submit_label'], 'classes': ['collapse']}),
3737
]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.db import migrations, models
5+
import form_designer.fields
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('form_designer', '0002_reply_to'),
12+
]
13+
14+
operations = [
15+
migrations.AddField(
16+
model_name='formdefinition',
17+
name='mail_cover_text',
18+
field=models.TextField(help_text='Email cover text which can be included in the default email template and in the message template.', null=True, verbose_name='email cover text', blank=True),
19+
),
20+
migrations.AlterField(
21+
model_name='formdefinition',
22+
name='message_template',
23+
field=form_designer.fields.TemplateTextField(help_text='Your form fields are available as template context. Example: "{{ message }}" if you have a field named `message`. To iterate over all fields, use the variable `data` (a list containing a dictionary for each form field, each containing the elements `name`, `label`, `value`). If you have set up email cover text, you can use {{ mail_cover_text }} to access it.', null=True, verbose_name='message template', blank=True),
24+
),
25+
]

form_designer/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class FormDefinition(models.Model):
4141
title = models.CharField(_('title'), max_length=255, blank=True, null=True)
4242
body = models.TextField(_('body'), help_text=_('Form description. Display on form after title.'), blank=True, null=True)
4343
action = models.URLField(_('target URL'), help_text=_('If you leave this empty, the page where the form resides will be requested, and you can use the mail form and logging features. You can also send data to external sites: For instance, enter "http://www.google.ch/search" to create a search form.'), max_length=255, blank=True, null=True)
44+
mail_cover_text = models.TextField(_('email cover text'), help_text=_('Email cover text which can be included in the default email template and in the message template.'), blank=True, null=True)
4445
mail_to = TemplateCharField(_('send form data to e-mail address'), help_text=_('Separate several addresses with a comma. Your form fields are available as template context. Example: "[email protected], {{ from_email }}" if you have a field named `from_email`.'), max_length=255, blank=True, null=True)
4546
mail_from = TemplateCharField(_('sender address'), max_length=255, help_text=MAIL_TEMPLATE_CONTEXT_HELP_TEXT, blank=True, null=True)
4647
mail_reply_to = TemplateCharField(_('reply-to address'), max_length=255, help_text=MAIL_TEMPLATE_CONTEXT_HELP_TEXT, blank=True)
@@ -55,7 +56,7 @@ class FormDefinition(models.Model):
5556
success_redirect = models.BooleanField(_('HTTP redirect after successful submission'), default=True)
5657
success_clear = models.BooleanField(_('clear form after successful submission'), default=True)
5758
allow_get_initial = models.BooleanField(_('allow initial values via URL'), help_text=_('If enabled, you can fill in form fields by adding them to the query string.'), default=True)
58-
message_template = TemplateTextField(_('message template'), help_text=_('Your form fields are available as template context. Example: "{{ message }}" if you have a field named `message`. To iterate over all fields, use the variable `data` (a list containing a dictionary for each form field, each containing the elements `name`, `label`, `value`).'), blank=True, null=True)
59+
message_template = TemplateTextField(_('message template'), help_text=_('Your form fields are available as template context. Example: "{{ message }}" if you have a field named `message`. To iterate over all fields, use the variable `data` (a list containing a dictionary for each form field, each containing the elements `name`, `label`, `value`). If you have set up email cover text, you can use {{ mail_cover_text }} to access it.'), blank=True, null=True)
5960
form_template_name = models.CharField(_('form template'), max_length=255, blank=True, null=True)
6061
display_logged = models.BooleanField(_('display logged submissions with form'), default=False)
6162

@@ -113,6 +114,7 @@ def compile_message(self, form_data, template=None):
113114
t = Template(self.message_template)
114115
context = self.get_form_data_context(form_data)
115116
context['data'] = form_data
117+
context['mail_cover_text'] = self.mail_cover_text or ''
116118
return t.render(Context(context))
117119

118120
def count_fields(self):

0 commit comments

Comments
 (0)