From 07e244c8c0fab0986ad8999431a45bd84d1f8bc7 Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Mon, 11 Jul 2011 10:22:18 +0200 Subject: [PATCH] Correct dates migration. see #140 --- tools/pfxadmin_migrate/migrate.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tools/pfxadmin_migrate/migrate.py b/tools/pfxadmin_migrate/migrate.py index 5e498ad63..a5a1140ba 100755 --- a/tools/pfxadmin_migrate/migrate.py +++ b/tools/pfxadmin_migrate/migrate.py @@ -52,12 +52,19 @@ from modoboa.lib import exec_cmd from modoboa.lib.emailutils import split_mailbox def migrate_dates(oldobj): + """Creates a new ObjectDates instance + + Due to Django limitations, we only retrieve the creation date. The + modification date will be set to 'now' because the corresponding + field in Modoboa's schema has the 'auto_now' attribute to True. + (see https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.DateField). + + :param oldobj: the PostfixAdmin record which is beeing migrated. + """ dates = md_models.ObjectDates() + dates.save() + dates.creation = oldobj.created - try: - dates.last_modification = oldobj.modified - except AttributeError: - dates.last_modification = oldobj.created dates.save() return dates @@ -168,6 +175,7 @@ def migrate_admins(options): mb.name = local_part mb.enabled = old_admin.active mb.password = old_admin.password + mb.dates = migrate_dates(old_admin) mb.save(using=options.to) mb.user.date_joined = old_admin.modified