introduce new app domains
- generate domains app - duplicate managemails.models.MailDomain as domains.models.MailDomain - add domains app to gnuviechadmin.settings.base.LOCAL_APPS - repair managemails.tests.test_models - fix handling of empty results in osusers.models.GroupManager.get_next_gid and osusers.models.UserManager.get_next_uid
This commit is contained in:
parent
e132c9a56c
commit
5db6223bc0
11 changed files with 76 additions and 1 deletions
0
gnuviechadmin/domains/__init__.py
Normal file
0
gnuviechadmin/domains/__init__.py
Normal file
3
gnuviechadmin/domains/admin.py
Normal file
3
gnuviechadmin/domains/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
36
gnuviechadmin/domains/migrations/0001_initial.py
Normal file
36
gnuviechadmin/domains/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from south.utils import datetime_utils as datetime
|
||||
from south.db import db
|
||||
from south.v2 import SchemaMigration
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Migration(SchemaMigration):
|
||||
|
||||
def forwards(self, orm):
|
||||
# Adding model 'MailDomain'
|
||||
db.create_table(u'domains_maildomain', (
|
||||
(u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
|
||||
('created', self.gf('model_utils.fields.AutoCreatedField')(default=datetime.datetime.now)),
|
||||
('modified', self.gf('model_utils.fields.AutoLastModifiedField')(default=datetime.datetime.now)),
|
||||
('domain', self.gf('django.db.models.fields.CharField')(unique=True, max_length=128)),
|
||||
))
|
||||
db.send_create_signal(u'domains', ['MailDomain'])
|
||||
|
||||
|
||||
def backwards(self, orm):
|
||||
# Deleting model 'MailDomain'
|
||||
db.delete_table(u'domains_maildomain')
|
||||
|
||||
|
||||
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'})
|
||||
}
|
||||
}
|
||||
|
||||
complete_apps = ['domains']
|
0
gnuviechadmin/domains/migrations/__init__.py
Normal file
0
gnuviechadmin/domains/migrations/__init__.py
Normal file
17
gnuviechadmin/domains/models.py
Normal file
17
gnuviechadmin/domains/models.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
from django.db import models
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from model_utils.models import TimeStampedModel
|
||||
|
||||
|
||||
@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
|
0
gnuviechadmin/domains/tests/__init__.py
Normal file
0
gnuviechadmin/domains/tests/__init__.py
Normal file
9
gnuviechadmin/domains/tests/test_models.py
Normal file
9
gnuviechadmin/domains/tests/test_models.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
from django.test import TestCase
|
||||
|
||||
from domains.models import MailDomain
|
||||
|
||||
|
||||
class MailDomainTest(TestCase):
|
||||
def test__str__(self):
|
||||
md = MailDomain.objects.create(domain='example.org')
|
||||
self.assertEqual(str(md), 'example.org')
|
3
gnuviechadmin/domains/views.py
Normal file
3
gnuviechadmin/domains/views.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
|
@ -219,6 +219,7 @@ DJANGO_APPS = (
|
|||
|
||||
# Apps specific for this project go here.
|
||||
LOCAL_APPS = (
|
||||
'domains',
|
||||
'osusers',
|
||||
'managemails',
|
||||
)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from django.test import TestCase
|
||||
from passlib.hash import sha512_crypt
|
||||
|
||||
from osusers.models import User
|
||||
from managemails.models import (
|
||||
MailAddress,
|
||||
MailDomain,
|
||||
|
@ -16,7 +17,8 @@ class MailDomainTest(TestCase):
|
|||
|
||||
class MailboxTest(TestCase):
|
||||
def test_set_password(self):
|
||||
mb = Mailbox.objects.create(username='test', uid=1000, gid=1000)
|
||||
user = User.objects.create_user()
|
||||
mb = Mailbox.objects.create(username='test', osuser=user)
|
||||
mb.set_password('test')
|
||||
self.assertTrue(sha512_crypt.verify('test', mb.password))
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@ class GroupManager(models.Manager):
|
|||
|
||||
def get_next_gid(self):
|
||||
q = self.aggregate(models.Max('gid'))
|
||||
if q['gid__max'] is None:
|
||||
return settings.OSUSER_MINGID
|
||||
return max(settings.OSUSER_MINGID, q['gid__max'] + 1)
|
||||
|
||||
|
||||
|
@ -45,6 +47,8 @@ class UserManager(models.Manager):
|
|||
|
||||
def get_next_uid(self):
|
||||
q = self.aggregate(models.Max('uid'))
|
||||
if q['uid__max'] is None:
|
||||
return settings.OSUSER_MINUID
|
||||
return max(settings.OSUSER_MINUID, q['uid__max'] + 1)
|
||||
|
||||
def get_next_username(self):
|
||||
|
|
Loading…
Reference in a new issue