dynamicweb/alplora/views.py

67 lines
2 KiB
Python
Raw Normal View History

from django.views.generic import TemplateView
2017-03-24 03:07:15 +00:00
2017-03-24 02:59:17 +00:00
from django.utils.translation import get_language, get_language_info
2017-03-22 15:18:10 +00:00
from django.utils.translation import ugettext_lazy as _
from django.views.generic.edit import FormView
from django.contrib import messages
from django.core.urlresolvers import reverse_lazy, reverse
from django.shortcuts import render
2017-03-22 15:18:10 +00:00
from utils.forms import ContactUsForm
class IndexView(TemplateView):
2017-04-01 22:45:12 +00:00
template_name = "alplora/index.html"
2017-03-24 02:59:17 +00:00
2017-04-01 22:45:12 +00:00
def get_context_data(self, *args, **kwargs):
context = super(IndexView, self).get_context_data(**kwargs)
languages = getlanguages()
context.update(languages)
return context
class ContactView(FormView):
template_name = 'alplora/contact.html'
form_class = ContactUsForm
success_message = _('Message Successfully Sent')
def get_context_data(self, *args, **kwargs):
context = super(ContactView, self).get_context_data(**kwargs)
languages = getlanguages()
context.update(languages)
return context
2017-03-24 03:07:15 +00:00
2017-04-01 22:45:12 +00:00
def form_valid(self, form):
form.save()
form.send_email(email_to='info@alplora.ch')
messages.add_message(self.request, messages.SUCCESS, self.success_message)
return render(self.request, 'alplora/contact_success.html', {})
2017-02-16 07:15:00 +00:00
class LoginView(TemplateView):
2017-04-01 22:45:12 +00:00
template_name = "alplora/login.html"
2017-03-24 02:59:17 +00:00
2017-04-01 22:45:12 +00:00
def get_context_data(self, *args, **kwargs):
context = super(LoginView, self).get_context_data(**kwargs)
languages = getlanguages()
context.update(languages)
return context
2017-03-24 02:59:17 +00:00
def getlanguages():
2017-04-01 22:45:12 +00:00
language = get_language()
language_activate = get_language_info(language)
if language == 'de':
list_language = {
'name': 'English',
'code': 'en-us'
}
else:
list_language = {
'name': 'Deutsch',
'code': 'de'
}
return {
'language': language,
'list_language': list_language,
'language_activate': language_activate['name_local']
}