diff --git a/modoboa/lib/dbutils.py b/modoboa/lib/dbutils.py index 12e6ec843..1bcd03fcb 100644 --- a/modoboa/lib/dbutils.py +++ b/modoboa/lib/dbutils.py @@ -1,7 +1,10 @@ # coding: utf-8 from django.db import connection from django.conf import settings - +from django.utils.translation import ugettext as _ +from modoboa.lib.exceptions import InternalError + + def db_table_exists(table, cursor=None): """Check if table exists @@ -20,14 +23,18 @@ def db_table_exists(table, cursor=None): else: return table in table_names -def db_type(connection="default"): + +def db_type(cname="default"): """Return the type of the *default* database Supported values : 'postgres', 'mysql', 'sqlite' + :param str cname: connection name :return: a string or None """ + if not cname in settings.DATABASES: + raise InternalError(_("Connection to database %s not configured" % cname)) for t in ['postgres', 'mysql', 'sqlite']: - if settings.DATABASES[connection]['ENGINE'].find(t) != -1: + if settings.DATABASES[cname]['ENGINE'].find(t) != -1: return t return None diff --git a/modoboa/lib/webutils.py b/modoboa/lib/webutils.py index 843897378..a41cec029 100644 --- a/modoboa/lib/webutils.py +++ b/modoboa/lib/webutils.py @@ -8,7 +8,7 @@ import re import json from django.http import HttpResponse, HttpResponseRedirect from django.contrib.auth.decorators import login_required -from django.shortcuts import render_to_response +from django.shortcuts import render, render_to_response from django.template.loader import render_to_string from django import template from django.conf import settings @@ -27,9 +27,8 @@ def _render_to_string(request, tpl, user_context): def _render_error(request, errortpl="error", user_context=None): if user_context is None: user_context = {} - return render_to_response( - "common/%s.html" % errortpl, user_context, - context_instance=template.RequestContext(request) + return render( + request, "common/%s.html" % errortpl, user_context ) diff --git a/modoboa/templates/common/error.html b/modoboa/templates/common/error.html index 0c57125a0..74c95a380 100644 --- a/modoboa/templates/common/error.html +++ b/modoboa/templates/common/error.html @@ -1,4 +1,4 @@ -{% extends "nlayout.html" %} +{% extends "layout_simple.html" %} {% load i18n %} {% block content %}
{% trans "Error:" %} {{ error }}