Try to handle errors when connecting to amavis.

fixes #257
This commit is contained in:
Antoine Nguyen
2013-11-26 09:55:41 +01:00
parent 5b302babd0
commit 6f1259aafd
3 changed files with 14 additions and 8 deletions
+10 -3
View File
@@ -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
+3 -4
View File
@@ -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
)
+1 -1
View File
@@ -1,4 +1,4 @@
{% extends "nlayout.html" %}
{% extends "layout_simple.html" %}
{% load i18n %}
{% block content %}
<div class="alert alert-error"><strong>{% trans "Error:" %}</strong> {{ error }}</div>