0001-manager-remove-unused-manager-views-code-40153.patch
hobo/environment/templates/environment/tenant_confirm_delete.html | ||
---|---|---|
1 |
{% extends "hobo/base.html" %} |
|
2 |
{% load i18n %} |
|
3 | ||
4 |
{% block content %} |
|
5 |
<form action="{% url 'delete-tenant' object.id %}" method="post"> |
|
6 |
{% csrf_token %} |
|
7 |
<p> |
|
8 |
{% blocktrans with name=object.schema_name %} |
|
9 |
Are you sure you want to delete "{{ name }}"? |
|
10 |
{% endblocktrans %} |
|
11 |
</p> |
|
12 |
<div class="right"> |
|
13 |
<button type="button" class="cancel">{% trans 'Cancel' %}</button> |
|
14 |
<input type="submit" value="{% trans 'Delete' %}" /> |
|
15 |
</div> |
|
16 |
</form> |
|
17 |
{% endblock %} |
hobo/manager_urls.py | ||
---|---|---|
1 |
from django.conf.urls import patterns, include, url |
|
2 | ||
3 |
urlpatterns = patterns('', |
|
4 |
url(r'^$', 'hobo.views.manager_home', name='manager-home'), |
|
5 |
url(r'^update/(?P<pk>\d+)$', 'hobo.views.update_tenant', name='update-tenant'), |
|
6 |
url(r'^delete/(?P<pk>\d+)$', 'hobo.views.delete_tenant', name='delete-tenant'), |
|
7 |
url(r'^hobos.json$', 'hobo.views.hobos', name='hobos'), |
|
8 |
) |
hobo/templates/hobo/manager_home.html | ||
---|---|---|
1 |
{% extends "hobo/base.html" %} |
|
2 |
{% load i18n %} |
|
3 | ||
4 |
{% block appbar %} |
|
5 |
<h2>{% trans 'Add instance' %}</h2> |
|
6 |
{% endblock %} |
|
7 | ||
8 |
{% block content %} |
|
9 |
<form class="small" method="post" > |
|
10 |
{% csrf_token %} |
|
11 |
{{ form.as_p }} |
|
12 |
<button>{% trans 'Add' %}</button> |
|
13 |
</form> |
|
14 | ||
15 |
<h2>{% trans 'Tenants' %}</h2> |
|
16 |
{% for tenant in tenants_list %} |
|
17 |
<div> |
|
18 |
<a href="{% url 'delete-tenant' tenant.object.id %}" class="delete-tenant" title="{% trans 'Delete tenant' %}"></a> |
|
19 |
<h3>{{ tenant.object }}</h3> |
|
20 |
<form class="small" method="post" action="{% url 'update-tenant' tenant.object.pk %}" > |
|
21 |
{% csrf_token %} |
|
22 |
{{ tenant.form.as_p }} |
|
23 |
<button class="enable-on-change" disabled="disabled">{% trans 'Save' %}</button> |
|
24 |
</form> |
|
25 |
</div> |
|
26 |
{% endfor %} |
|
27 |
{% endblock %} |
|
28 | ||
29 |
{% block page-end %} |
|
30 |
<script> |
|
31 |
$(function() { |
|
32 |
$('a.delete-tenant').click(function() { |
|
33 |
var url = $(this).attr('href'); |
|
34 |
$.get($(this).attr('href'), function(data) { |
|
35 |
var form = $(data).find('form'); |
|
36 |
$(form).dialog({modal: true, title: '{% trans "Tenant deletion" %}', width: 'auto'}); |
|
37 |
$('.cancel', form).click(function() {$(form).dialog('close')}); |
|
38 |
}); |
|
39 |
event.preventDefault(); |
|
40 |
}); |
|
41 | ||
42 |
$('button.enable-on-change').each(function(index, element) { |
|
43 |
var button = $(element); |
|
44 |
$(element).parent('form').find('input').on('change keydown', |
|
45 |
function() {$(button).prop('disabled', null);}); |
|
46 |
}); |
|
47 | ||
48 |
}) |
|
49 |
</script> |
|
50 |
{% endblock %} |
hobo/views.py | ||
---|---|---|
33 | 33 |
def get_context_data(self, **kwargs): |
34 | 34 |
context = super(Home, self).get_context_data(**kwargs) |
35 | 35 |
context['services'] = [x for x in get_installed_services() if not x.secondary] |
36 | 36 |
context['has_authentic'] = bool(Authentic.objects.filter(secondary=False)) |
37 | 37 |
return context |
38 | 38 | |
39 | 39 |
home = admin_required(Home.as_view()) |
40 | 40 | |
41 |
class ManagerHome(edit.CreateView): |
|
42 |
template_name = 'hobo/manager_home.html' |
|
43 |
form_class = HoboForm |
|
44 | ||
45 |
def get_success_url(self): |
|
46 |
return reverse('manager-home') |
|
47 | ||
48 |
def get_context_data(self, **kwargs): |
|
49 |
from tenant_schemas.utils import get_public_schema_name |
|
50 |
context = super(ManagerHome, self).get_context_data(**kwargs) |
|
51 |
tenants_list = () |
|
52 |
for obj in get_tenant_model().objects.exclude(schema_name=get_public_schema_name()): |
|
53 |
f = HoboUpdateForm(instance=obj, auto_id='%s_%%s' % obj.pk) |
|
54 |
tenants_list += ({'object': obj, 'form': f},) |
|
55 |
context['tenants_list'] = tenants_list |
|
56 |
return context |
|
57 | ||
58 |
def form_valid(self, form): |
|
59 |
response = super(ManagerHome, self).form_valid(form) |
|
60 |
self.object.create_schema(True) |
|
61 |
return response |
|
62 | ||
63 |
manager_home = admin_required(ManagerHome.as_view()) |
|
64 | ||
65 |
class ManagerUpdateTenant(edit.UpdateView): |
|
66 |
model = get_tenant_model() |
|
67 |
template_name = 'hobo/manager_home.html' |
|
68 |
form_class = HoboUpdateForm |
|
69 | ||
70 |
def get_success_url(self): |
|
71 |
return reverse('manager-home') |
|
72 | ||
73 |
def form_valid(self, form): |
|
74 |
response = super(ManagerUpdateTenant, self).form_valid(form) |
|
75 |
self.object.create_schema(True) |
|
76 |
return response |
|
77 | ||
78 |
update_tenant = admin_required(ManagerUpdateTenant.as_view()) |
|
79 | ||
80 |
class ManagerDeleteTenant(edit.DeleteView): |
|
81 |
template_name = 'environment/tenant_confirm_delete.html' |
|
82 |
model = get_tenant_model() |
|
83 | ||
84 |
def get_success_url(self): |
|
85 |
return reverse('manager-home', self.object.id) |
|
86 | ||
87 |
delete_tenant = admin_required(ManagerDeleteTenant.as_view()) |
|
88 | ||
89 |
def hobos(request, *args, **kwargs): |
|
90 |
response = HttpResponse(content_type='application/json') |
|
91 |
tenants = [{'name': tenant.schema_name, 'url': tenant.domain_url} \ |
|
92 |
for tenant in get_tenant_model().objects.all()] |
|
93 |
json.dump(tenants, response) |
|
94 |
return response |
|
95 | 41 | |
96 | 42 |
def hobo(request, **kwargs): |
97 | 43 |
# The hobos URL is supposed to return a list of hobo websites, this |
98 | 44 |
# dummy implementation makes it possible to point deployment agents to |
99 | 45 |
# a single instance, that will announce itself as the only hobo around. |
100 | 46 |
response = HttpResponse(content_type='application/json') |
101 | 47 |
json.dump([request.build_absolute_uri('/')], response) |
102 | 48 |
return response |
103 |
- |