зеркало из https://github.com/mozilla/normandy.git
recipe-server: Add migration to change username to emails
This commit is contained in:
Родитель
0fcab6a004
Коммит
cf69f3050f
|
@ -0,0 +1,39 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.5 on 2017-03-06 19:25
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def email_to_username(apps, schema_editor):
|
||||
"""
|
||||
Copy emails to usernames for all users.
|
||||
"""
|
||||
User = apps.get_model('auth', 'User')
|
||||
for user in User.objects.all():
|
||||
if user.email:
|
||||
user.username = user.email
|
||||
user.save()
|
||||
|
||||
|
||||
def remove_email_from_username(apps, schema_editor):
|
||||
"""
|
||||
Copy emails to usernames for all users.
|
||||
"""
|
||||
User = apps.get_model('auth', 'User')
|
||||
for user in User.objects.all():
|
||||
if '@' in user.username:
|
||||
user.username = user.username.split('@')[0]
|
||||
user.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(email_to_username, remove_email_from_username),
|
||||
]
|
Загрузка…
Ссылка в новой задаче