author | Pawel Solyga <Pawel.Solyga@gmail.com> |
Sun, 01 Feb 2009 13:24:00 +0000 | |
changeset 1140 | a8eaea0b268d |
parent 1088 | 7ad48d59da3d |
child 1143 | b07b7d5b3e27 |
permissions | -rw-r--r-- |
601
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
2 |
# |
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2008 the Melange authors. |
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
4 |
# |
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
8 |
# |
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
10 |
# |
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
16 |
|
1028
43fdf6739e8d
Style fixes in soc.logic.cleaning module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
1013
diff
changeset
|
17 |
"""Generic cleaning methods. |
601
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
18 |
""" |
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
19 |
|
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
21 |
'"Todd Larsen" <tlarsen@google.com>', |
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
22 |
'"Sverre Rabbelier" <sverre@rabbelier.nl>', |
928
df051fc9d7a1
Replaced the boolean properties in soc/models/request.py with a state property.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
905
diff
changeset
|
23 |
'"Lennard de Rijk" <ljvderijk@gmail.com>', |
601
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
24 |
] |
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
25 |
|
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
26 |
|
1013
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
27 |
from google.appengine.api import users |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
28 |
|
601
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
29 |
from django import forms |
1083
b8018d7a9f23
Moved clean_club_app_link_id to cleaning.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1079
diff
changeset
|
30 |
from django.utils.translation import ugettext |
601
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
31 |
|
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
32 |
from soc.logic import validate |
1039
d53b963b1454
Added new clean_agrees_to_tos to cleaning.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1028
diff
changeset
|
33 |
from soc.logic.models import site as site_logic |
788
892877b7db07
Factored out the clean_existing_user method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
34 |
from soc.logic.models import user as user_logic |
601
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
35 |
|
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
36 |
|
1079
be1aacb33b0f
Changed clean_link_id to be in a wrapper form as well.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1039
diff
changeset
|
37 |
def clean_link_id(field_name): |
1088
7ad48d59da3d
Added a clean_scope_path to cleaning
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1085
diff
changeset
|
38 |
"""Checks if the field_name value is in a valid link ID format. |
1079
be1aacb33b0f
Changed clean_link_id to be in a wrapper form as well.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1039
diff
changeset
|
39 |
""" |
be1aacb33b0f
Changed clean_link_id to be in a wrapper form as well.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1039
diff
changeset
|
40 |
def wrapper(self): |
be1aacb33b0f
Changed clean_link_id to be in a wrapper form as well.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1039
diff
changeset
|
41 |
# convert to lowercase for user comfort |
be1aacb33b0f
Changed clean_link_id to be in a wrapper form as well.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1039
diff
changeset
|
42 |
link_id = self.cleaned_data.get(field_name).lower() |
be1aacb33b0f
Changed clean_link_id to be in a wrapper form as well.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1039
diff
changeset
|
43 |
if not validate.isLinkIdFormatValid(link_id): |
be1aacb33b0f
Changed clean_link_id to be in a wrapper form as well.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1039
diff
changeset
|
44 |
raise forms.ValidationError("This link ID is in wrong format.") |
be1aacb33b0f
Changed clean_link_id to be in a wrapper form as well.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1039
diff
changeset
|
45 |
return link_id |
be1aacb33b0f
Changed clean_link_id to be in a wrapper form as well.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1039
diff
changeset
|
46 |
return wrapper |
601
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
47 |
|
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
48 |
|
1088
7ad48d59da3d
Added a clean_scope_path to cleaning
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1085
diff
changeset
|
49 |
def clean_scope_path(field_name): |
7ad48d59da3d
Added a clean_scope_path to cleaning
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1085
diff
changeset
|
50 |
"""Checks if the field_name value is in a valid scope path format. |
7ad48d59da3d
Added a clean_scope_path to cleaning
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1085
diff
changeset
|
51 |
""" |
7ad48d59da3d
Added a clean_scope_path to cleaning
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1085
diff
changeset
|
52 |
def wrapper(self): |
7ad48d59da3d
Added a clean_scope_path to cleaning
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1085
diff
changeset
|
53 |
# convert to lowercase for user comfort |
7ad48d59da3d
Added a clean_scope_path to cleaning
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1085
diff
changeset
|
54 |
scope_path = self.cleaned_data.get(field_name).lower() |
7ad48d59da3d
Added a clean_scope_path to cleaning
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1085
diff
changeset
|
55 |
if not validate.isScopePathFormatValid(scope_path): |
7ad48d59da3d
Added a clean_scope_path to cleaning
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1085
diff
changeset
|
56 |
raise forms.ValidationError("This scope path is in wrong format.") |
7ad48d59da3d
Added a clean_scope_path to cleaning
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1085
diff
changeset
|
57 |
return scope_path |
7ad48d59da3d
Added a clean_scope_path to cleaning
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1085
diff
changeset
|
58 |
return wrapper |
7ad48d59da3d
Added a clean_scope_path to cleaning
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1085
diff
changeset
|
59 |
|
7ad48d59da3d
Added a clean_scope_path to cleaning
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1085
diff
changeset
|
60 |
|
1039
d53b963b1454
Added new clean_agrees_to_tos to cleaning.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1028
diff
changeset
|
61 |
def clean_agrees_to_tos(field_name): |
d53b963b1454
Added new clean_agrees_to_tos to cleaning.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1028
diff
changeset
|
62 |
"""Checks if there is a ToS to see if it is allowed to leave |
d53b963b1454
Added new clean_agrees_to_tos to cleaning.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1028
diff
changeset
|
63 |
the field_name field false. |
d53b963b1454
Added new clean_agrees_to_tos to cleaning.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1028
diff
changeset
|
64 |
""" |
d53b963b1454
Added new clean_agrees_to_tos to cleaning.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1028
diff
changeset
|
65 |
|
d53b963b1454
Added new clean_agrees_to_tos to cleaning.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1028
diff
changeset
|
66 |
def wrapper(self): |
d53b963b1454
Added new clean_agrees_to_tos to cleaning.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1028
diff
changeset
|
67 |
agrees_to_tos = self.cleaned_data.get(field_name) |
d53b963b1454
Added new clean_agrees_to_tos to cleaning.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1028
diff
changeset
|
68 |
|
d53b963b1454
Added new clean_agrees_to_tos to cleaning.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1028
diff
changeset
|
69 |
if not site_logic.logic.getToS(site_logic.logic.getSingleton()): |
d53b963b1454
Added new clean_agrees_to_tos to cleaning.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1028
diff
changeset
|
70 |
return agrees_to_tos |
d53b963b1454
Added new clean_agrees_to_tos to cleaning.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1028
diff
changeset
|
71 |
|
d53b963b1454
Added new clean_agrees_to_tos to cleaning.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1028
diff
changeset
|
72 |
# Site settings specify a site-wide ToS, so agreement is *required* |
d53b963b1454
Added new clean_agrees_to_tos to cleaning.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1028
diff
changeset
|
73 |
if agrees_to_tos: |
d53b963b1454
Added new clean_agrees_to_tos to cleaning.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1028
diff
changeset
|
74 |
return True |
d53b963b1454
Added new clean_agrees_to_tos to cleaning.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1028
diff
changeset
|
75 |
|
d53b963b1454
Added new clean_agrees_to_tos to cleaning.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1028
diff
changeset
|
76 |
# there was no agreement made so raise an error |
d53b963b1454
Added new clean_agrees_to_tos to cleaning.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1028
diff
changeset
|
77 |
raise forms.ValidationError( |
d53b963b1454
Added new clean_agrees_to_tos to cleaning.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1028
diff
changeset
|
78 |
'The site-wide Terms of Service must be accepted to participate' |
d53b963b1454
Added new clean_agrees_to_tos to cleaning.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1028
diff
changeset
|
79 |
' on this site.') |
d53b963b1454
Added new clean_agrees_to_tos to cleaning.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1028
diff
changeset
|
80 |
|
d53b963b1454
Added new clean_agrees_to_tos to cleaning.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1028
diff
changeset
|
81 |
return wrapper |
d53b963b1454
Added new clean_agrees_to_tos to cleaning.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1028
diff
changeset
|
82 |
|
788
892877b7db07
Factored out the clean_existing_user method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
83 |
def clean_existing_user(field_name): |
892877b7db07
Factored out the clean_existing_user method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
84 |
"""Check if the field_name field is a valid user. |
892877b7db07
Factored out the clean_existing_user method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
85 |
""" |
892877b7db07
Factored out the clean_existing_user method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
86 |
|
892877b7db07
Factored out the clean_existing_user method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
87 |
def wrapped(self): |
1079
be1aacb33b0f
Changed clean_link_id to be in a wrapper form as well.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1039
diff
changeset
|
88 |
link_id = clean_link_id(field_name)(self) |
788
892877b7db07
Factored out the clean_existing_user method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
89 |
|
1028
43fdf6739e8d
Style fixes in soc.logic.cleaning module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
1013
diff
changeset
|
90 |
user_entity = user_logic.logic.getForFields({'link_id': link_id}, |
43fdf6739e8d
Style fixes in soc.logic.cleaning module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
1013
diff
changeset
|
91 |
unique=True) |
788
892877b7db07
Factored out the clean_existing_user method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
92 |
|
892877b7db07
Factored out the clean_existing_user method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
93 |
if not user_entity: |
892877b7db07
Factored out the clean_existing_user method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
94 |
# user does not exist |
837
bc1c951bf3a0
Add missing blank line in soc.views.helper.params module. Fix docstring typo in soc.views.models.role module. Add missing dots at the end of sentences in soc.logic.cleaning and soc.view.models.user_self modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
788
diff
changeset
|
95 |
raise forms.ValidationError("This user does not exist.") |
788
892877b7db07
Factored out the clean_existing_user method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
96 |
|
892877b7db07
Factored out the clean_existing_user method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
97 |
return user_entity |
892877b7db07
Factored out the clean_existing_user method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
98 |
return wrapped |
892877b7db07
Factored out the clean_existing_user method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
99 |
|
1013
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
100 |
|
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
101 |
def clean_user_not_exist(field_name): |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
102 |
"""Check if the field_name value is a valid link_id and a user with the |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
103 |
link id does not exist. |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
104 |
""" |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
105 |
|
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
106 |
def wrapped(self): |
1079
be1aacb33b0f
Changed clean_link_id to be in a wrapper form as well.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1039
diff
changeset
|
107 |
link_id = clean_link_id(field_name)(self) |
1013
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
108 |
|
1028
43fdf6739e8d
Style fixes in soc.logic.cleaning module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
1013
diff
changeset
|
109 |
user_entity = user_logic.logic.getForFields({'link_id': link_id}, |
43fdf6739e8d
Style fixes in soc.logic.cleaning module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
1013
diff
changeset
|
110 |
unique=True) |
1013
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
111 |
|
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
112 |
if user_entity: |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
113 |
# user exists already |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
114 |
raise forms.ValidationError("There is already a user with this link id.") |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
115 |
|
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
116 |
return link_id |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
117 |
return wrapped |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
118 |
|
1028
43fdf6739e8d
Style fixes in soc.logic.cleaning module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
1013
diff
changeset
|
119 |
|
905
70eb2493a346
Rename clean_existing_user_not_equal_to_current function to clean_users_not_same in soc.logic.cleaning module and fix affected files.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
902
diff
changeset
|
120 |
def clean_users_not_same(field_name): |
886
f5847f24c56e
Added clean_existing_user_not_equal_to_current to clean the backup Administrator field in an application.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
867
diff
changeset
|
121 |
"""Check if the field_name field is a valid user and is not |
f5847f24c56e
Added clean_existing_user_not_equal_to_current to clean the backup Administrator field in an application.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
867
diff
changeset
|
122 |
equal to the current user. |
f5847f24c56e
Added clean_existing_user_not_equal_to_current to clean the backup Administrator field in an application.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
867
diff
changeset
|
123 |
""" |
f5847f24c56e
Added clean_existing_user_not_equal_to_current to clean the backup Administrator field in an application.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
867
diff
changeset
|
124 |
|
f5847f24c56e
Added clean_existing_user_not_equal_to_current to clean the backup Administrator field in an application.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
867
diff
changeset
|
125 |
def wrapped(self): |
f5847f24c56e
Added clean_existing_user_not_equal_to_current to clean the backup Administrator field in an application.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
867
diff
changeset
|
126 |
|
f5847f24c56e
Added clean_existing_user_not_equal_to_current to clean the backup Administrator field in an application.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
867
diff
changeset
|
127 |
clean_user_field = clean_existing_user(field_name) |
f5847f24c56e
Added clean_existing_user_not_equal_to_current to clean the backup Administrator field in an application.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
867
diff
changeset
|
128 |
user_entity = clean_user_field(self) |
f5847f24c56e
Added clean_existing_user_not_equal_to_current to clean the backup Administrator field in an application.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
867
diff
changeset
|
129 |
|
f5847f24c56e
Added clean_existing_user_not_equal_to_current to clean the backup Administrator field in an application.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
867
diff
changeset
|
130 |
current_user_entity = user_logic.logic.getForCurrentAccount() |
f5847f24c56e
Added clean_existing_user_not_equal_to_current to clean the backup Administrator field in an application.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
867
diff
changeset
|
131 |
|
f5847f24c56e
Added clean_existing_user_not_equal_to_current to clean the backup Administrator field in an application.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
867
diff
changeset
|
132 |
if user_entity.key() == current_user_entity.key(): |
f5847f24c56e
Added clean_existing_user_not_equal_to_current to clean the backup Administrator field in an application.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
867
diff
changeset
|
133 |
# users are equal |
1028
43fdf6739e8d
Style fixes in soc.logic.cleaning module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
1013
diff
changeset
|
134 |
raise forms.ValidationError("You cannot enter yourself here.") |
886
f5847f24c56e
Added clean_existing_user_not_equal_to_current to clean the backup Administrator field in an application.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
867
diff
changeset
|
135 |
|
f5847f24c56e
Added clean_existing_user_not_equal_to_current to clean the backup Administrator field in an application.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
867
diff
changeset
|
136 |
return user_entity |
f5847f24c56e
Added clean_existing_user_not_equal_to_current to clean the backup Administrator field in an application.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
867
diff
changeset
|
137 |
return wrapped |
f5847f24c56e
Added clean_existing_user_not_equal_to_current to clean the backup Administrator field in an application.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
867
diff
changeset
|
138 |
|
788
892877b7db07
Factored out the clean_existing_user method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
139 |
|
1013
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
140 |
def clean_user_account(field_name): |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
141 |
"""Returns the User with the given field_name value. |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
142 |
""" |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
143 |
def wrapped(self): |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
144 |
email_adress = self.cleaned_data.get(field_name).lower() |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
145 |
|
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
146 |
# get the user account for this email |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
147 |
user_account = users.User(email_adress) |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
148 |
|
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
149 |
return user_account |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
150 |
return wrapped |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
151 |
|
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
152 |
|
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
153 |
def clean_user_account_not_in_use(field_name): |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
154 |
"""Check if the field_name value contains an email |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
155 |
address that hasn't been used for an existing account. |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
156 |
""" |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
157 |
|
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
158 |
def wrapped(self): |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
159 |
email_adress = self.cleaned_data.get(field_name).lower() |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
160 |
|
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
161 |
# get the user account for this email and check if it's in use |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
162 |
user_account = users.User(email_adress) |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
163 |
|
1028
43fdf6739e8d
Style fixes in soc.logic.cleaning module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
1013
diff
changeset
|
164 |
fields = {'account': user_account} |
1013
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
165 |
user_entity = user_logic.logic.getForFields(fields, unique=True) |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
166 |
|
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
167 |
if user_entity or user_logic.logic.isFormerAccount(user_account): |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
168 |
raise forms.ValidationError("There is already a user with this email adress.") |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
169 |
|
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
170 |
return user_account |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
171 |
return wrapped |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
172 |
|
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
173 |
|
601
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
174 |
def clean_feed_url(self): |
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
175 |
feed_url = self.cleaned_data.get('feed_url') |
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
176 |
|
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
177 |
if feed_url == '': |
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
178 |
# feed url not supplied (which is OK), so do not try to validate it |
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
179 |
return None |
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
180 |
|
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
181 |
if not validate.isFeedURLValid(feed_url): |
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
182 |
raise forms.ValidationError('This URL is not a valid ATOM or RSS feed.') |
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
183 |
|
988f8a8cd6de
Added a cleaning module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
184 |
return feed_url |
898
adf5b7e98dcf
Added a cleaning method for a LinkProperty Field.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
886
diff
changeset
|
185 |
|
1028
43fdf6739e8d
Style fixes in soc.logic.cleaning module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
1013
diff
changeset
|
186 |
|
898
adf5b7e98dcf
Added a cleaning method for a LinkProperty Field.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
886
diff
changeset
|
187 |
def clean_url(field_name): |
adf5b7e98dcf
Added a cleaning method for a LinkProperty Field.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
886
diff
changeset
|
188 |
"""Clean method for cleaning a field belonging to a LinkProperty. |
adf5b7e98dcf
Added a cleaning method for a LinkProperty Field.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
886
diff
changeset
|
189 |
""" |
adf5b7e98dcf
Added a cleaning method for a LinkProperty Field.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
886
diff
changeset
|
190 |
|
adf5b7e98dcf
Added a cleaning method for a LinkProperty Field.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
886
diff
changeset
|
191 |
def wrapped(self): |
adf5b7e98dcf
Added a cleaning method for a LinkProperty Field.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
886
diff
changeset
|
192 |
|
adf5b7e98dcf
Added a cleaning method for a LinkProperty Field.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
886
diff
changeset
|
193 |
value = self.cleaned_data.get(field_name) |
adf5b7e98dcf
Added a cleaning method for a LinkProperty Field.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
886
diff
changeset
|
194 |
|
adf5b7e98dcf
Added a cleaning method for a LinkProperty Field.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
886
diff
changeset
|
195 |
# LinkProperty does not accept the empty string so we must return None |
adf5b7e98dcf
Added a cleaning method for a LinkProperty Field.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
886
diff
changeset
|
196 |
if not value or value == u'': |
adf5b7e98dcf
Added a cleaning method for a LinkProperty Field.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
886
diff
changeset
|
197 |
return None |
adf5b7e98dcf
Added a cleaning method for a LinkProperty Field.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
886
diff
changeset
|
198 |
|
adf5b7e98dcf
Added a cleaning method for a LinkProperty Field.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
886
diff
changeset
|
199 |
# call the Django URLField cleaning method to properly clean/validate this field |
967
be5f5533a07f
Changed clean_url to work with dynaform.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
928
diff
changeset
|
200 |
return forms.URLField.clean(self.fields[field_name], value) |
898
adf5b7e98dcf
Added a cleaning method for a LinkProperty Field.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
886
diff
changeset
|
201 |
return wrapped |
adf5b7e98dcf
Added a cleaning method for a LinkProperty Field.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
886
diff
changeset
|
202 |
|
1013
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
203 |
|
1083
b8018d7a9f23
Moved clean_club_app_link_id to cleaning.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1079
diff
changeset
|
204 |
def clean_new_club_link_id(field_name, club_logic, club_app_logic): |
b8018d7a9f23
Moved clean_club_app_link_id to cleaning.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1079
diff
changeset
|
205 |
"""Cleans the field_name value to check if it's a valid |
b8018d7a9f23
Moved clean_club_app_link_id to cleaning.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1079
diff
changeset
|
206 |
link_id for a new club. |
b8018d7a9f23
Moved clean_club_app_link_id to cleaning.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1079
diff
changeset
|
207 |
""" |
b8018d7a9f23
Moved clean_club_app_link_id to cleaning.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1079
diff
changeset
|
208 |
def wrapper(self): |
b8018d7a9f23
Moved clean_club_app_link_id to cleaning.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1079
diff
changeset
|
209 |
# validate the link_id |
b8018d7a9f23
Moved clean_club_app_link_id to cleaning.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1079
diff
changeset
|
210 |
club_link_id = clean_link_id(field_name)(self) |
b8018d7a9f23
Moved clean_club_app_link_id to cleaning.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1079
diff
changeset
|
211 |
|
b8018d7a9f23
Moved clean_club_app_link_id to cleaning.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1079
diff
changeset
|
212 |
# check if there is already an application with the given link_id |
b8018d7a9f23
Moved clean_club_app_link_id to cleaning.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1079
diff
changeset
|
213 |
fields = {'link_id': club_link_id, |
1085
0afbdd0905ef
Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1083
diff
changeset
|
214 |
'status': ['accepted','ignored','needs review','completed']} |
1083
b8018d7a9f23
Moved clean_club_app_link_id to cleaning.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1079
diff
changeset
|
215 |
club_app_entity = club_app_logic.logic.getForFields(fields, unique=True) |
b8018d7a9f23
Moved clean_club_app_link_id to cleaning.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1079
diff
changeset
|
216 |
|
b8018d7a9f23
Moved clean_club_app_link_id to cleaning.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1079
diff
changeset
|
217 |
if club_app_entity: |
b8018d7a9f23
Moved clean_club_app_link_id to cleaning.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1079
diff
changeset
|
218 |
raise forms.ValidationError( |
b8018d7a9f23
Moved clean_club_app_link_id to cleaning.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1079
diff
changeset
|
219 |
ugettext('This link ID is already in use, please specify another one')) |
b8018d7a9f23
Moved clean_club_app_link_id to cleaning.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1079
diff
changeset
|
220 |
|
b8018d7a9f23
Moved clean_club_app_link_id to cleaning.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1079
diff
changeset
|
221 |
# check if there is already a club with the given link_id |
1085
0afbdd0905ef
Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1083
diff
changeset
|
222 |
fields['status'] = ['new', 'active', 'inactive'] |
1083
b8018d7a9f23
Moved clean_club_app_link_id to cleaning.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1079
diff
changeset
|
223 |
club_entity = club_logic.logic.getForFields(fields, unique=True) |
b8018d7a9f23
Moved clean_club_app_link_id to cleaning.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1079
diff
changeset
|
224 |
|
b8018d7a9f23
Moved clean_club_app_link_id to cleaning.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1079
diff
changeset
|
225 |
if club_entity: |
b8018d7a9f23
Moved clean_club_app_link_id to cleaning.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1079
diff
changeset
|
226 |
raise forms.ValidationError( |
b8018d7a9f23
Moved clean_club_app_link_id to cleaning.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1079
diff
changeset
|
227 |
ugettext('This link ID is already in use, please specify another one')) |
b8018d7a9f23
Moved clean_club_app_link_id to cleaning.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1079
diff
changeset
|
228 |
|
b8018d7a9f23
Moved clean_club_app_link_id to cleaning.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1079
diff
changeset
|
229 |
return club_link_id |
b8018d7a9f23
Moved clean_club_app_link_id to cleaning.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1079
diff
changeset
|
230 |
return wrapper |
b8018d7a9f23
Moved clean_club_app_link_id to cleaning.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1079
diff
changeset
|
231 |
|
b8018d7a9f23
Moved clean_club_app_link_id to cleaning.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1079
diff
changeset
|
232 |
|
1013
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
233 |
def validate_user_edit(link_id_field, account_field): |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
234 |
"""Clean method for cleaning user edit form. |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
235 |
|
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
236 |
Raises ValidationError if: |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
237 |
-Another User has the given email address as account |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
238 |
-Another User has the given email address in it's FormerAccounts list |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
239 |
""" |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
240 |
def wrapper(self): |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
241 |
cleaned_data = self.cleaned_data |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
242 |
|
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
243 |
link_id = cleaned_data.get(link_id_field) |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
244 |
user_account = cleaned_data.get(account_field) |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
245 |
|
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
246 |
# if both fields were valid do this check |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
247 |
if link_id and user_account: |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
248 |
# get the user from the link_id in the form |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
249 |
fields = {'link_id': link_id} |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
250 |
user_entity = user_logic.logic.getForFields(fields, unique=True) |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
251 |
|
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
252 |
former_accounts = user_entity.former_accounts |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
253 |
|
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
254 |
# if it's not the user's current account or one of his former accounts |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
255 |
if (user_entity.account != user_account and |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
256 |
user_account not in former_accounts): |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
257 |
|
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
258 |
# get the user having the given account |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
259 |
fields = {'account': user_account} |
1028
43fdf6739e8d
Style fixes in soc.logic.cleaning module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
1013
diff
changeset
|
260 |
user_from_account_entity = user_logic.logic.getForFields(fields, |
43fdf6739e8d
Style fixes in soc.logic.cleaning module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
1013
diff
changeset
|
261 |
unique=True) |
1013
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
262 |
|
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
263 |
# if there is a user with the given account or it's a former account |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
264 |
if user_from_account_entity or user_logic.logic.isFormerAccount(user_account): |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
265 |
# raise an error because this email address can't be used |
1028
43fdf6739e8d
Style fixes in soc.logic.cleaning module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
1013
diff
changeset
|
266 |
raise forms.ValidationError("There is already a user with this email adress.") |
1013
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
267 |
|
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
268 |
return cleaned_data |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
269 |
return wrapper |
68c52d6b3fb4
Added new clean methods in preparation for new User View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
967
diff
changeset
|
270 |