equal
deleted
inserted
replaced
38 skip_properties=['former_accounts']) |
38 skip_properties=['former_accounts']) |
39 |
39 |
40 def isFormerAccount(self, account): |
40 def isFormerAccount(self, account): |
41 """Returns true if account is a former account of some User. |
41 """Returns true if account is a former account of some User. |
42 """ |
42 """ |
43 # TODO(pawel.solyga): replace 1000 with solution that works for any number of queries |
43 # TODO(pawel.solyga): replace 1000 with solution that works for any |
|
44 # number of queries |
44 users_with_former_accounts = soc.models.user.User.gql( |
45 users_with_former_accounts = soc.models.user.User.gql( |
45 'WHERE former_accounts != :1', None).fetch(1000) |
46 'WHERE former_accounts != :1', None).fetch(1000) |
46 |
47 |
47 for former_account_user in users_with_former_accounts: |
48 for former_account_user in users_with_former_accounts: |
48 if account in former_account_user.former_accounts: |
49 if account in former_account_user.former_accounts: |
72 """See base.Logic.getKeyFieldNames. |
73 """See base.Logic.getKeyFieldNames. |
73 """ |
74 """ |
74 |
75 |
75 return ['link_id'] |
76 return ['link_id'] |
76 |
77 |
77 def updateOrCreateFromAccount(self, properties, account): |
|
78 """Like updateOrCreateFromKeyName, but resolves account to key_name first. |
|
79 """ |
|
80 |
|
81 # attempt to retrieve the existing entity |
|
82 user = soc.models.user.User.gql('WHERE account = :1', account).get() |
|
83 |
|
84 if user: |
|
85 key_name = user.key().name() |
|
86 else: |
|
87 raise |
|
88 key_name = self.getKeyNameForFields({'link_id': properties['link_id']}) |
|
89 |
|
90 return self.updateOrCreateFromKeyName(properties, key_name) |
|
91 |
|
92 def _updateField(self, model, name, value): |
78 def _updateField(self, model, name, value): |
93 """Special case logic for account. |
79 """Special case logic for account. |
94 |
80 |
95 When the account is changed, the former_accounts field should be appended |
81 When the account is changed, the former_accounts field should be appended |
96 with the old account. |
82 with the old account. |
97 """ |
83 """ |
98 if name == 'account' and model.account != value: |
84 if (name == 'account') and (model.account != value): |
99 model.former_accounts.append(model.account) |
85 model.former_accounts.append(model.account) |
100 |
86 |
101 return True |
87 return True |
102 |
88 |
103 |
89 |