mirror of https://gitlab.federez.net/re2o/re2o
4 changed files with 108 additions and 10 deletions
@ -0,0 +1,31 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.10.7 on 2017-10-09 |
|||
# Modified by Tudor, with love |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations, models |
|||
import django.db.models.deletion |
|||
|
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('users', '0055_auto_20171003_0556'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.CreateModel( |
|||
name='BanType', |
|||
fields=[ |
|||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
|||
('name', models.CharField(max_length=255)), |
|||
('description', models.TextField(help_text="Description de l'effet et des raisons de la blacklist")), |
|||
], |
|||
), |
|||
migrations.AddField( |
|||
model_name='ban', |
|||
name='ban_type', |
|||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='users.BanType'), |
|||
), |
|||
] |
|||
@ -0,0 +1,43 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.10.7 on 2017-10-09 |
|||
# Modified by Tudor, with love |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations, models |
|||
import django.db.models.deletion |
|||
|
|||
def add_foreign_bans(apps, schema_editor): |
|||
Ban = apps.get_model('users', 'Ban') |
|||
BanType = apps.get_model('users', 'BanType') |
|||
b_hard = BanType(name='HARD', description="aucun accès") |
|||
b_soft = BanType(name='SOFT', description="accès local seulement") |
|||
b_bridage = BanType(name='BRIDAGE', description="bridage du débit") |
|||
|
|||
# Ajoute et synchronise le nouveau field à partir du field state |
|||
db_alias = schema_editor.connection.alias |
|||
for b_type in [b_hard, b_soft, b_bridage]: |
|||
b_type.save(using=db_alias) |
|||
bans = Ban.objects.using(db_alias).all() |
|||
for b in bans: |
|||
if b.state == 0: |
|||
b.ban_type = b_hard |
|||
elif b.state == 1: |
|||
b.ban_type = b_soft |
|||
elif b.state == 2: |
|||
b.ban_type = b_bridage |
|||
else: |
|||
raise Exception("Un ban state inconnu %r n'a pu être converti" % b.state) |
|||
b.save(using=db_alias) |
|||
|
|||
def remove_foreign_bans(apps, schema_editor): |
|||
pass |
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('users', '0056_1_bantype_alter'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.RunPython(add_foreign_bans, remove_foreign_bans), |
|||
] |
|||
@ -0,0 +1,25 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.10.7 on 2017-10-09 20:59 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations, models |
|||
import django.db.models.deletion |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('users', '0056_2_bantype_pop'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.RemoveField( |
|||
model_name='ban', |
|||
name='state', |
|||
), |
|||
migrations.AlterField( |
|||
model_name='ban', |
|||
name='ban_type', |
|||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='users.BanType'), |
|||
), |
|||
] |
|||
Loading…
Reference in new issue