diff --git a/context_processors.py b/context_processors.py index 0f6834c..4418487 100644 --- a/context_processors.py +++ b/context_processors.py @@ -36,3 +36,13 @@ """ This function is a wrapper to render the Mailman Theme Variable from Settings """ return {"MAILMAN_THEME":MAILMAN_THEME} + +def extend_ajax(request): + """ This function checks if the request was made using AJAX + Using Ajax template_extend will base_ajax.html else it will be base.html + """ + if request.is_ajax(): + extend_template = "mailman-django/base_ajax.html" + else: + extend_template = "mailman-django/base.html" + return {"extend_template":extend_template} diff --git a/templates/mailman-django/base_ajax.html b/templates/mailman-django/base_ajax.html new file mode 100644 index 0000000..75ddf24 --- /dev/null +++ b/templates/mailman-django/base_ajax.html @@ -0,0 +1,3 @@ + +{% load i18n %} + {% block header%}{% endblock %} diff --git a/templates/mailman-django/domain_index.html b/templates/mailman-django/domain_index.html new file mode 100644 index 0000000..3d943bc --- /dev/null +++ b/templates/mailman-django/domain_index.html @@ -0,0 +1,41 @@ +{% extends "mailman-django/base.html" %} +{% load i18n %} + +{% block heading %} + {% trans "Add a new Domain" %} +{% endblock %} + +{% block smallBoxLeft %} + {% for domain in domains %} +
+
{{ domain.contact_address }}
+ +
+ {% endfor %} +{% endblock %} + +{% block header %} +
+
{% trans "About" %}
+ This site allows to register a new Domain, due to restriction in the REST API we can't delete them here yet. Please modify the Mailman DB directly if you need to remove a Domain. If interested take a look at the Launchapd Bug Report +

+
+{% endblock %} +{% block actionButtonsList %} + + +{% endblock %} diff --git a/templates/mailman-django/domain_new.html b/templates/mailman-django/domain_new.html new file mode 100644 index 0000000..15c621e --- /dev/null +++ b/templates/mailman-django/domain_new.html @@ -0,0 +1,18 @@ +{% extends extend_template %} +{% load i18n %} + +{% block heading %} + {% trans "Add a new Domain" %} +{% endblock %} + +{% block header %} +
+
{% trans "New Domain" %}
+
+ {{ form.as_div }} +
+ +
+
+
+{% endblock %} diff --git a/templates/mailman-django/domains.html b/templates/mailman-django/domains.html deleted file mode 100644 index 346b6ba..0000000 --- a/templates/mailman-django/domains.html +++ /dev/null @@ -1,47 +0,0 @@ -{% extends "mailman-django/base.html" %} -{% load i18n %} - -{% block heading %} - {% trans "Add a new Domain" %} -{% endblock %} - -{% block smallBoxLeft %} - {% for domain in domains %} -
-
{{ domain.contact_address }}
- -
- {% endfor %} -{% endblock %} - -{% block header %} -
-
{% trans "About" %}
- This site allows to register a new Domain, due to restriction in the REST API we can't delete them here yet. Please modify the Mailman DB directly if you need to remove a Domain. If interested take a look at the Launchapd Bug Report -

-
-{% endblock %} -{% block actionButtonsList %} - - -{% endblock %} diff --git a/urls.py b/urls.py index 226418f..ae5c902 100644 --- a/urls.py +++ b/urls.py @@ -25,7 +25,8 @@ (r'^$', 'list_index'), url(r'^logout/$', 'logout', name = 'logout'), url(r'^administration/$', 'administration', name = 'administration'), - url(r'^domains/$', 'domains', name = 'domains'), + url(r'^domains/$', 'domain_index', name = 'domain_index'), + url(r'^domains/new/$', 'domain_new', name = 'domain_new'), url(r'^lists/$', 'list_index', name = 'list_index'), url(r'^lists/new/$', 'list_new', name = 'list_new'), url(r'^lists/(?P[^/]+)/$', 'list_summary', name = 'list_summary'), #PUBLIC diff --git a/views.py b/views.py index c540bd9..2bfe067 100644 --- a/views.py +++ b/views.py @@ -79,12 +79,22 @@ return _login_decorator @login_required -def domains(request, template = 'mailman-django/domains.html'): - message="" - error="" +def domain_index(request, template = 'mailman-django/domain_index.html'): + try: + c = Client('http://localhost:8001/3.0', API_USER, API_PASS) + existing_domains = c.domains + except AttributeError, e: + return render_to_response('mailman-django/errors/generic.html', + {'error': "REST API not found / Offline"}, + context_instance=RequestContext(request)) + return render_to_response(template, {'domains':existing_domains,}, + context_instance=RequestContext(request)) + +@login_required +def domain_new(request, template = 'mailman-django/domain_new.html'): + message = None if request.method == 'POST': form = DomainNew(request.POST) - existing_domains = None try: c = Client('http://localhost:8001/3.0', API_USER, API_PASS) if form.is_valid(): @@ -94,24 +104,17 @@ try: domain = c.create_domain(mail_host,web_host,description) except HTTPError, e: - error=e - existing_domains = c.domains + message=e + return redirect("domain_index") except AttributeError, e: return render_to_response('mailman-django/errors/generic.html', - {'error': "REST API not found / Offline"},context_instance=RequestContext(request)) + {'error': "REST API not found / Offline", + 'is_ajax':is_ajax}, + context_instance=RequestContext(request)) else: - try: - c = Client('http://localhost:8001/3.0', API_USER, API_PASS) - existing_domains = c.domains - except AttributeError, e: - return render_to_response('mailman-django/errors/generic.html', - {'error': "REST API not found / Offline"},context_instance=RequestContext(request)) form = DomainNew() - return render_to_response(template, {'form': form, - 'domains':existing_domains, - 'message':message, - 'error':error, - },context_instance=RequestContext(request)) + return render_to_response(template, {'form': form,'message':message}, + context_instance=RequestContext(request)) @login_required def administration(request): #TODO @@ -176,7 +179,6 @@ for domain in c.domains: choosable_domains.append((domain.email_host,domain.email_host)) form = ListNew(choosable_domains) - login.html return render_to_response(template, {'form': form, error:None}, context_instance=RequestContext(request))