Statistics
| Branch: | Tag: | Revision:

root / snf-astakos-app / astakos / im / migrations / 0045_set_username_uuid.py @ 2b80cfeb

History | View | Annotate | Download (21.5 kB)

1
# encoding: utf-8
2
import datetime
3
import uuid
4

    
5
from south.db import db
6
from south.v2 import DataMigration
7
from django.db import models
8
from django.core.validators import email_re
9

    
10
class Migration(DataMigration):
11

    
12
    def forwards(self, orm):
13
        for u in orm.AstakosUser.objects.all():
14
            save = False
15
            while not u.uuid:
16
                uuid_val =  str(uuid.uuid4())
17
                try:
18
                    orm.AstakosUser.objects.get(uuid=uuid_val)
19
                except orm.AstakosUser.DoesNotExist, e:
20
                    u.uuid = uuid_val
21
                    save = True
22
            if not email_re.match(u.username):
23
                u.username = u.email.lower()
24
                save = True
25
            if save:
26
                u.save()
27

    
28
    def backwards(self, orm):
29
        for u in orm.AstakosUser.objects.all():
30
            u.uuid = None
31
            if email_re.match(u.username):
32
                username = None
33
                while not username:
34
                    username_val =  uuid.uuid4().hex[:30]
35
                    try:
36
                        orm.AstakosUser.objects.get(username = username_val)
37
                    except orm.AstakosUser.DoesNotExist, e:
38
                        username = username_val
39
                u.username = username
40
            u.save()
41

    
42
    models = {
43
        'auth.group': {
44
            'Meta': {'object_name': 'Group'},
45
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
46
            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
47
            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
48
        },
49
        'auth.permission': {
50
            'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
51
            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
52
            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
53
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
54
            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
55
        },
56
        'auth.user': {
57
            'Meta': {'object_name': 'User'},
58
            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
59
            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
60
            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
61
            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
62
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
63
            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
64
            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
65
            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
66
            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
67
            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
68
            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
69
            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
70
            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '75'})
71
        },
72
        'contenttypes.contenttype': {
73
            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
74
            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
75
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
76
            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
77
            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
78
        },
79
        'im.additionalmail': {
80
            'Meta': {'object_name': 'AdditionalMail'},
81
            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
82
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
83
            'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.AstakosUser']"})
84
        },
85
        'im.approvalterms': {
86
            'Meta': {'object_name': 'ApprovalTerms'},
87
            'date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 12, 28, 10, 3, 44, 519671)', 'db_index': 'True'}),
88
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
89
            'location': ('django.db.models.fields.CharField', [], {'max_length': '255'})
90
        },
91
        'im.astakosuser': {
92
            'Meta': {'object_name': 'AstakosUser', '_ormbases': ['auth.User']},
93
            'activation_sent': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
94
            'affiliation': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
95
            'auth_token': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
96
            'auth_token_created': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
97
            'auth_token_expires': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
98
            'date_signed_terms': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
99
            'disturbed_quota': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}),
100
            'email_verified': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
101
            'has_credits': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
102
            'has_signed_terms': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
103
            'invitations': ('django.db.models.fields.IntegerField', [], {'default': '100'}),
104
            'is_verified': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
105
            'level': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
106
            'policy': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['im.Resource']", 'null': 'True', 'through': "orm['im.AstakosUserQuota']", 'symmetrical': 'False'}),
107
            'provider': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
108
            'third_party_identifier': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
109
            'updated': ('django.db.models.fields.DateTimeField', [], {}),
110
            'user_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True', 'primary_key': 'True'}),
111
            'uuid': ('django.db.models.fields.CharField', [], {'max_length': '255', 'unique': 'True', 'null': 'True'})
112
        },
113
        'im.astakosuserauthprovider': {
114
            'Meta': {'ordering': "('module', 'created')", 'unique_together': "(('identifier', 'module', 'user'),)", 'object_name': 'AstakosUserAuthProvider'},
115
            'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
116
            'affiliation': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '255', 'null': 'True', 'blank': 'True'}),
117
            'auth_backend': ('django.db.models.fields.CharField', [], {'default': "'astakos'", 'max_length': '255'}),
118
            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
119
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
120
            'identifier': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
