8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-24 20:33:11 +00:00
re2o/users/migrations/0079_auto_20181109_0156.py

49 lines
1.6 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-11-09 00:56
from __future__ import unicode_literals
from django.db import migrations, models
import users.models
from re2o.settings import GID_RANGES
class Migration(migrations.Migration):
dependencies = [
('users', '0078_auto_20181011_1405'),
]
def set_clubs_gid(apps, schema_editor):
LdapUserGroup = apps.get_model('users', 'LdapUserGroup')
gids = list(range(
int(min(GID_RANGES['clubs'])),
int(max(GID_RANGES['clubs']))
))
used_gids = list(LdapUserGroup.objects.values_list('gid', flat=True))
free_gids = [id for id in gids if id not in used_gids]
Club = apps.get_model('users', 'Club')
for ident, club in enumerate(Club.objects.all()):
club.gid_number = free_gids[ident]
club.save()
operations = [
migrations.AddField(
model_name='club',
name='gid_number',
field=models.PositiveIntegerField(null=True, validators=[users.models.validate_gid]),
),
migrations.AlterField(
model_name='listright',
name='gid',
field=models.PositiveIntegerField(unique=True, validators=[users.models.validate_gid]),
),
migrations.RunPython(set_clubs_gid),
migrations.AlterField(
model_name='club',
name='gid_number',
field=models.PositiveIntegerField(default=users.models.get_fresh_gid('clubs'), unique=True, validators=[users.models.validate_gid]),
),
]