enable admin (public/tenants)

This commit is contained in:
Thomas Noel 2014-03-16 16:53:45 +00:00
parent c6574ff3ae
commit db40a4a857
11 changed files with 241 additions and 10 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
settings.ini
static
*.pyo
*.pyc

View File

@ -2,6 +2,13 @@ univnautes-idp : IdP multi-tenants pour UnivNautes
cp settings.ini.example /somewhere/settings.ini
export UNIVNAUTES_IDP_SETTINGS_INI=/somewhere/settings.ini
python manage.py sync_schemas --shared --noinput
python manage.py create-tenant xyz.univnautes-idp.dev.entrouvert.org xyz
# creation du schema public
python manage.py sync_schemas --shared --noinput
python manage.py migrate_schemas
python manage.py create-tenant univnautes-idp.dev.entrouvert.org public
python manage.py createsuperuser -s public
python manage.py create-tenant xyz.univnautes-idp.dev.entrouvert.org xyz
python manage.py createsuperuser -s xyz

0
base/__init__.py Normal file
View File

13
base/admin.py Normal file
View File

@ -0,0 +1,13 @@
from django.contrib import admin
from entrouvert.djommon.multitenant.models import Tenant, ClientSetting
class TenantAdmin(admin.ModelAdmin):
list_display = ('schema_name', 'name', 'domain_url', 'is_active')
class ClientSettingAdmin(admin.ModelAdmin):
list_display = ('tenant', 'name', 'value')
admin.site.register(Tenant, TenantAdmin)
admin.site.register(ClientSetting, ClientSettingAdmin)

3
base/models.py Normal file
View File

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

56
base/templates/base.html Normal file
View File

@ -0,0 +1,56 @@
{% load i18n %}<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="{{ STATIC_URL }}authentic2/css/style.css" />
<link rel="stylesheet" href="{{ STATIC_URL }}jquery/css/jquery-ui.custom.css" />
<link rel="stylesheet" href="{{ STATIC_URL }}ulx/css/ulx.css" />
<title>{% block title %}User test{% endblock %}</title>
{{ openid_meta }}
{% block extra_scripts %}
{% endblock %}
</head>
<body {% block bodyargs %}{% endblock %} >
<div id="wrap">
<a href="/"><div id="header">
{% block header %}
<span>Tenant</span>
<h1>{{request.tenant.name|default:request.tenant.schema_name}}</h1>
{% endblock %}
</div></a>
<div id="splash"></div>
<div id="content">
{% if request.user.is_authenticated %}
<div id="user">
<p>
{% blocktrans with request.user.get_full_name as username %}Hello {{ username }}.{% endblocktrans %}
</p>
</div>
{% endif %}
{% block messages %}
{% if messages %}
<ul class="messages">
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
{% endblock %}
{% block content %}{% endblock %}
</div>
<div id="footer">
{% block footer %}
Copyright &copy; 2014 Entr'ouvert
&mdash;
Powered by <strong>Authentic 2</strong> the Versatile Identity Management Server
{% endblock %}
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,6 @@
{% extends 'base.html' %}
{% load i18n %}
{% block content %}
<h1>Gestion des tenants</h1>
{% endblock %}

1
base/views.py Normal file
View File

@ -0,0 +1 @@
# Create your views here.

123
univnautes_idp/dashboard.py Normal file
View File

