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:
Jan Dittberner 2014-05-25 14:53:58 +02:00
parent e132c9a56c
commit 5db6223bc0
11 changed files with 76 additions and 1 deletions

View file

View file

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

View 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']

View 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

View file

View 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')

View file

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

View file

@ -219,6 +219,7 @@ DJANGO_APPS = (
# Apps specific for this project go here. # Apps specific for this project go here.
LOCAL_APPS = ( LOCAL_APPS = (
'domains',
'osusers', 'osusers',
'managemails', 'managemails',
) )

View file

@ -1,6 +1,7 @@
from django.test import TestCase from django.test import TestCase
from passlib.hash import sha512_crypt from passlib.hash import sha512_crypt
from osusers.models import User
from managemails.models import ( from managemails.models import (
MailAddress, MailAddress,
MailDomain, MailDomain,
@ -16,7 +17,8 @@ class MailDomainTest(TestCase):
class MailboxTest(TestCase): class MailboxTest(TestCase):
def test_set_password(self): 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') mb.set_password('test')
self.assertTrue(sha512_crypt.verify('test', mb.password)) self.assertTrue(sha512_crypt.verify('test', mb.password))

View file

@ -18,6 +18,8 @@ class GroupManager(models.Manager):
def get_next_gid(self): def get_next_gid(self):
q = self.aggregate(models.Max('gid')) 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) return max(settings.OSUSER_MINGID, q['gid__max'] + 1)
@ -45,6 +47,8 @@ class UserManager(models.Manager):
def get_next_uid(self): def get_next_uid(self):
q = self.aggregate(models.Max('uid')) 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) return max(settings.OSUSER_MINUID, q['uid__max'] + 1)
def get_next_username(self): def get_next_username(self):