mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-22 06:28:41 +02:00
@@ -89,6 +89,25 @@ def is_not_localadmin(errortpl="error"):
|
||||
return wrapped_f
|
||||
return dec
|
||||
|
||||
def db_table_exists(table, cursor=None):
|
||||
"""Check if table exists
|
||||
|
||||
Taken from here:
|
||||
https://gist.github.com/527113/307c2dec09ceeb647b8fa1d6d49591f3352cb034
|
||||
|
||||
"""
|
||||
try:
|
||||
if not cursor:
|
||||
from django.db import connection
|
||||
cursor = connection.cursor()
|
||||
if not cursor:
|
||||
raise Exception
|
||||
table_names = connection.introspection.get_table_list(cursor)
|
||||
except:
|
||||
raise Exception("unable to determine if the table '%s' exists" % table)
|
||||
else:
|
||||
return table in table_names
|
||||
|
||||
class Singleton(type):
|
||||
def __init__(cls, name, bases, dict):
|
||||
super(Singleton, cls).__init__(name, bases, dict)
|
||||
|
||||
Reference in New Issue
Block a user