summaryrefslogtreecommitdiffstats
path: root/base/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'base/views.py')
-rw-r--r--base/views.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/base/views.py b/base/views.py
index 60f00ef..8a49bea 100644
--- a/base/views.py
+++ b/base/views.py
@@ -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)
+