2014-07-26 13:00:21 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2014-07-27 23:34:23 +02:00
|
|
|
|
2014-07-28 15:13:55 +02:00
|
|
|
from django.views.generic import TemplateView, FormView, CreateView, UpdateView
|
2014-07-27 23:34:23 +02:00
|
|
|
from django.contrib.auth.decorators import login_required
|
|
|
|
from django.utils.decorators import method_decorator
|
|
|
|
from django.contrib.auth.views import login, logout
|
2014-07-26 13:00:21 +02:00
|
|
|
|
2014-07-28 15:13:55 +02:00
|
|
|
from frontend.forms import ExampleForm
|
|
|
|
|
2014-07-27 23:34:23 +02:00
|
|
|
FRONTEND_PAGE_NAME = 'Citavi Mapper'
|
|
|
|
|
2014-07-28 15:13:55 +02:00
|
|
|
# Login wrapper functions
|
2014-07-27 23:34:23 +02:00
|
|
|
def login_wrap(*args, **kwargs):
|
|
|
|
kwargs['extra_context'] = {
|
|
|
|
'page': {
|
|
|
|
'name': FRONTEND_PAGE_NAME,
|
|
|
|
'title': 'Login'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return login(*args, **kwargs)
|
|
|
|
|
|
|
|
def logout_wrap(*args, **kwargs):
|
|
|
|
kwargs['extra_context'] = {
|
|
|
|
'page': {
|
|
|
|
'name': FRONTEND_PAGE_NAME,
|
|
|
|
'title': 'Logout'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return logout(*args, **kwargs)
|
|
|
|
|
|
|
|
|
2014-07-28 15:13:55 +02:00
|
|
|
# My base classes for views
|
|
|
|
class MyTemplateView(TemplateView):
|
2014-07-27 23:34:23 +02:00
|
|
|
template_name = 'base.html'
|
|
|
|
page_name = FRONTEND_PAGE_NAME
|
|
|
|
page_title = 'BASE'
|
|
|
|
|
|
|
|
def get_page_data(self):
|
|
|
|
return {
|
|
|
|
u'name': self.page_name,
|
|
|
|
u'title': self.page_title
|
|
|
|
}
|
2014-07-26 13:00:21 +02:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
2014-07-27 23:34:23 +02:00
|
|
|
kwargs[u'page'] = self.get_page_data()
|
2014-07-28 15:13:55 +02:00
|
|
|
return super(MyTemplateView, self).get_context_data(**kwargs)
|
|
|
|
|
|
|
|
class MyFormView(FormView):
|
|
|
|
template_name = 'base.html'
|
|
|
|
page_name = FRONTEND_PAGE_NAME
|
|
|
|
page_title = 'BASE'
|
|
|
|
|
|
|
|
def get_page_data(self):
|
|
|
|
return {
|
|
|
|
u'name': self.page_name,
|
|
|
|
u'title': self.page_title
|
|
|
|
}
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
kwargs[u'page'] = self.get_page_data()
|
|
|
|
return super(MyFormView, self).get_context_data(**kwargs)
|
2014-07-27 23:34:23 +02:00
|
|
|
|
|
|
|
class LoggedInMixin(object):
|
|
|
|
@method_decorator(login_required)
|
|
|
|
def dispatch(self, *args, **kwargs):
|
|
|
|
return super(LoggedInMixin, self).dispatch(*args, **kwargs)
|
|
|
|
|
2014-07-28 15:13:55 +02:00
|
|
|
class ProtectedTemplateView(LoggedInMixin, MyTemplateView):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class ProtectedFormView(LoggedInMixin, MyFormView):
|
2014-07-27 23:34:23 +02:00
|
|
|
pass
|
|
|
|
|
2014-07-28 15:13:55 +02:00
|
|
|
# Actual Views
|
|
|
|
|
|
|
|
class IndexView(ProtectedTemplateView):
|
2014-07-27 23:34:23 +02:00
|
|
|
template_name = 'index.html'
|
|
|
|
page_title = 'Index'
|
|
|
|
|
2014-07-28 15:13:55 +02:00
|
|
|
class RegisterView(MyTemplateView):
|
2014-07-27 23:34:23 +02:00
|
|
|
template_name = 'register.html'
|
|
|
|
page_title = 'Register'
|
2014-07-28 15:13:55 +02:00
|
|
|
|
|
|
|
class ProjectContextView(ProtectedFormView):
|
|
|
|
template_name = 'projectcontext.html'
|
|
|
|
page_title = 'Project Contexts'
|
|
|
|
form_class = ExampleForm
|
|
|
|
success_url = '/project/thanks'
|
|
|
|
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
super(ProjectContextView, self).__init__(**kwargs)
|
|
|
|
print(self.__class__.__mro__)
|
|
|
|
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
pass
|