@ -0,0 +1,123 @@
"""
This file was generated with the customdashboard management command, it
contains the two classes for the main dashboard and app index dashboard.
You can customize these classes as you want.
To activate your index dashboard add the following to your settings.py::
ADMIN_TOOLS_INDEX_DASHBOARD = 'authentic2.dashboard.CustomIndexDashboard'
And to activate the app index dashboard::
ADMIN_TOOLS_APP_INDEX_DASHBOARD = 'authentic2.dashboard.CustomAppIndexDashboard'
"""
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse
from admin_tools.dashboard import modules, Dashboard, AppIndexDashboard
from admin_tools.utils import get_admin_site_name
class CustomIndexDashboard(Dashboard):
"""
Custom index dashboard for authentic2.
"""
def init_with_context(self, context):
site_name = get_admin_site_name(context)
tenant = context.get('request').tenant.schema_name
# append a link list module for "quick links"
self.children.append(modules.LinkList(
_('Quick links'),
layout='inline',
draggable=False,
deletable=False,
collapsible=False,
children=[
[_('Return to site'), '/'],
[_('Change password'),
reverse('%s:password_change' % site_name)],
[_('Log out'), reverse('%s:logout' % site_name)],
]
))
# append an app list module for "Applications"
self.children.append(modules.ModelList(
_('Users and groups'),
models=('authentic2.models.User',
'django.contrib.auth.models.*'),
))
if tenant == 'public':
self.children.append(modules.ModelList(
_('Tenants'),
models=(
'entrouvert.djommon.multitenant.models.*',
),
))
else:
self.children.append(modules.ModelList(
_('Services'),
models=(
'authentic2.saml.models.LibertyProvider',
'authentic2.saml.models.SPOptionsIdPPolicy',
'authentic2.saml.models.IdPOptionsSPPolicy',
'authentic2.idp.models.AttributePolicy',
'authentic2.attribute_aggregator.models.AttributeList',
'authentic2.attribute_aggregator.models.AttributeItem',
'authentic2.attribute_aggregator.models.AttributeSource',
),
))
# append a recent actions module
self.children.append(modules.RecentActions(_('Recent Actions'), 5))
# append another link list module for "support".
self.children.append(modules.LinkList(
_('Support'),
children=[
{
'title': _('Authentic2 documentation'),
'url': 'http://pythonhosted.org/authentic2/',
'external': True,
},
{
'title': _('Authentic2 project'),
'url': 'http://dev.entrouvert.org/projects/authentic/',
'external': True,
},
{
'title': _('Authentic Mailing List'),
'url': 'http://listes.entrouvert.com/info/authentic',
'external': True,
},
]
))
class CustomAppIndexDashboard(AppIndexDashboard):
"""
Custom app index dashboard for authentic2.
"""
# we disable title because its redundant with the model list module
title = ''
def __init__(self, *args, **kwargs):
AppIndexDashboard.__init__(self, *args, **kwargs)
# append a model list module and a recent actions module
self.children += [
modules.ModelList(self.app_title, self.models),
modules.RecentActions(
_('Recent Actions'),
include_list=self.get_app_content_types(),
limit=5
)
]
def init_with_context(self, context):
"""
Use this method if you need to access the request context.
"""
return super(CustomAppIndexDashboard, self).init_with_context(context)

View File

@ -131,7 +131,6 @@ MIDDLEWARE_CLASSES = (
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'univnautes_idp.urls'
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'univnautes_idp.wsgi.application'
@ -140,8 +139,13 @@ TEMPLATE_DIRS = tuple(config.get('dirs', 'template_dirs').split())
MULTITENANT_TEMPLATE_DIRS = tuple(config.get('dirs', 'multitenant_template_dirs').split())
SHARED_APPS = (
'base',
'tenant_schemas',
'entrouvert.djommon.multitenant',
'admin_tools',
'admin_tools.theming',
'admin_tools.menu',
'admin_tools.dashboard',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.messages',
@ -152,6 +156,10 @@ SHARED_APPS = (
)
TENANT_APPS = (
'admin_tools',
'admin_tools.theming',
'admin_tools.menu',
'admin_tools.dashboard',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.messages',
@ -159,10 +167,6 @@ TENANT_APPS = (
'django.contrib.staticfiles',
'django.contrib.contenttypes',
'south',
'admin_tools',
'admin_tools.theming',
'admin_tools.menu',
'admin_tools.dashboard',
'registration',
'authentic2.nonce',
'authentic2.saml',
@ -180,6 +184,11 @@ INSTALLED_APPS = SHARED_APPS + TENANT_APPS
INSTALLED_APPS += ('tenant_schemas', 'entrouvert.djommon.multitenant',)
TENANT_MODEL = 'multitenant.Tenant'
PUBLIC_SCHEMA_NAME = 'public'
ROOT_URLCONF = 'univnautes_idp.urls'
PUBLIC_SCHEMA_URLCONF = 'univnautes_idp.urls_public'
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'
@ -267,9 +276,9 @@ ACCOUNT_ACTIVATION_DAYS = 3
PASSWORD_RESET_TIMEOUT_DAYS = 3
# Admin tools
ADMIN_TOOLS_INDEX_DASHBOARD = 'authentic2.dashboard.CustomIndexDashboard'
ADMIN_TOOLS_APP_INDEX_DASHBOARD = 'authentic2.dashboard.CustomAppIndexDashboard'
ADMIN_TOOLS_MENU = 'authentic2.menu.CustomMenu'
ADMIN_TOOLS_INDEX_DASHBOARD = 'univnautes_idp.dashboard.CustomIndexDashboard'
ADMIN_TOOLS_APP_INDEX_DASHBOARD = 'univnautes_idp.dashboard.CustomAppIndexDashboard'
#ADMIN_TOOLS_MENU = 'authentic2.menu.CustomMenu'
# AUTH systels
AUTH_SAML2 = False

View File

@ -0,0 +1,12 @@
from django.conf.urls import patterns, url, include
from django.views.generic import TemplateView
from authentic2.urls import urlpatterns as authentic2_urlpatterns
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^$', TemplateView.as_view(template_name="univnautes-idp/homepage.html")),
url(r'^admin/', include(admin.site.urls)),
url(r'^admin_tools/', include('admin_tools.urls')),
)