summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
Diffstat (limited to 'main')
-rw-r--r--main/actions.py1
-rw-r--r--main/forms.py31
-rw-r--r--main/views.py38
3 files changed, 60 insertions, 10 deletions
diff --git a/main/actions.py b/main/actions.py
index d2cd409..74b622a 100644
--- a/main/actions.py
+++ b/main/actions.py
@@ -34,4 +34,5 @@ actions = ((Action('view', '', _('View')), []),
(Action('edit', 'edit', _('Add a new point of interest')),
Action('edit_route', 'edit_route', _('Add a new route')))
),
+ (Action('contact', 'contact', _('Contact us')), []),
)
diff --git a/main/forms.py b/main/forms.py
index ee69328..be18b2f 100644
--- a/main/forms.py
+++ b/main/forms.py
@@ -24,7 +24,7 @@ from django import forms
from django.contrib.gis.db import models
from django.utils.translation import ugettext as _
from django.contrib.auth.models import User
-from django.core.mail import send_mail
+from django.core.mail import EmailMessage, BadHeaderError
from chimere import settings
@@ -32,17 +32,38 @@ from chimere.main.models import Marker, Route, PropertyModel, Property, Area,\
News, Category
from chimere.main.widgets import AreaField, PointField, TextareaWidget
-def notifyStaff(geo_object):
- category = unicode(geo_object.subcategory)
- subject = u'[Chimère] %s %s' % (_(u"New submission for"), category)
+def notifyStaff(subject, body, sender=None):
+ if settings.PROJECT_NAME:
+ subject = u'[%s] %s' % (settings.PROJECT_NAME, subject)
user_list = [u.email for u in
User.objects.filter(is_staff=True).exclude(email="").order_by('id')]
+ headers = {}
+ if sender:
+ headers['Reply-To'] = sender
+ email = EmailMessage(subject, body, user_list[0], user_list,
+ headers=headers)
+ try:
+ email.send()
+ except BadHeaderError:
+ return False
+ return True
+
+def notifySubmission(geo_object):
+ category = unicode(geo_object.subcategory)
+ subject = u'%s %s' % (_(u"New submission for"), category)
message = _(u'The new item "%s" has been submited in the category: ') % \
geo_object.name + category
message += "\n\n" + _(u"To valid, precise or unvalid this item: ")
message += settings.BASE_URL + 'admin'
message += u"\n\n--\nChimère"
- send_mail(subject, message, user_list[0], user_list)
+ return notifyStaff(subject, message)
+
+class ContactForm(forms.Form):
+ """
+ Main form for categories
+ """
+ email = forms.EmailField(label=_("Email (optional)"), required=False)
+ content = forms.CharField(label=_("Object"), widget=forms.Textarea)
class NewsAdminForm(forms.ModelForm):
"""
diff --git a/main/views.py b/main/views.py
index ce41c40..9de8f4b 100644
--- a/main/views.py
+++ b/main/views.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-# Copyright (C) 2008 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
+# Copyright (C) 2008-2010 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as
@@ -23,6 +23,7 @@ Views of the project
import datetime
+from django.utils.translation import ugettext as _
from django.shortcuts import render_to_response
from django.template import loader
from django.http import HttpResponseRedirect, HttpResponse
@@ -35,7 +36,8 @@ from chimere.main.models import Category, SubCategory, PropertyModel, Marker, \
from chimere.main.widgets import getMapJS, PointChooserWidget, \
RouteChooserWidget, URL_OSM_JS, URL_OSM_CSS
-from chimere.main.forms import MarkerForm, RouteForm, notifyStaff
+from chimere.main.forms import MarkerForm, RouteForm, ContactForm, \
+ notifySubmission, notifyStaff
def index(request):
"""
@@ -100,7 +102,7 @@ def edit(request):
# set the submited status
marker.status = 'S'
marker.save()
- notifyStaff(marker)
+ notifySubmission(marker)
return HttpResponseRedirect('/' + settings.EXTRA_URL +'submited/edit')
else:
# An unbound form
@@ -136,8 +138,9 @@ def editRoute(request):
# set the submited status
route.status = 'S'
route.save()
- notifyStaff(route)
- return HttpResponseRedirect('/' + settings.EXTRA_URL + 'submited/edit_route')
+ notifySubmission(route)
+ return HttpResponseRedirect('/' + settings.EXTRA_URL + \
+ 'submited/edit_route')
else:
# An unbound form
form = RouteForm()
@@ -176,6 +179,31 @@ def submited(request, action):
'media_path':settings.MEDIA_URL,}
return render_to_response('submited.html', response_dct)
+def contactus(request):
+ """
+ Contact page
+ """
+ form = None
+ msg = ''
+ # If the form has been submited
+ if request.method == 'POST':
+ form = ContactForm(request.POST)
+ # All validation rules pass
+ if form.is_valid():
+ response = notifyStaff(_(u"Comments/request on the map"),
+ form.cleaned_data['content'], form.cleaned_data['email'])
+ if response:
+ msg = _(u"Thank you for your contribution. It will be taken \
+into account. If you have left your email you may be contacted soon for more \
+details.")
+ else:
+ msg = _(u"Temporary error. Renew your message later.")
+ else:
+ form = ContactForm()
+ response_dct = {'actions':actions, 'action_selected':('contact',),
+ 'media_path':settings.MEDIA_URL,'contact_form':form, 'message':msg}
+ return render_to_response('contactus.html', response_dct)
+
def getDetail(request, marker_id):
'''
Get the detail for a marker