adding new tenants in main instance and listing them

This commit is contained in:
Serghei Mihai 2014-07-01 19:02:21 +02:00
parent 792ff4d4a3
commit ee906aa352
6 changed files with 51 additions and 2 deletions

7
hobo/forms.py Normal file
View File

@ -0,0 +1,7 @@
from django.forms import ModelForm
from tenant_schemas.utils import get_tenant_model
class HoboForm(ModelForm):
class Meta:
model = get_tenant_model()
fields = ['schema_name', 'domain_url']

6
hobo/manager_urls.py Normal file
View File

@ -0,0 +1,6 @@
from django.conf.urls import patterns, include, url
urlpatterns = patterns('',
url(r'^$', 'hobo.views.manager_home'),
url(r'^hobos.json$', 'hobo.views.hobos', name='hobos'),
)

View File

@ -0,0 +1,16 @@
{% extends "hobo/base.html" %}
{% load i18n %}
{% load url from future %}
{% block appbar %}
<h2>{% trans 'Add instance' %}</h2>
{% endblock %}
{% block content %}
<form class="small" method="post" >
{% csrf_token %}
{{ form.as_p }}
<button>{% trans 'Add' %}</button>
</form>
{% endblock %}

View File

@ -31,6 +31,8 @@ TEMPLATE_LOADERS = (
'django.template.loaders.app_directories.Loader',
)
PUBLIC_SCHEMA_URLCONF = 'hobo.manager_urls'
MULTITENANT_TEMPLATE_DIRS = (
os.environ.get('MULTITENANT_TEMPLATE_DIRS', '.'),
)

View File

@ -7,7 +7,7 @@ urlpatterns = patterns('',
url(r'^$', 'hobo.views.home', name='home'),
url(r'^environment/', include('hobo.environment.urls')),
url(r'^hobos.json$', 'hobo.views.hobos'),
url(r'^hobos.json$', 'hobo.views.hobo'),
url(r'^admin/', include(admin.site.urls)),
)

View File

@ -3,6 +3,7 @@ import json
from django.http import HttpResponse
from django.utils.translation import ugettext as _
from django.views.generic.base import TemplateView
from django.views.generic.edit import CreateView
from .environment.utils import Zone, get_operational_services
@ -21,8 +22,25 @@ class Home(TemplateView):
home = Home.as_view()
class ManagerHome(CreateView):
template_name = 'hobo/manager_home.html'
success_url = '.'
def hobos(request, **kwargs):
def get_form_class(self):
from .forms import HoboForm
return HoboForm
manager_home = ManagerHome.as_view()
def hobos(request, *args, **kwargs):
from tenant_schemas.utils import get_tenant_model, get_public_schema_name
response = HttpResponse(content_type='application/json')
tenants = [{'name': tenant.schema_name, 'url': tenant.domain_url} \
for tenant in get_tenant_model().objects.all()]
json.dump(tenants, response)
return response
def hobo(request, **kwargs):
# The hobos URL is supposed to return a list of hobo websites, this
# dummy implementation makes it possible to point deployment agents to
# a single instance, that will announce itself as the only hobo around.