Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #30 from atiberghien/master

Add file upload management
  • Loading branch information...
commit ad69dda2d30c0104e0e96a0b3cafd2be4c6a015c 2 parents 09766ac + 1108b50
Marc-Stefan Cassola authored
Showing with 6 additions and 3 deletions.
  1. +6 −3 cmsplugin_contact/cms_plugins.py
9 cmsplugin_contact/cms_plugins.py
View
@@ -87,12 +87,12 @@ class ContactForm(self.contact_form, HoneyPotContactForm):
FormClass = ContactForm
if request.method == "POST":
- return FormClass(request, data=request.POST)
+ return FormClass(request, data=request.POST, files=request.FILES)
else:
return FormClass(request)
- def send(self, form, site_email):
+ def send(self, form, site_email, attachments=None):
subject = form.cleaned_data['subject']
if not subject:
subject = _('No subject')
@@ -108,6 +108,9 @@ def send(self, form, site_email):
headers = {
'Reply-To': form.cleaned_data['email']
},)
+ if attachments:
+ for var_name, data in attachments.iteritems():
+ email_message.attach(data.name, data.read(), data.content_type)
email_message.send(fail_silently=False)
def render(self, context, instance, placeholder):
@@ -116,7 +119,7 @@ def render(self, context, instance, placeholder):
form = self.create_form(instance, request)
if request.method == "POST" and form.is_valid():
- self.send(form, instance.site_email)
+ self.send(form, instance.site_email, attachments=request.FILES)
context.update( {
'contact': instance,
})
Please sign in to comment.
Something went wrong with that request. Please try again.