121
            'info_data': ('django.db.models.fields.TextField', [], {'default': "''", 'null': 'True', 'blank': 'True'}),
122
            'module': ('django.db.models.fields.CharField', [], {'default': "'local'", 'max_length': '255'}),
123
            'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'auth_providers'", 'to': "orm['im.AstakosUser']"})
124
        },
125
        'im.astakosuserquota': {
126
            'Meta': {'unique_together': "(('resource', 'user'),)", 'object_name': 'AstakosUserQuota'},
127
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
128
            'limit': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True'}),
129
            'resource': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.Resource']"}),
130
            'uplimit': ('django.db.models.fields.BigIntegerField', [], {'null': 'True'}),
131
            'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.AstakosUser']"})
132
        },
133
        'im.emailchange': {
134
            'Meta': {'object_name': 'EmailChange'},
135
            'activation_key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '40', 'db_index': 'True'}),
136
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
137
            'new_email_address': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
138
            'requested_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 12, 28, 10, 3, 44, 521365)'}),
139
            'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'emailchanges'", 'unique': 'True', 'to': "orm['im.AstakosUser']"})
140
        },
141
        'im.invitation': {
142
            'Meta': {'object_name': 'Invitation'},
143
            'code': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True'}),
144
            'consumed': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
145
            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
146
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
147
            'inviter': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'invitations_sent'", 'null': 'True', 'to': "orm['im.AstakosUser']"}),
148
            'is_consumed': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
149
            'realname': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
150
            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
151
        },
152
        'im.memberjoinpolicy': {
153
            'Meta': {'object_name': 'MemberJoinPolicy'},
154
            'description': ('django.db.models.fields.CharField', [], {'max_length': '80'}),
155
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
156
            'policy': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255', 'db_index': 'True'})
157
        },
158
        'im.memberleavepolicy': {
159
            'Meta': {'object_name': 'MemberLeavePolicy'},
160
            'description': ('django.db.models.fields.CharField', [], {'max_length': '80'}),
161
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
162
            'policy': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255', 'db_index': 'True'})
163
        },
164
        'im.pendingthirdpartyuser': {
165
            'Meta': {'unique_together': "(('provider', 'third_party_identifier'),)", 'object_name': 'PendingThirdPartyUser'},
166
            'affiliation': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
167
            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'null': 'True', 'blank': 'True'}),
168
            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}),
169
            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
170
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
171
            'info': ('django.db.models.fields.TextField', [], {'default': "''", 'null': 'True', 'blank': 'True'}),
172
            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
173
            'provider': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
174
            'third_party_identifier': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
175
            'token': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
176
            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
177
        },
178
        'im.project': {
179
            'Meta': {'object_name': 'Project'},
180
            'application': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'project'", 'unique': 'True', 'to': "orm['im.ProjectApplication']"}),
181
            'creation_date': ('django.db.models.fields.DateTimeField', [], {}),
182
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
183
            'last_approval_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
184
            'members': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['im.AstakosUser']", 'through': "orm['im.ProjectMembership']", 'symmetrical': 'False'}),
185
            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80', 'db_index': 'True'}),
186
            'termination_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
187
            'termination_start_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True'})
188
        },
