Commit 9ea6e605a84ce8b130b5bc160dad10efe5b11fd3

Authored by Sergio Oliveira
2 parents 249ad1c3 d8ba91b2

Merge branch 'user_reset_pwd_migration'

colab/accounts/migrations/0004_auto_20150311_1818.py 0 → 100644
... ... @@ -0,0 +1,50 @@
  1 +# -*- coding: utf-8 -*-
  2 +from __future__ import unicode_literals
  3 +
  4 +from django.db import models, migrations
  5 +
  6 +def trim_fields(apps, schema_editor):
  7 + trim_extra_account(apps, schema_editor, "facebook")
  8 + trim_extra_account(apps, schema_editor, "github")
  9 + trim_extra_account(apps, schema_editor, "twitter")
  10 +
  11 +def trim_extra_account(apps, schema_editor, types):
  12 + Users = apps.get_model('accounts', 'User')
  13 + for user in Users.objects.all():
  14 + field = getattr(user, types)
  15 + if not field:
  16 + continue
  17 + tmpString = field.split("/")[-1]
  18 + if len(field) >= 15:
  19 + setattr(user, types, tmpString[:14])
  20 + user.save()
  21 +
  22 +
  23 +class Migration(migrations.Migration):
  24 +
  25 + dependencies = [
  26 + ('accounts', '0003_auto_20141218_1755'),
  27 + ]
  28 +
  29 + operations = [
  30 + migrations.RunPython(trim_fields),
  31 + migrations.AlterField(
  32 + model_name='user',
  33 + name='facebook',
  34 + field=models.CharField(max_length=15, null=True, blank=True),
  35 + preserve_default=True,
  36 + ),
  37 +
  38 + migrations.AlterField(
  39 + model_name='user',
  40 + name='github',
  41 + field=models.CharField(max_length=39, null=True, verbose_name='github', blank=True),
  42 + preserve_default=True,
  43 + ),
  44 + migrations.AlterField(
  45 + model_name='user',
  46 + name='twitter',
  47 + field=models.CharField(max_length=15, null=True, blank=True),
  48 + preserve_default=True,
  49 + ),
  50 + ]
... ...
colab/accounts/migrations/0005_auto_20150312_1454.py 0 → 100644
... ... @@ -0,0 +1,29 @@
  1 +# -*- coding: utf-8 -*-
  2 +from __future__ import unicode_literals
  3 +
  4 +from django.contrib.auth.hashers import make_password
  5 +from django.db import models, migrations
  6 +from django.utils.crypto import get_random_string
  7 +
  8 +
  9 +def normalize_password(apps, schema_editor):
  10 + User = apps.get_model("accounts", "User")
  11 + for user in User.objects.all():
  12 + if len(user.password) is not 0:
  13 + continue
  14 +
  15 + rand_pwd = get_random_string()
  16 +
  17 + user.password = make_password(rand_pwd)
  18 + user.save()
  19 +
  20 +
  21 +class Migration(migrations.Migration):
  22 +
  23 + dependencies = [
  24 + ('accounts', '0004_auto_20150311_1818'),
  25 + ]
  26 +
  27 + operations = [
  28 + migrations.RunPython(normalize_password)
  29 + ]
... ...