Commit 16a3f0015718fd2bb4bcedbec9a2e8d47cf25068

Authored by Rodrigo Siqueira de Melo
1 parent f59cc898

Add migration to accounts

colab/accounts/migrations/0004_auto_20150311_1818.py 0 → 100644
@@ -0,0 +1,50 @@ @@ -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 + ]