Skip to content
This repository was archived by the owner on Nov 16, 2017. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions templatesadmin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from django.conf import settings
from django.contrib.auth.decorators import login_required, user_passes_test
from django.contrib import messages
from django.core.exceptions import ImproperlyConfigured
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
Expand Down Expand Up @@ -117,9 +118,9 @@ def listing(request,
template_dict = (l,)

template_context = {
'messages': request.user.get_and_delete_messages(),
'messages': messages.get_messages(request),
'template_dict': template_dict,
'ADMIN_MEDIA_PREFIX': settings.ADMIN_MEDIA_PREFIX,
'ADMIN_MEDIA_PREFIX': settings.STATIC_URL + '/admin/',
}

return render_to_response(template_name, template_context,
Expand Down Expand Up @@ -153,9 +154,10 @@ def modify(request,
for hook in TEMPLATESADMIN_EDITHOOKS:
pre_save_notice = hook.pre_save(request, form, template_path)
if pre_save_notice:
request.user.message_set.create(message=pre_save_notice)
messages.add_message(request, messages.INFO, pre_save_notice)
except TemplatesAdminException, e:
messages.add_message(request, messages.ERROR, e.message)
except TemplatesAdminException, e:
request.user.message_set.create(message=e.message)
return HttpResponseRedirect(request.build_absolute_uri())

# Save the template
Expand All @@ -180,26 +182,23 @@ def modify(request,
f.write(content)
f.close()
except IOError, e:
request.user.message_set.create(
message=_('Template "%(path)s" has not been saved! Reason: %(errormsg)s' % {
'path': path,
'errormsg': e
})
messages.add_message(request, messages.ERROR, ('Template "%(path)s" has not been saved! Reason: %(errormsg)s' % {
'path': path,
'errormsg': e
})
)
return HttpResponseRedirect(request.build_absolute_uri())

try:
for hook in TEMPLATESADMIN_EDITHOOKS:
post_save_notice = hook.post_save(request, form, template_path)
if post_save_notice:
request.user.message_set.create(message=post_save_notice)
messages.add_message(request, messages.INFO, post_save_notice)
except TemplatesAdminException, e:
request.user.message_set.create(message=e.message)
messages.add_message(request, messages.ERROR, e.message)
return HttpResponseRedirect(request.build_absolute_uri())

request.user.message_set.create(
message=_('Template "%s" was saved successfully.' % path)
)
messages.add_message(request, messages.INFO, _('Template "%s" was saved successfully.' % path))
return HttpResponseRedirect(reverse('templatesadmin-overview'))
else:
template_file = codecs.open(template_path, 'r', 'utf-8').read()
Expand All @@ -213,12 +212,12 @@ def modify(request,
)

template_context = {
'messages': request.user.get_and_delete_messages(),
'messages': messages.get_messages(request),
'form': form,
'short_path': path,
'template_path': path,
'template_writeable': os.access(template_path, os.W_OK),
'ADMIN_MEDIA_PREFIX': settings.ADMIN_MEDIA_PREFIX,
'ADMIN_MEDIA_PREFIX': settings.STATIC_URL + '/admin/',
}

return render_to_response(template_name, template_context,
Expand Down