2012-03-02 16:16:20 +01:00
|
|
|
from django.shortcuts import render_to_response
|
|
|
|
from django.template import RequestContext
|
2012-03-05 10:55:21 +01:00
|
|
|
from django.conf import settings
|
2012-03-05 11:44:26 +01:00
|
|
|
from django.contrib import messages
|
2012-03-05 10:55:21 +01:00
|
|
|
from django.utils.translation import ugettext as _
|
2012-03-05 11:44:26 +01:00
|
|
|
from django.http import HttpResponseRedirect
|
2012-03-05 12:06:00 +01:00
|
|
|
from django.core.mail import mail_admins
|
2012-03-02 16:16:20 +01:00
|
|
|
|
2012-03-05 14:19:38 +01:00
|
|
|
from accounts.models import set_lang
|
2012-03-05 10:55:21 +01:00
|
|
|
from accounts.forms import ProfileForm, UserForm, ContactForm
|
2012-03-02 16:16:20 +01:00
|
|
|
|
|
|
|
def profile(request):
|
|
|
|
|
|
|
|
if request.method == 'POST':
|
2012-03-02 16:38:41 +01:00
|
|
|
form = ProfileForm(request.POST, instance = request.user.get_profile())
|
|
|
|
userform = UserForm(request.POST, instance = request.user)
|
|
|
|
if form.is_valid() and userform.is_valid():
|
|
|
|
form.save()
|
|
|
|
userform.save()
|
2012-03-05 14:19:38 +01:00
|
|
|
set_lang(request.user, request = request, user = request.user)
|
|
|
|
# Need to redirect to allow language change
|
|
|
|
return HttpResponseRedirect('/accounts/profile/')
|
2012-03-02 16:16:20 +01:00
|
|
|
else:
|
|
|
|
form = ProfileForm(instance = request.user.get_profile())
|
2012-03-02 16:38:41 +01:00
|
|
|
userform = UserForm(instance = request.user)
|
2012-03-02 16:16:20 +01:00
|
|
|
|
2012-03-02 16:38:41 +01:00
|
|
|
return render_to_response('profile.html', RequestContext(request, {
|
|
|
|
'form': form,
|
|
|
|
'userform': userform,
|
|
|
|
}))
|
2012-03-05 10:55:21 +01:00
|
|
|
|
|
|
|
def contact(request):
|
|
|
|
if request.method == 'POST':
|
|
|
|
form = ContactForm(request.POST)
|
2012-03-05 11:44:26 +01:00
|
|
|
if form.is_valid():
|
2012-03-05 12:06:00 +01:00
|
|
|
mail_admins(
|
|
|
|
form.cleaned_data['subject'],
|
|
|
|
'Message from %s <%s>:\n\n%s' % (
|
|
|
|
form.cleaned_data['name'],
|
|
|
|
form.cleaned_data['email'],
|
|
|
|
form.cleaned_data['message']
|
|
|
|
))
|
2012-03-05 11:44:26 +01:00
|
|
|
messages.add_message(request, messages.INFO, _('Message has been sent to administrator.'))
|
|
|
|
return HttpResponseRedirect('/')
|
2012-03-05 10:55:21 +01:00
|
|
|
else:
|
2012-03-05 11:55:50 +01:00
|
|
|
initial = {}
|
|
|
|
if request.user.is_authenticated():
|
|
|
|
initial['name'] = request.user.get_full_name()
|
|
|
|
initial['email'] = request.user.email
|
2012-03-05 11:56:46 +01:00
|
|
|
if 'subject' in request.GET:
|
|
|
|
initial['subject'] = request.GET['subject']
|
2012-03-05 11:55:50 +01:00
|
|
|
form = ContactForm(initial = initial)
|
2012-03-05 10:55:21 +01:00
|
|
|
|
|
|
|
return render_to_response('contact.html', RequestContext(request, {
|
|
|
|
'form': form,
|
|
|
|
'title': '%s @ %s' % (_('Contact'), settings.SITE_TITLE),
|
|
|
|
}))
|