89 """Checks if the field_name value is in a valid link ID format. |
93 """Checks if the field_name value is in a valid link ID format. |
90 """ |
94 """ |
91 |
95 |
92 @check_field_is_empty(field_name) |
96 @check_field_is_empty(field_name) |
93 def wrapper(self): |
97 def wrapper(self): |
|
98 """Decorator wrapper method. |
|
99 """ |
94 # convert to lowercase for user comfort |
100 # convert to lowercase for user comfort |
95 link_id = self.cleaned_data.get(field_name).lower() |
101 link_id = self.cleaned_data.get(field_name).lower() |
96 if not validate.isLinkIdFormatValid(link_id): |
102 if not validate.isLinkIdFormatValid(link_id): |
97 raise forms.ValidationError("This link ID is in wrong format.") |
103 raise forms.ValidationError("This link ID is in wrong format.") |
98 return link_id |
104 return link_id |
103 """Checks if the field_name value is in a valid scope path format. |
109 """Checks if the field_name value is in a valid scope path format. |
104 """ |
110 """ |
105 |
111 |
106 @check_field_is_empty(field_name) |
112 @check_field_is_empty(field_name) |
107 def wrapper(self): |
113 def wrapper(self): |
|
114 """Decorator wrapper method. |
|
115 """ |
108 # convert to lowercase for user comfort |
116 # convert to lowercase for user comfort |
109 scope_path = self.cleaned_data.get(field_name).lower() |
117 scope_path = self.cleaned_data.get(field_name).lower() |
110 if not validate.isScopePathFormatValid(scope_path): |
118 if not validate.isScopePathFormatValid(scope_path): |
111 raise forms.ValidationError("This scope path is in wrong format.") |
119 raise forms.ValidationError("This scope path is in wrong format.") |
112 return scope_path |
120 return scope_path |
233 address that hasn't been used for an existing account. |
252 address that hasn't been used for an existing account. |
234 """ |
253 """ |
235 |
254 |
236 @check_field_is_empty(field_name) |
255 @check_field_is_empty(field_name) |
237 def wrapped(self): |
256 def wrapped(self): |
|
257 """Decorator wrapper method. |
|
258 """ |
238 email_adress = self.cleaned_data.get(field_name).lower() |
259 email_adress = self.cleaned_data.get(field_name).lower() |
239 |
260 |
240 # get the user account for this email and check if it's in use |
261 # get the user account for this email and check if it's in use |
241 user_account = users.User(email_adress) |
262 user_account = users.User(email_adress) |
242 |
263 |
243 fields = {'account': user_account} |
264 fields = {'account': user_account} |
244 user_entity = user_logic.logic.getForFields(fields, unique=True) |
265 user_entity = user_logic.logic.getForFields(fields, unique=True) |
245 |
266 |
246 if user_entity or user_logic.logic.isFormerAccount(user_account): |
267 if user_entity or user_logic.logic.isFormerAccount(user_account): |
247 raise forms.ValidationError("There is already a user with this email adress.") |
268 raise forms.ValidationError("There is already a user " |
|
269 "with this email adress.") |
248 |
270 |
249 return user_account |
271 return user_account |
250 return wrapped |
272 return wrapped |
251 |
273 |
252 |
274 |
253 def clean_feed_url(self): |
275 def clean_feed_url(self): |
|
276 """Clean method for cleaning feed url. |
|
277 """ |
254 feed_url = self.cleaned_data.get('feed_url') |
278 feed_url = self.cleaned_data.get('feed_url') |
255 |
279 |
256 if feed_url == '': |
280 if feed_url == '': |
257 # feed url not supplied (which is OK), so do not try to validate it |
281 # feed url not supplied (which is OK), so do not try to validate it |
258 return None |
282 return None |
277 """Clean method for cleaning a field belonging to a LinkProperty. |
303 """Clean method for cleaning a field belonging to a LinkProperty. |
278 """ |
304 """ |
279 |
305 |
280 @check_field_is_empty(field_name) |
306 @check_field_is_empty(field_name) |
281 def wrapped(self): |
307 def wrapped(self): |
282 |
308 """Decorator wrapper method. |
|
309 """ |
283 value = self.cleaned_data.get(field_name) |
310 value = self.cleaned_data.get(field_name) |
284 |
311 |
285 # call the Django URLField cleaning method to properly clean/validate this field |
312 # call the Django URLField cleaning method to |
|
313 # properly clean/validate this field |
286 return forms.URLField.clean(self.fields[field_name], value) |
314 return forms.URLField.clean(self.fields[field_name], value) |
287 return wrapped |
315 return wrapped |
288 |
316 |
289 |
317 |
290 def validate_user_edit(link_id_field, account_field): |
318 def validate_user_edit(link_id_field, account_field): |
314 fields = {'account': user_account} |
344 fields = {'account': user_account} |
315 user_from_account_entity = user_logic.logic.getForFields(fields, |
345 user_from_account_entity = user_logic.logic.getForFields(fields, |
316 unique=True) |
346 unique=True) |
317 |
347 |
318 # if there is a user with the given account or it's a former account |
348 # if there is a user with the given account or it's a former account |
319 if user_from_account_entity or user_logic.logic.isFormerAccount(user_account): |
349 if user_from_account_entity or \ |
|
350 user_logic.logic.isFormerAccount(user_account): |
320 # raise an error because this email address can't be used |
351 # raise an error because this email address can't be used |
321 raise forms.ValidationError("There is already a user with this email address.") |
352 raise forms.ValidationError("There is already a user with " |
|
353 "this email address.") |
322 |
354 |
323 return cleaned_data |
355 return cleaned_data |
324 return wrapper |
356 return wrapper |
325 |
357 |
326 |
358 |
332 -A application with this link id and scope path already exists |
364 -A application with this link id and scope path already exists |
333 -A group with this link id and scope path already exists |
365 -A group with this link id and scope path already exists |
334 """ |
366 """ |
335 |
367 |
336 def wrapper(self): |
368 def wrapper(self): |
337 cleaned_data = self.cleaned_data |
369 """Decorator wrapper method. |
338 |
370 """ |
339 fields = {} |
371 cleaned_data = self.cleaned_data |
340 |
372 |
341 link_id = cleaned_data.get(link_id_field) |
373 fields = {} |
342 |
374 |
343 if link_id: |
375 link_id = cleaned_data.get(link_id_field) |
344 fields['link_id'] = link_id |
376 |
345 |
377 if link_id: |
346 scope_path = cleaned_data.get(scope_path_field) |
378 fields['link_id'] = link_id |
347 if scope_path: |
379 |
348 fields['scope_path'] = scope_path |
380 scope_path = cleaned_data.get(scope_path_field) |
349 |
381 if scope_path: |
350 # get the application |
382 fields['scope_path'] = scope_path |
351 group_app_entity = group_app_logic.logic.getForFields(fields, unique=True) |
383 |
352 |
384 # get the application |
353 # get the current user |
385 group_app_entity = group_app_logic.logic.getForFields(fields, unique=True) |
354 user_entity = user_logic.logic.getForCurrentAccount() |
386 |
355 |
387 # get the current user |
356 # make sure it's not the applicant creating the new group |
388 user_entity = user_logic.logic.getForCurrentAccount() |
357 if group_app_entity and ( |
389 |
358 group_app_entity.applicant.key() != user_entity.key()): |
390 # make sure it's not the applicant creating the new group |
359 # add the error message to the link id field |
391 if group_app_entity and ( |
360 self._errors[link_id_field] = ErrorList([DEF_LINK_ID_IN_USE_MSG]) |
392 group_app_entity.applicant.key() != user_entity.key()): |
361 del cleaned_data[link_id_field] |
393 # add the error message to the link id field |
362 # return the new cleaned_data |
394 self._errors[link_id_field] = ErrorList([DEF_LINK_ID_IN_USE_MSG]) |
363 return cleaned_data |
395 del cleaned_data[link_id_field] |
364 |
396 # return the new cleaned_data |
365 # check if there is already a group for the given fields |
397 return cleaned_data |
366 group_entity = group_logic.logic.getForFields(fields, unique=True) |
398 |
367 |
399 # check if there is already a group for the given fields |
368 if group_entity: |
400 group_entity = group_logic.logic.getForFields(fields, unique=True) |
369 # add the error message to the link id field |
401 |
370 self._errors[link_id_field] = ErrorList([DEF_LINK_ID_IN_USE_MSG]) |
402 if group_entity: |
371 del cleaned_data[link_id_field] |
403 # add the error message to the link id field |
372 # return the new cleaned_data |
404 self._errors[link_id_field] = ErrorList([DEF_LINK_ID_IN_USE_MSG]) |
373 return cleaned_data |
405 del cleaned_data[link_id_field] |
374 |
406 # return the new cleaned_data |
375 return cleaned_data |
407 return cleaned_data |
|
408 |
|
409 return cleaned_data |
376 return wrapper |
410 return wrapper |
377 |
411 |
378 def validate_student_proposal(org_field, scope_field, |
412 def validate_student_proposal(org_field, scope_field, |
379 student_logic, org_logic): |
413 student_logic, org_logic): |
380 """Validates the form of a student proposal. |
414 """Validates the form of a student proposal. |
420 def validate_document_acl(view): |
456 def validate_document_acl(view): |
421 """Validates that the document ACL settings are correct. |
457 """Validates that the document ACL settings are correct. |
422 """ |
458 """ |
423 |
459 |
424 def wrapper(self): |
460 def wrapper(self): |
|
461 """Decorator wrapper method. |
|
462 """ |
425 cleaned_data = self.cleaned_data |
463 cleaned_data = self.cleaned_data |
426 read_access = cleaned_data.get('read_access') |
464 read_access = cleaned_data.get('read_access') |
427 write_access = cleaned_data.get('write_access') |
465 write_access = cleaned_data.get('write_access') |
428 |
466 |
429 if not (read_access and write_access and ('prefix' in cleaned_data)): |
467 if not (read_access and write_access and ('prefix' in cleaned_data)): |