author | Lennard de Rijk <ljvderijk@gmail.com> |
Sun, 15 Mar 2009 16:10:19 +0000 | |
changeset 1873 | bbd4fa245285 |
parent 1603 | ec08b2b00439 |
child 2068 | f5e8fbbd3bea |
permissions | -rw-r--r-- |
1603
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
2 |
# |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2008 the Melange authors. |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
4 |
# |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
8 |
# |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
10 |
# |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
16 |
|
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
17 |
"""Converts the DB from an old scheme to a new one. |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
18 |
""" |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
19 |
|
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
21 |
'"Sverre Rabbelier" <sverre@rabbelier.nl>', |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
22 |
] |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
23 |
|
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
24 |
|
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
25 |
from google.appengine.api import users |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
26 |
|
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
27 |
from django import http |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
28 |
|
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
29 |
from soc.models import user as user_model |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
30 |
from soc.logic import accounts |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
31 |
from soc.logic.models.user import logic as user_logic |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
32 |
|
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
33 |
|
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
34 |
def convert_user_accounts(*args, **kwargs): |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
35 |
"""Converts all current user accounts to normalized form. |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
36 |
""" |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
37 |
|
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
38 |
data = user_logic.getAll(user_model.User.all()) |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
39 |
|
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
40 |
for user in data: |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
41 |
normalized = accounts.normalizeAccount(user.account) |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
42 |
if user.account != normalized: |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
43 |
user.account = normalized |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
44 |
user.put() |
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
45 |
|
ec08b2b00439
Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
46 |
return http.HttpResponse('Done') |