move existing MailDomains to domains table
This commit is contained in:
parent
5db6223bc0
commit
ecaff6a4af
5 changed files with 181 additions and 20 deletions
|
@ -1,5 +1,5 @@
|
|||
[run]
|
||||
source = gnuviechadmin,managemails
|
||||
source = gnuviechadmin,managemails,osusers,domains
|
||||
|
||||
[report]
|
||||
omit = */migrations/*,*/tests/*.py,*/tests.py,gnuviechadmin/settings/local.py,gnuviechadmin/settings/production.py
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# pymode:lint_ignore=E501
|
||||
from south.v2 import DataMigration
|
||||
|
||||
|
||||
class Migration(DataMigration):
|
||||
|
||||
def forwards(self, orm):
|
||||
"Write your forwards methods here."
|
||||
OrigMailDomain = orm['managemails.MailDomain']
|
||||
NewMailDomain = orm['domains.MailDomain']
|
||||
for domain in OrigMailDomain.objects.all():
|
||||
NewMailDomain(domain=domain.domain, id=domain.id, created=domain.created).save()
|
||||
|
||||
def backwards(self, orm):
|
||||
"Write your backwards methods here."
|
||||
OrigMailDomain = orm['domains.MailDomain']
|
||||
NewMailDomain = orm['managemails.MailDomain']
|
||||
for domain in OrigMailDomain.objects.all():
|
||||
NewMailDomain(domain=domain.domain, id=domain.id, created=domain.created).save()
|
||||
|
||||
models = {
|
||||
u'domains.maildomain': {
|
||||
'Meta': {'object_name': 'MailDomain'},
|
||||
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||
'domain': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '128'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'})
|
||||
},
|
||||
u'managemails.maildomain': {
|
||||
'Meta': {'object_name': 'MailDomain'},
|
||||
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||
'domain': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '128'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'})
|
||||
},
|
||||
u'managemails.mailaddress': {
|
||||
'Meta': {'unique_together': "(('localpart', 'domain'),)", 'object_name': 'MailAddress'},
|
||||
'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
|
||||
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||
'domain': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['domains.MailDomain']"}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'localpart': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
|
||||
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'})
|
||||
},
|
||||
u'managemails.mailaddressforward': {
|
||||
'Meta': {'unique_together': "(('mailaddress', 'target'),)", 'object_name': 'MailAddressForward'},
|
||||
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'mailaddress': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['managemails.MailAddress']"}),
|
||||
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
|
||||
'target': ('django.db.models.fields.EmailField', [], {'max_length': '254'})
|
||||
},
|
||||
u'managemails.mailaddressmailbox': {
|
||||
'Meta': {'unique_together': "(('mailaddress', 'mailbox'),)", 'object_name': 'MailAddressMailbox'},
|
||||
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||
'mailaddress': ('django.db.models.fields.related.OneToOneField', [], {'to': u"orm['managemails.MailAddress']", 'unique': 'True', 'primary_key': 'True'}),
|
||||
'mailbox': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['managemails.Mailbox']"}),
|
||||
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'})
|
||||
},
|
||||
u'managemails.mailbox': {
|
||||
'Meta': {'object_name': 'Mailbox'},
|
||||
'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
|
||||
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
|
||||
'osuser': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['osusers.User']"}),
|
||||
'password': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
|
||||
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '128'})
|
||||
},
|
||||
u'osusers.group': {
|
||||
'Meta': {'object_name': 'Group'},
|
||||
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||
'descr': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'gid': ('django.db.models.fields.PositiveSmallIntegerField', [], {'unique': 'True', 'primary_key': 'True'}),
|
||||
'groupname': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '16'}),
|
||||
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
|
||||
'passwd': ('django.db.models.fields.CharField', [], {'max_length': '128', 'blank': 'True'})
|
||||
},
|
||||
u'osusers.user': {
|
||||
'Meta': {'object_name': 'User'},
|
||||
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||
'gecos': ('django.db.models.fields.CharField', [], {'max_length': '128', 'blank': 'True'}),
|
||||
'group': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['osusers.Group']"}),
|
||||
'homedir': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
|
||||
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
|
||||
'shell': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
|
||||
'uid': ('django.db.models.fields.PositiveSmallIntegerField', [], {'unique': 'True', 'primary_key': 'True'}),
|
||||
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '64'})
|
||||
}
|
||||
}
|
||||
|
||||
complete_apps = ['managemails']
|
||||
symmetrical = True
|
|
@ -0,0 +1,84 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# pymode:lint_ignore=E501
|
||||
from south.db import db
|
||||
from south.v2 import SchemaMigration
|
||||
|
||||
|
||||
class Migration(SchemaMigration):
|
||||
|
||||
def forwards(self, orm):
|
||||
# Deleting model 'MailDomain'
|
||||
db.delete_table(u'managemails_maildomain')
|
||||
|
||||
# Changing field 'MailAddress.domain'
|
||||
db.alter_column(u'managemails_mailaddress', 'domain_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['domains.MailDomain']))
|
||||
|
||||
def backwards(self, orm):
|
||||
# Adding model 'MailDomain'
|
||||
raise RuntimeError("Backward migration is not supported.")
|
||||
|
||||
models = {
|
||||
u'domains.maildomain': {
|
||||
'Meta': {'object_name': 'MailDomain'},
|
||||
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||
'domain': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '128'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'})
|
||||
},
|
||||
u'managemails.mailaddress': {
|
||||
'Meta': {'unique_together': "(('localpart', 'domain'),)", 'object_name': 'MailAddress'},
|
||||
'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
|
||||
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||
'domain': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['domains.MailDomain']"}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'localpart': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
|
||||
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'})
|
||||
},
|
||||
u'managemails.mailaddressforward': {
|
||||
'Meta': {'unique_together': "(('mailaddress', 'target'),)", 'object_name': 'MailAddressForward'},
|
||||
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'mailaddress': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['managemails.MailAddress']"}),
|
||||
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
|
||||
'target': ('django.db.models.fields.EmailField', [], {'max_length': '254'})
|
||||
},
|
||||
u'managemails.mailaddressmailbox': {
|
||||
'Meta': {'unique_together': "(('mailaddress', 'mailbox'),)", 'object_name': 'MailAddressMailbox'},
|
||||
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||
'mailaddress': ('django.db.models.fields.related.OneToOneField', [], {'to': u"orm['managemails.MailAddress']", 'unique': 'True', 'primary_key': 'True'}),
|
||||
'mailbox': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['managemails.Mailbox']"}),
|
||||
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'})
|
||||
},
|
||||
u'managemails.mailbox': {
|
||||
'Meta': {'object_name': 'Mailbox'},
|
||||
'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
|
||||
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
|
||||
'osuser': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['osusers.User']"}),
|
||||
'password': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
|
||||
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '128'})
|
||||
},
|
||||
u'osusers.group': {
|
||||
'Meta': {'object_name': 'Group'},
|
||||
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||
'descr': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'gid': ('django.db.models.fields.PositiveSmallIntegerField', [], {'unique': 'True', 'primary_key': 'True'}),
|
||||
'groupname': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '16'}),
|
||||
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
|
||||
'passwd': ('django.db.models.fields.CharField', [], {'max_length': '128', 'blank': 'True'})
|
||||
},
|
||||
u'osusers.user': {
|
||||
'Meta': {'object_name': 'User'},
|
||||
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||
'gecos': ('django.db.models.fields.CharField', [], {'max_length': '128', 'blank': 'True'}),
|
||||
'group': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['osusers.Group']"}),
|
||||
'homedir': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
|
||||
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
|
||||
'shell': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
|
||||
'uid': ('django.db.models.fields.PositiveSmallIntegerField', [], {'unique': 'True', 'primary_key': 'True'}),
|
||||
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '64'})
|
||||
}
|
||||
}
|
||||
|
||||
complete_apps = ['managemails']
|
|
@ -5,21 +5,10 @@ from django.utils.translation import ugettext as _
|
|||
from passlib.hash import sha512_crypt
|
||||
from model_utils.models import TimeStampedModel
|
||||
|
||||
from domains.models import MailDomain
|
||||
from osusers.models import User as OsUser
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class MailDomain(TimeStampedModel, models.Model):
|
||||
domain = models.CharField(max_length=128, unique=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Mail domain')
|
||||
verbose_name_plural = _('Mail domains')
|
||||
|
||||
def __str__(self):
|
||||
return self.domain
|
||||
|
||||
|
||||
class ActivateAbleMixin(models.Model):
|
||||
"""
|
||||
Mixin for model classes that can be active or inactive.
|
||||
|
|
|
@ -1,20 +1,14 @@
|
|||
from django.test import TestCase
|
||||
from passlib.hash import sha512_crypt
|
||||
|
||||
from domains.models import MailDomain
|
||||
from osusers.models import User
|
||||
from managemails.models import (
|
||||
MailAddress,
|
||||
MailDomain,
|
||||
Mailbox,
|
||||
)
|
||||
|
||||
|
||||
class MailDomainTest(TestCase):
|
||||
def test__str__(self):
|
||||
md = MailDomain.objects.create(domain='example.org')
|
||||
self.assertEqual(str(md), 'example.org')
|
||||
|
||||
|
||||
class MailboxTest(TestCase):
|
||||
def test_set_password(self):
|
||||
user = User.objects.create_user()
|
||||
|
|
Loading…
Reference in a new issue