mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-11-16 09:34:03 +01:00
@@ -0,0 +1,18 @@
|
||||
"""
|
||||
Extra classes for management commands.
|
||||
"""
|
||||
|
||||
from django.db import connection
|
||||
|
||||
|
||||
class CloseConnectionMixin(object):
|
||||
|
||||
"""
|
||||
A simple mixin used to close all database connections after
|
||||
command execution.
|
||||
"""
|
||||
|
||||
def execute(self, *args, **options):
|
||||
"""Execute will call handle so we can close the connection here."""
|
||||
super(CloseConnectionMixin, self).execute(*args, **options)
|
||||
connection.close()
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
import datetime
|
||||
from optparse import make_option
|
||||
|
||||
from django.db import connection
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.utils import timezone
|
||||
|
||||
@@ -11,8 +10,10 @@ from modoboa.core import load_core_settings
|
||||
from modoboa.core.models import Log
|
||||
from modoboa.lib import parameters
|
||||
|
||||
from . import CloseConnectionMixin
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
||||
class Command(BaseCommand, CloseConnectionMixin):
|
||||
args = ''
|
||||
help = 'Log table cleanup'
|
||||
|
||||
@@ -45,5 +46,4 @@ class Command(BaseCommand):
|
||||
self.__vprint("Deleting logs older than %d days..." % log_maximum_age)
|
||||
limit = timezone.now() - datetime.timedelta(log_maximum_age)
|
||||
Log.objects.filter(date_created__lt=limit).delete()
|
||||
connection.close()
|
||||
self.__vprint("Done.")
|
||||
|
||||
@@ -6,12 +6,12 @@ from optparse import make_option
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.db import connection
|
||||
|
||||
from modoboa.core.models import Extension
|
||||
from . import CloseConnectionMixin
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
class Command(BaseCommand, CloseConnectionMixin):
|
||||
|
||||
"""Command definition."""
|
||||
|
||||
@@ -56,5 +56,3 @@ class Command(BaseCommand):
|
||||
if not fullname in settings.MODOBOA_APPS:
|
||||
continue
|
||||
self._change_extension_state(extname, options)
|
||||
|
||||
connection.close()
|
||||
|
||||
@@ -6,12 +6,13 @@ See `https://docs.djangoproject.com/en/dev/ref/contrib/sites/`_.
|
||||
"""
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.db import connection
|
||||
|
||||
from django.contrib.sites.models import Site
|
||||
|
||||
from . import CloseConnectionMixin
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
||||
class Command(BaseCommand, CloseConnectionMixin):
|
||||
|
||||
"""Management command to set the default site."""
|
||||
|
||||
@@ -25,4 +26,3 @@ class Command(BaseCommand):
|
||||
site.domain = args[0]
|
||||
site.name = args[0]
|
||||
site.save()
|
||||
connection.close()
|
||||
|
||||
Reference in New Issue
Block a user