citavi_mapper/frontend/views.py

62 lines
1.6 KiB
Python

# -*- coding: utf-8 -*-
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.views.generic import TemplateView
from django.contrib.auth.views import login, logout
FRONTEND_PAGE_NAME = 'Citavi Mapper'
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)
class BaseView(TemplateView):
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(self, request, **kwargs):
return super(BaseView, self).get(request, **kwargs)
def get_context_data(self, **kwargs):
kwargs[u'page'] = self.get_page_data()
return super(BaseView, self).get_context_data(**kwargs)
class LoggedInMixin(object):
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(LoggedInMixin, self).dispatch(*args, **kwargs)
class ProtectedSiteView(LoggedInMixin, BaseView):
pass
class IndexView(ProtectedSiteView):
template_name = 'index.html'
page_title = 'Index'
class RegisterView(BaseView):
template_name = 'register.html'
page_title = 'Register'