Added Django Message Framework, changed addList and addDomain Notifications
1 parent 4fda17d commit 4a288827249c8059c896b889a09ef0a27e6aad63
@benste benste authored on 14 Mar 2012
Showing 3 changed files
View
2
■■■
dev_setup/settings.py
)
 
TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
)
 
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.messages',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
View
7
src/mailmanweb/templates/mailmanweb/base.html
</div>
</header>
 
<div class="mm_main mm_canvas">
{% if messages %}
<ul class="mm_messages">
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
{% block main %}{% endblock main %}
</div>
<div id="mm_footer">
{% block footer %}{% endblock footer %}
View
18
src/mailmanweb/views.py
import logging
 
 
from django.conf import settings
from django.contrib import messages
from django.contrib.auth import logout, authenticate, login
from django.contrib.auth.decorators import login_required, permission_required
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth.models import User
 
@login_required
@permission_required('server_admin')
def domain_new(request, template = 'mailmanweb/domain_new.html'):
message = None
if request.method == 'POST':
form = DomainNew(request.POST)
if form.is_valid():
domain = Domain(mail_host=form.cleaned_data['mail_host'],
domain.save()
except MailmanApiError:
return utils.render_api_error(request)
except HTTPError, e:
message=e
messages.error(request,e)
else:
messages.success(request,_("New Domain registered"))
return redirect("domain_index")
else:
form = DomainNew()
return render_to_response(template,
{'form': form,'message': message},
{'form': form},
context_instance=RequestContext(request))
 
@login_required
def administration(request):
correct the list gets created and otherwise the form with the data
filled in before the last POST request is returned. The user must
be logged in to create a new list.
"""
error = None
message = None
mailing_list = None
if request.method == 'POST':
try:
domains = Domain.objects.all()
list_settings["owner_address"] = form.cleaned_data['list_owner']
#settings["???"] = form.cleaned_data['languages'] #TODO not found in REST:
list_settings["advertised"] = form.cleaned_data['advertised']
list_settings.save()
messages.success(_("List created"))
return redirect("list_summary",fqdn_listname=mailing_list.fqdn_listname)
#TODO catch correct Error class:
except HTTPError, e:
messages.error(request,e)
return render_to_response('mailmanweb/errors/generic.html',
{'error':e},
context_instance=RequestContext(request))
else:
messages.success(_("New List created"))
else:
try:
domains = Domain.objects.all()
except MailmanApiError:
choosable_domains = [("",_("Choose a Domain"))]
for domain in domains:
choosable_domains.append((domain.mail_host,domain.mail_host))
form = ListNew(choosable_domains,initial={'list_owner': request.user.username})
return render_to_response(template, {'form': form, error:None},
return render_to_response(template, {'form': form},
context_instance=RequestContext(request))
 
def list_index(request, template = 'mailmanweb/lists/index.html'):
"""Show a table of all public mailing lists.