mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-22 06:28:41 +02:00
#48 : rollback, this is not trivial.
This commit is contained in:
@@ -112,56 +112,3 @@ class Alias(models.Model):
|
||||
("view_aliases", "View aliases"),
|
||||
)
|
||||
|
||||
class Extension(models.Model):
|
||||
name = models.CharField(max_length=150)
|
||||
enabled = models.BooleanField(_('enabled'),
|
||||
help_text=_("Check to enable this extension"))
|
||||
has_templates = models.BooleanField()
|
||||
|
||||
def on(self):
|
||||
from django.core.management import sql, color
|
||||
from django.db import connection, models
|
||||
|
||||
style = color.no_style()
|
||||
cursor = connection.cursor()
|
||||
module = __import__("mailng.extensions.%s" % self.name,
|
||||
globals(), locals(), ['main', 'models'])
|
||||
try:
|
||||
extmodels = module.models
|
||||
except AttributeError:
|
||||
extmodels = None
|
||||
if extmodels is not None:
|
||||
mods = []
|
||||
for k, v in extmodels.__dict__.iteritems():
|
||||
try:
|
||||
if not issubclass(v, models.Model):
|
||||
continue
|
||||
statements, pending = \
|
||||
connection.creation.sql_create_model(v, style)
|
||||
try:
|
||||
for sql in statements:
|
||||
cursor.execute(sql)
|
||||
except Exception, msg:
|
||||
pass
|
||||
except TypeError:
|
||||
pass
|
||||
if self.has_templates:
|
||||
code, output = exec_cmd("ln -s ../extensions/%s/templates templates/%s" \
|
||||
% (self.name, self.name))
|
||||
if os.path.exists("extensions/%s/scripts" % self.name):
|
||||
code, output = exec_cmd("ln -s ../extensions/%s/scripts scripts/%s" \
|
||||
% (self.name, self.name))
|
||||
module.main.init()
|
||||
self.enabled = True
|
||||
self.save()
|
||||
|
||||
def off(self):
|
||||
if self.has_templates:
|
||||
code, output = exec_cmd("rm -f templates/%s" % self.name)
|
||||
print output
|
||||
self.enabled = False
|
||||
self.save()
|
||||
module = __import__("mailng.extensions.%s" % self.name,
|
||||
globals(), locals(), ['main', 'models'])
|
||||
module.main.destroy()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user