tenant creation form
This commit is contained in:
parent
f56508132d
commit
371245abb5
|
@ -0,0 +1,15 @@
|
|||
{% extends 'base.html' %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Nouveau tenant</h1>
|
||||
<p>
|
||||
Indiquer ci-dessous le nom du nouveau tenant choisi.<br />
|
||||
Utilisez uniquement des lettres minuscules, des chiffres et le trait d'union.
|
||||
</p>
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<input type="submit" value="Créer" />
|
||||
</form>
|
||||
{% endblock %}
|
|
@ -3,7 +3,19 @@
|
|||
|
||||
{% block content %}
|
||||
<h1>Gestion des tenants</h1>
|
||||
<ul>
|
||||
{% for obj in object_list %}
|
||||
{% if obj.schema_name != "public" %}
|
||||
<li><a href="//{{ obj.domain_url }}">{{ obj.domain_url }}</a> — tenant «{{obj}}»</li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<h1>Demander un tenant</h1>
|
||||
<p>
|
||||
<a href="/admin">Administration</a>
|
||||
<a href="/create/">Création d'un tenant</a>
|
||||
</p>
|
||||
<h1>Administration</h1>
|
||||
<p>
|
||||
<a href="/admin/">Interface d'administration complète</a> (technique)
|
||||
</p>
|
||||
{% endblock %}
|
||||
|
|
|
@ -1 +1,27 @@
|
|||
# Create your views here.
|
||||
import subprocess
|
||||
from django.views.generic.edit import FormView
|
||||
from django.contrib import messages
|
||||
from django import forms
|
||||
from entrouvert.djommon.multitenant.models import Tenant
|
||||
|
||||
CREATION_SCRIPT = '/home/thomas/univnautes-idp/create-dirty-tenant.py'
|
||||
|
||||
class TenantCreateForm(forms.Form):
|
||||
schema_name = forms.RegexField(regex='^[a-z0-9_-]+$',
|
||||
required=True,
|
||||
max_length=16)
|
||||
|
||||
class TenantCreateView(FormView):
|
||||
template_name = 'univnautes-idp/create-tenant.html'
|
||||
form_class = TenantCreateForm
|
||||
success_url = '/'
|
||||
|
||||
def form_valid(self, form):
|
||||
schema_name = form.cleaned_data['schema_name']
|
||||
r = subprocess.call([CREATION_SCRIPT, schema_name])
|
||||
if r:
|
||||
messages.error(self.request, 'cannot create %s tenant (error %r)' % (schema_name, r))
|
||||
else:
|
||||
messages.info(self.request, '%s tenant created' % schema_name)
|
||||
return super(TenantCreateView, self).form_valid(form)
|
||||
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
#!/bin/sh -e
|
||||
|
||||
cd /home/thomas/univnautes-idp
|
||||
. /home/thomas/venv/bin/activate
|
||||
export UNIVNAUTES_IDP_SETTINGS_INI=/home/thomas/univnautes-idp/settings.ini.example
|
||||
|
||||
TENANT=$(echo "$1" | tr -dc a-z0-9_-)
|
||||
if [ x"$1" != x"$TENANT" ]
|
||||
then
|
||||
echo $1 not a valid tenant name
|
||||
exit 1
|
||||
fi
|
||||
|
||||
python << EOF
|
||||
import os, sys
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "univnautes_idp.settings")
|
||||
from entrouvert.djommon.multitenant.models import Tenant
|
||||
if Tenant.objects.filter(schema_name="${TENANT}"):
|
||||
print >> sys.stderr, "tenant ${TENANT} already exists"
|
||||
sys.exit(1)
|
||||
EOF
|
||||
|
||||
echo ""
|
||||
echo "creating tenant..."
|
||||
echo ""
|
||||
python manage.py create-tenant $TENANT.univnautes-idp.dev.entrouvert.org $TENANT
|
||||
|
||||
echo ""
|
||||
echo "creating 'admin' user in this tenant"
|
||||
echo ""
|
||||
python << EOF
|
||||
import os, sys
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "univnautes_idp.settings")
|
||||
from django.db import connection
|
||||
from django.contrib.auth.models import User
|
||||
connection.set_schema("${TENANT}")
|
||||
u=User(username='admin')
|
||||
u.set_password("${TENANT}")
|
||||
u.is_staff=True
|
||||
u.is_superuser=True
|
||||
u.save()
|
||||
print 'users:', User.objects.all()
|
||||
EOF
|
||||
|
||||
echo ""
|
||||
echo "tenant ${TENANT} created"
|
|
@ -1,12 +1,19 @@
|
|||
from django.conf.urls import patterns, url, include
|
||||
from django.views.generic import TemplateView, RedirectView
|
||||
from django.views.generic import ListView, CreateView, RedirectView
|
||||
from authentic2.urls import urlpatterns as authentic2_urlpatterns
|
||||
from entrouvert.djommon.multitenant.models import Tenant
|
||||
from base.views import TenantCreateView
|
||||
|
||||
from django.contrib import admin
|
||||
admin.autodiscover()
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url(r'^$', TemplateView.as_view(template_name='univnautes-idp/homepage.html')),
|
||||
url(r'^$', ListView.as_view(
|
||||
model=Tenant,
|
||||
template_name='univnautes-idp/homepage.html')
|
||||
),
|
||||
#url(r'^create/$', CreateView.as_view(model=Tenant)),
|
||||
url(r'^create/$', TenantCreateView.as_view()),
|
||||
url(r'^admin/', include(admin.site.urls)),
|
||||
url(r'^admin_tools/', include('admin_tools.urls')),
|
||||
url(r'^logout/$', RedirectView.as_view(url='/admin/logout'), name='auth_logout'),
|
||||
|
|
Reference in New Issue