189
        'im.projectapplication': {
190
            'Meta': {'object_name': 'ProjectApplication'},
191
            'applicant': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'projects_applied'", 'to': "orm['im.AstakosUser']"}),
192
            'comments': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
193
            'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
194
            'end_date': ('django.db.models.fields.DateTimeField', [], {}),
195
            'homepage': ('django.db.models.fields.URLField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
196
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
197
            'issue_date': ('django.db.models.fields.DateTimeField', [], {}),
198
            'limit_on_members_number': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True', 'blank': 'True'}),
199
            'member_join_policy': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.MemberJoinPolicy']"}),
200
            'member_leave_policy': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.MemberLeavePolicy']"}),
201
            'name': ('django.db.models.fields.CharField', [], {'max_length': '80'}),
202
            'owner': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'projects_owned'", 'to': "orm['im.AstakosUser']"}),
203
            'precursor_application': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['im.ProjectApplication']", 'unique': 'True', 'null': 'True', 'blank': 'True'}),
204
            'resource_grants': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['im.Resource']", 'null': 'True', 'through': "orm['im.ProjectResourceGrant']", 'blank': 'True'}),
205
            'start_date': ('django.db.models.fields.DateTimeField', [], {}),
206
            'state': ('django.db.models.fields.CharField', [], {'default': "'Unknown'", 'max_length': '80'})
207
        },
208
        'im.projectmembership': {
209
            'Meta': {'unique_together': "(('person', 'project'),)", 'object_name': 'ProjectMembership'},
210
            'acceptance_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'db_index': 'True'}),
211
            'application': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'memberships'", 'null': 'True', 'to': "orm['im.ProjectApplication']"}),
212
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
213
            'leave_request_date': ('django.db.models.fields.DateField', [], {'null': 'True'}),
214
            'pending_application': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'pending_memebrships'", 'null': 'True', 'to': "orm['im.ProjectApplication']"}),
215
            'pending_serial': ('django.db.models.fields.BigIntegerField', [], {'null': 'True', 'db_index': 'True'}),
216
            'person': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.AstakosUser']"}),
217
            'project': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.Project']"}),
218
            'request_date': ('django.db.models.fields.DateField', [], {'default': 'datetime.datetime(2012, 12, 28, 10, 3, 44, 529721)'}),
219
            'state': ('django.db.models.fields.IntegerField', [], {'default': '0'})
220
        },
221
        'im.projectmembershiphistory': {
222
            'Meta': {'object_name': 'ProjectMembershipHistory'},
223
            'date': ('django.db.models.fields.DateField', [], {'default': 'datetime.datetime.now'}),
224
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
225
            'person': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.AstakosUser']"}),
226
            'project': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.Project']"}),
227
            'reason': ('django.db.models.fields.IntegerField', [], {}),
228
            'serial': ('django.db.models.fields.BigIntegerField', [], {})
229
        },
230
        'im.projectresourcegrant': {
231
            'Meta': {'unique_together': "(('resource', 'project_application'),)", 'object_name': 'ProjectResourceGrant'},
232
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
233
            'member_capacity': ('django.db.models.fields.BigIntegerField', [], {'null': 'True'}),
234
            'member_export_limit': ('django.db.models.fields.BigIntegerField', [], {'null': 'True'}),
235
            'member_import_limit': ('django.db.models.fields.BigIntegerField', [], {'null': 'True'}),
236
            'project_application': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.ProjectApplication']", 'null': 'True'}),
237
            'project_capacity': ('django.db.models.fields.BigIntegerField', [], {'null': 'True'}),
238
            'project_export_limit': ('django.db.models.fields.BigIntegerField', [], {'null': 'True'}),
239
            'project_import_limit': ('django.db.models.fields.BigIntegerField', [], {'null': 'True'}),
240
            'resource': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.Resource']"})
241
        },
242
        'im.resource': {
243
            'Meta': {'unique_together': "(('name', 'service'),)", 'object_name': 'Resource'},
244
            'desc': ('django.db.models.fields.TextField', [], {'null': 'True'}),
245
            'group': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
246
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
247
            'meta': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['im.ResourceMetadata']", 'symmetrical': 'False'}),
248
            'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
249
            'service': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.Service']"}),
250
            'unit': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'})
251
        },
252
        'im.resourcemetadata': {
253
            'Meta': {'object_name': 'ResourceMetadata'},
254
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
255
            'key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255', 'db_index': 'True'}),
256
            'value': ('django.db.models.fields.CharField', [], {'max_length': '255'})
257
        },
258
        'im.serial': {
259
            'Meta': {'object_name': 'Serial'},
260
            'serial': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
261
        },
262
        'im.service': {
263
            'Meta': {'object_name': 'Service'},
264
            'auth_token': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
265
            'auth_token_created': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
266
            'auth_token_expires': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
267
            'icon': ('django.db.models.fields.FilePathField', [], {'max_length': '100', 'blank': 'True'}),
268
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
269
            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255', 'db_index': 'True'}),
270
            'url': ('django.db.models.fields.FilePathField', [], {'max_length': '100'})
271
        },
272
        'im.sessioncatalog': {
273
            'Meta': {'object_name': 'SessionCatalog'},
274
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
275
            'session_key': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
276
            'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'sessions'", 'null': 'True', 'to': "orm['im.AstakosUser']"})
277
        }
278
    }
279

    
280
    complete_apps = ['im']