equal
deleted
inserted
replaced
12 # distributed under the License is distributed on an "AS IS" BASIS, |
12 # distributed under the License is distributed on an "AS IS" BASIS, |
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 # See the License for the specific language governing permissions and |
14 # See the License for the specific language governing permissions and |
15 # limitations under the License. |
15 # limitations under the License. |
16 |
16 |
17 """Generic cleaning methods |
17 """Generic cleaning methods. |
18 """ |
18 """ |
19 |
19 |
20 __authors__ = [ |
20 __authors__ = [ |
21 '"Todd Larsen" <tlarsen@google.com>', |
21 '"Todd Larsen" <tlarsen@google.com>', |
22 '"Sverre Rabbelier" <sverre@rabbelier.nl>', |
22 '"Sverre Rabbelier" <sverre@rabbelier.nl>', |
48 link_id = self.cleaned_data.get(field_name).lower() |
48 link_id = self.cleaned_data.get(field_name).lower() |
49 |
49 |
50 if not validate.isLinkIdFormatValid(link_id): |
50 if not validate.isLinkIdFormatValid(link_id): |
51 raise forms.ValidationError("This link ID is in wrong format.") |
51 raise forms.ValidationError("This link ID is in wrong format.") |
52 |
52 |
53 user_entity = user_logic.logic.getForFields({'link_id' : link_id}, unique=True) |
53 user_entity = user_logic.logic.getForFields({'link_id': link_id}, |
|
54 unique=True) |
54 |
55 |
55 if not user_entity: |
56 if not user_entity: |
56 # user does not exist |
57 # user does not exist |
57 raise forms.ValidationError("This user does not exist.") |
58 raise forms.ValidationError("This user does not exist.") |
58 |
59 |
69 link_id = self.cleaned_data.get(field_name).lower() |
70 link_id = self.cleaned_data.get(field_name).lower() |
70 |
71 |
71 if not validate.isLinkIdFormatValid(link_id): |
72 if not validate.isLinkIdFormatValid(link_id): |
72 raise forms.ValidationError("This link ID is in wrong format.") |
73 raise forms.ValidationError("This link ID is in wrong format.") |
73 |
74 |
74 user_entity = user_logic.logic.getForFields({'link_id' : link_id}, unique=True) |
75 user_entity = user_logic.logic.getForFields({'link_id': link_id}, |
|
76 unique=True) |
75 |
77 |
76 if user_entity: |
78 if user_entity: |
77 # user exists already |
79 # user exists already |
78 raise forms.ValidationError("There is already a user with this link id.") |
80 raise forms.ValidationError("There is already a user with this link id.") |
79 |
81 |
80 return link_id |
82 return link_id |
81 return wrapped |
83 return wrapped |
82 |
84 |
|
85 |
83 def clean_users_not_same(field_name): |
86 def clean_users_not_same(field_name): |
84 """Check if the field_name field is a valid user and is not |
87 """Check if the field_name field is a valid user and is not |
85 equal to the current user. |
88 equal to the current user. |
86 """ |
89 """ |
87 |
90 |
92 |
95 |
93 current_user_entity = user_logic.logic.getForCurrentAccount() |
96 current_user_entity = user_logic.logic.getForCurrentAccount() |
94 |
97 |
95 if user_entity.key() == current_user_entity.key(): |
98 if user_entity.key() == current_user_entity.key(): |
96 # users are equal |
99 # users are equal |
97 raise forms.ValidationError("You cannot enter yourself here") |
100 raise forms.ValidationError("You cannot enter yourself here.") |
98 |
101 |
99 return user_entity |
102 return user_entity |
100 return wrapped |
103 return wrapped |
101 |
104 |
102 |
105 |
122 email_adress = self.cleaned_data.get(field_name).lower() |
125 email_adress = self.cleaned_data.get(field_name).lower() |
123 |
126 |
124 # get the user account for this email and check if it's in use |
127 # get the user account for this email and check if it's in use |
125 user_account = users.User(email_adress) |
128 user_account = users.User(email_adress) |
126 |
129 |
127 fields = {'account' : user_account} |
130 fields = {'account': user_account} |
128 user_entity = user_logic.logic.getForFields(fields, unique=True) |
131 user_entity = user_logic.logic.getForFields(fields, unique=True) |
129 |
132 |
130 if user_entity or user_logic.logic.isFormerAccount(user_account): |
133 if user_entity or user_logic.logic.isFormerAccount(user_account): |
131 raise forms.ValidationError("There is already a user with this email adress.") |
134 raise forms.ValidationError("There is already a user with this email adress.") |
132 |
135 |
143 |
146 |
144 if not validate.isFeedURLValid(feed_url): |
147 if not validate.isFeedURLValid(feed_url): |
145 raise forms.ValidationError('This URL is not a valid ATOM or RSS feed.') |
148 raise forms.ValidationError('This URL is not a valid ATOM or RSS feed.') |
146 |
149 |
147 return feed_url |
150 return feed_url |
|
151 |
148 |
152 |
149 def clean_url(field_name): |
153 def clean_url(field_name): |
150 """Clean method for cleaning a field belonging to a LinkProperty. |
154 """Clean method for cleaning a field belonging to a LinkProperty. |
151 """ |
155 """ |
152 |
156 |
188 if (user_entity.account != user_account and |
192 if (user_entity.account != user_account and |
189 user_account not in former_accounts): |
193 user_account not in former_accounts): |
190 |
194 |
191 # get the user having the given account |
195 # get the user having the given account |
192 fields = {'account': user_account} |
196 fields = {'account': user_account} |
193 user_from_account_entity = user_logic.logic.getForFields(fields, unique=True) |
197 user_from_account_entity = user_logic.logic.getForFields(fields, |
|
198 unique=True) |
194 |
199 |
195 # if there is a user with the given account or it's a former account |
200 # if there is a user with the given account or it's a former account |
196 if user_from_account_entity or user_logic.logic.isFormerAccount(user_account): |
201 if user_from_account_entity or user_logic.logic.isFormerAccount(user_account): |
197 # raise an error because this email address can't be used |
202 # raise an error because this email address can't be used |
198 raise forms.ValidationError("There is already a user with this email adress.") |
203 raise forms.ValidationError("There is already a user with this email adress.") |
199 |
204 |
200 return cleaned_data |
205 return cleaned_data |
201 return wrapper |
206 return wrapper |
202 |
207 |