8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-23 03:43:12 +00:00
re2o/users/migrations/0073_auto_20180629_1614.py

58 lines
2.3 KiB
Python
Raw Normal View History

2018-06-29 14:36:04 +00:00
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-06-29 14:14
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import re2o.mixins
class Migration(migrations.Migration):
2018-08-01 11:06:25 +00:00
def create_initial_email_address(apps, schema_editor):
2018-07-30 15:00:41 +00:00
db_alias = schema_editor.connection.alias
User = apps.get_model("users", "User")
2018-08-01 11:06:25 +00:00
EMailAddress = apps.get_model("users", "EMailAddress")
2018-07-30 15:00:41 +00:00
users = User.objects.using(db_alias).all()
for user in users:
2018-08-01 11:06:25 +00:00
EMailAddress.objects.using(db_alias).create(
2018-07-30 15:00:41 +00:00
local_part=user.pseudo,
user=user
)
2018-08-01 11:06:25 +00:00
def delete_all_email_address(apps, schema_editor):
2018-07-30 15:00:41 +00:00
db_alias = schema_editor.connection.alias
2018-08-01 11:06:25 +00:00
EMailAddress = apps.get_model("users", "EMailAddress")
EMailAddress.objects.using(db_alias).delete()
2018-07-30 15:00:41 +00:00
2018-06-29 14:36:04 +00:00
dependencies = [
('users', '0072_auto_20180426_2021'),
]
operations = [
migrations.CreateModel(
2018-08-01 11:06:25 +00:00
name='EMailAddress',
2018-06-29 14:36:04 +00:00
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
2018-07-30 15:00:41 +00:00
('local_part', models.CharField(help_text="Local part of the email address", max_length=128, unique=True)),
('user', models.ForeignKey(help_text='User of the local email', on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
2018-06-29 14:36:04 +00:00
],
bases=(re2o.mixins.RevMixin, re2o.mixins.AclMixin, models.Model),
2018-08-01 11:06:25 +00:00
options={'permissions': (('view_emailaddress', 'Can see a local email account object'),), 'verbose_name': 'Local email account', 'verbose_name_plural': 'Local email accounts'},
2018-06-29 14:36:04 +00:00
),
migrations.AddField(
model_name='user',
2018-07-30 15:00:41 +00:00
name='local_email_enabled',
field=models.BooleanField(default=False, help_text="Wether or not to enable the local email account."),
2018-06-29 14:36:04 +00:00
),
migrations.AddField(
model_name='user',
2018-07-30 15:00:41 +00:00
name='local_email_redirect',
field=models.BooleanField(default=False, help_text='Whether or not to redirect the local email messages to the main email.'),
2018-06-29 14:36:04 +00:00
),
2018-08-01 11:06:25 +00:00
migrations.RunPython(create_initial_email_address,
delete_all_email_address),
2018-06-29 14:36:04 +00:00
]
2018-07-30 15:00:41 +00:00