mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-18 05:51:26 +02:00
WIP.
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.5 on 2016-11-04 18:00
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
def move_dates(apps, schema_editor):
|
||||
"""Move dates to models."""
|
||||
Domain = apps.get_model("admin", "Domain")
|
||||
DomainAlias = apps.get_model("admin", "DomainAlias")
|
||||
Mailbox = apps.get_model("admin", "Mailbox")
|
||||
Alias = apps.get_model("admin", "Alias")
|
||||
RelayDomain = apps.get_model("relaydomains", "RelayDomain")
|
||||
for model in [Domain, DomainAlias, Mailbox, Alias, RelayDomain]:
|
||||
for instance in model.objects.all():
|
||||
instance.creation = instance.dates.creation
|
||||
instance.last_modification = instance.dates.last_modification
|
||||
instance.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('admin', '0005_auto_20161026_1003'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='alias',
|
||||
name='creation',
|
||||
field=models.DateTimeField(default=django.utils.timezone.now),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='alias',
|
||||
name='last_modification',
|
||||
field=models.DateTimeField(null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='domain',
|
||||
name='creation',
|
||||
field=models.DateTimeField(default=django.utils.timezone.now),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='domain',
|
||||
name='last_modification',
|
||||
field=models.DateTimeField(null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='domainalias',
|
||||
name='creation',
|
||||
field=models.DateTimeField(default=django.utils.timezone.now),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='domainalias',
|
||||
name='last_modification',
|
||||
field=models.DateTimeField(null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='mailbox',
|
||||
name='creation',
|
||||
field=models.DateTimeField(default=django.utils.timezone.now),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='mailbox',
|
||||
name='last_modification',
|
||||
field=models.DateTimeField(null=True),
|
||||
),
|
||||
migrations.RunPython(move_dates)
|
||||
]
|
||||
@@ -0,0 +1,55 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.5 on 2016-11-04 18:15
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('relaydomains', '0003_remove_relaydomain_dates'),
|
||||
('admin', '0006_auto_20161104_1900'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='alias',
|
||||
name='dates',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='domain',
|
||||
name='dates',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='domainalias',
|
||||
name='dates',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='mailbox',
|
||||
name='dates',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='alias',
|
||||
name='last_modification',
|
||||
field=models.DateTimeField(auto_now=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='domain',
|
||||
name='last_modification',
|
||||
field=models.DateTimeField(auto_now=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='domainalias',
|
||||
name='last_modification',
|
||||
field=models.DateTimeField(auto_now=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='mailbox',
|
||||
name='last_modification',
|
||||
field=models.DateTimeField(auto_now=True),
|
||||
),
|
||||
migrations.DeleteModel(
|
||||
name='ObjectDates',
|
||||
),
|
||||
]
|
||||
@@ -1,4 +1,7 @@
|
||||
"""Base admin models."""
|
||||
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
|
||||
from modoboa.lib import events
|
||||
from modoboa.lib.permissions import (
|
||||
@@ -6,55 +9,21 @@ from modoboa.lib.permissions import (
|
||||
)
|
||||
|
||||
|
||||
class ObjectDates(models.Model):
|
||||
|
||||
"""Dates recording for admin objects
|
||||
|
||||
This table keeps creation and last modification dates for Domains,
|
||||
domain aliases, mailboxes and aliases objects.
|
||||
"""
|
||||
creation = models.DateTimeField(auto_now_add=True)
|
||||
last_modification = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
app_label = "admin"
|
||||
|
||||
@staticmethod
|
||||
def set_for_object(obj):
|
||||
"""Initialize or update dates for a given object.
|
||||
|
||||
:param obj: an admin object (Domain, Mailbox, etc)
|
||||
"""
|
||||
try:
|
||||
dates = getattr(obj, "dates")
|
||||
except ObjectDates.DoesNotExist:
|
||||
dates = ObjectDates()
|
||||
dates.save()
|
||||
obj.dates = dates
|
||||
|
||||
|
||||
class AdminObject(models.Model):
|
||||
|
||||
"""Abstract model to support dates
|
||||
"""Abstract model to support dates.
|
||||
|
||||
Inherit from this model to automatically add the "dates" feature
|
||||
to another model. It defines the appropriate field and handles
|
||||
saves.
|
||||
"""
|
||||
dates = models.ForeignKey(ObjectDates)
|
||||
|
||||
creation = models.DateTimeField(default=timezone.now)
|
||||
last_modification = models.DateTimeField(auto_now=True)
|
||||
_objectname = None
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
@property
|
||||
def creation(self):
|
||||
return self.dates.creation
|
||||
|
||||
@property
|
||||
def last_modification(self):
|
||||
return self.dates.last_modification
|
||||
|
||||
@property
|
||||
def objectname(self):
|
||||
if self._objectname is None:
|
||||
@@ -66,12 +35,7 @@ class AdminObject(models.Model):
|
||||
events.raiseEvent("%sCreated" % self.objectname, creator, self)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
ObjectDates.set_for_object(self)
|
||||
if "creator" in kwargs:
|
||||
creator = kwargs["creator"]
|
||||
del kwargs["creator"]
|
||||
else:
|
||||
creator = None
|
||||
creator = kwargs.pop("creator", None)
|
||||
super(AdminObject, self).save(*args, **kwargs)
|
||||
if creator is not None:
|
||||
self.post_create(creator)
|
||||
|
||||
@@ -366,11 +366,7 @@ class User(PermissionsMixin):
|
||||
events.raiseEvent("AccountCreated", self)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if "creator" in kwargs:
|
||||
creator = kwargs["creator"]
|
||||
del kwargs["creator"]
|
||||
else:
|
||||
creator = None
|
||||
creator = kwargs.pop("creator", None)
|
||||
super(User, self).save(*args, **kwargs)
|
||||
if creator is not None:
|
||||
self.post_create(creator)
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
from django import forms
|
||||
|
||||
from modoboa.lib import events
|
||||
from modoboa.lib import db_utils
|
||||
from modoboa.lib import form_utils
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ class RelayDomainFormGeneral(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = RelayDomain
|
||||
exclude = ["domain", "dates"]
|
||||
exclude = ["domain"]
|
||||
widgets = {
|
||||
"service": forms.Select(attrs={"class": "form-control"})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.5 on 2016-11-04 18:15
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('relaydomains', '0002_migrate_from_modoboa_admin_relaydomains'),
|
||||
('admin', '0006_auto_20161104_1900'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='relaydomain',
|
||||
name='dates',
|
||||
),
|
||||
]
|
||||
@@ -41,7 +41,6 @@ class ServiceManager(Manager):
|
||||
|
||||
|
||||
class Service(models.Model):
|
||||
|
||||
"""Postfix service."""
|
||||
|
||||
name = models.CharField(
|
||||
@@ -59,13 +58,13 @@ class Service(models.Model):
|
||||
|
||||
|
||||
class RelayDomain(admin_models.AdminObject):
|
||||
|
||||
"""Relay domain.
|
||||
|
||||
A relay domain differs from a usual domaine because its final
|
||||
destination is not reached yet. It must be accepted by the MTA but
|
||||
it will then be transfered to another one.
|
||||
"""
|
||||
|
||||
domain = models.OneToOneField("admin.Domain", null=True)
|
||||
target_host = models.CharField(
|
||||
ugettext_lazy('target host'), max_length=255,
|
||||
|
||||
Reference in New Issue
Block a user