26 |
26 |
27 import datetime |
27 import datetime |
28 |
28 |
29 from google.appengine.api import users |
29 from google.appengine.api import users |
30 |
30 |
|
31 from django import forms |
31 from django import http |
32 from django import http |
32 from django.utils.encoding import force_unicode |
33 from django.utils.encoding import force_unicode |
33 from django.utils.safestring import mark_safe |
34 from django.utils.safestring import mark_safe |
34 from django.utils.translation import ugettext |
35 from django.utils.translation import ugettext |
35 |
36 |
38 from soc.logic import models as model_logic |
39 from soc.logic import models as model_logic |
39 from soc.logic.models.user import logic as user_logic |
40 from soc.logic.models.user import logic as user_logic |
40 from soc.views import helper |
41 from soc.views import helper |
41 from soc.views.helper import access |
42 from soc.views.helper import access |
42 from soc.views.helper import decorators |
43 from soc.views.helper import decorators |
|
44 from soc.views.helper import dynaform |
43 from soc.views.helper import redirects |
45 from soc.views.helper import redirects |
44 from soc.views.helper import widgets |
46 from soc.views.helper import widgets |
45 from soc.views.models import base |
47 from soc.views.models import base |
46 from soc.views.models import user as user_view |
48 from soc.views.models import user as user_view |
47 |
49 |
82 new_params['save_message'] = [ugettext('Profile saved.')] |
84 new_params['save_message'] = [ugettext('Profile saved.')] |
83 new_params['edit_redirect'] = '/%(url_name)s/edit_profile' |
85 new_params['edit_redirect'] = '/%(url_name)s/edit_profile' |
84 |
86 |
85 # set the specific fields for the users profile page |
87 # set the specific fields for the users profile page |
86 new_params['extra_dynaexclude'] = ['former_accounts', |
88 new_params['extra_dynaexclude'] = ['former_accounts', |
87 'account', 'is_developer', 'status'] |
89 'account', 'is_developer', 'status', 'agreed_to_tos_on'] |
88 |
90 |
89 new_params['create_extra_dynafields'] = { |
91 new_params['create_extra_dynafields'] = { |
90 'clean_agreed_to_tos': cleaning.clean_agrees_to_tos('agreed_to_tos'), |
92 'clean_agreed_to_tos': cleaning.clean_agrees_to_tos('agreed_to_tos'), |
91 'clean_link_id': cleaning.clean_user_not_exist('link_id'),} |
93 'clean_link_id': cleaning.clean_user_not_exist('link_id'),} |
92 |
94 |
93 new_params['edit_extra_dynafields'] = { |
95 new_params['edit_extra_dynafields'] = { |
94 'clean_link_id': cleaning.clean_link_id('link_id') |
96 'clean_link_id': cleaning.clean_link_id('link_id'), |
95 } |
97 } |
96 |
98 |
97 new_params['sidebar_heading'] = 'User (self)' |
99 new_params['sidebar_heading'] = 'User (self)' |
98 new_params['sidebar'] = [ |
100 new_params['sidebar'] = [ |
99 (users.create_login_url("/"), 'Sign In', 'signIn'), |
101 (users.create_login_url("/"), 'Sign In', 'signIn'), |
120 |
122 |
121 params = dicts.merge(params, new_params) |
123 params = dicts.merge(params, new_params) |
122 |
124 |
123 super(View, self).__init__(params=params) |
125 super(View, self).__init__(params=params) |
124 |
126 |
|
127 # create and store the special form when editing your profile after signing the ToS |
|
128 updated_fields = { |
|
129 'agreed_to_tos_on': forms.DateTimeField( |
|
130 widget=widgets.ReadOnlyInput(attrs={'disabled':'true'}), |
|
131 required=False), |
|
132 'clean_agreed_to_tos' : lambda x: True |
|
133 } |
|
134 |
|
135 signed_tos_edit_form = dynaform.extendDynaForm( |
|
136 dynaform = self._params['edit_form'], |
|
137 dynafields = updated_fields) |
|
138 |
|
139 params['signed_tos_edit_form'] = signed_tos_edit_form |
|
140 |
125 |
141 |
126 @decorators.merge_params |
142 @decorators.merge_params |
127 @decorators.check_access |
143 @decorators.check_access |
128 def editProfile(self, request, access_type, |
144 def editProfile(self, request, access_type, |
129 page_name=None, params=None, seed=None, **kwargs): |
145 page_name=None, params=None, seed=None, **kwargs): |
138 |
154 |
139 # set the link_id to the current user's link_id |
155 # set the link_id to the current user's link_id |
140 user_entity = user_logic.getForCurrentAccount() |
156 user_entity = user_logic.getForCurrentAccount() |
141 link_id = user_entity.link_id |
157 link_id = user_entity.link_id |
142 |
158 |
|
159 if user_entity.agreed_to_tos: |
|
160 # use the special form |
|
161 params['edit_form'] = params['signed_tos_edit_form'] |
|
162 |
143 return self.edit(request, access_type, |
163 return self.edit(request, access_type, |
144 page_name=page_name, params=params, seed=seed, link_id=link_id, **kwargs) |
164 page_name=page_name, params=params, seed=seed, link_id=link_id, **kwargs) |
145 |
165 |
146 |
166 |
147 def editGet(self, request, entity, context, seed, params=None): |
167 def editGet(self, request, entity, context, seed, params=None): |
148 """Overwrite so we can add the contents of the ToS. |
168 """Overwrite so we can add the contents of the ToS. |
149 For params see base.View.editGet(). |
169 For params see base.View.editGet(). |
153 site_tos = s_logic.getToS(s_logic.getSingleton()) |
173 site_tos = s_logic.getToS(s_logic.getSingleton()) |
154 if site_tos: |
174 if site_tos: |
155 context['tos_contents'] = site_tos.content |
175 context['tos_contents'] = site_tos.content |
156 |
176 |
157 return super(View, self).editGet(request, entity, context, seed, params=params) |
177 return super(View, self).editGet(request, entity, context, seed, params=params) |
|
178 |
|
179 def _editGet(self, request, entity, form): |
|
180 """Sets the content of the agreed_to_tos_on field. |
|
181 For params see base.View._editGet(). |
|
182 """ |
|
183 |
|
184 if entity.agreed_to_tos: |
|
185 form.fields['agreed_to_tos_on'].initial = entity.agreed_to_tos_on |
158 |
186 |
159 def editPost(self, request, entity, context, params=None): |
187 def editPost(self, request, entity, context, params=None): |
160 """Overwrite so we can add the contents of the ToS. |
188 """Overwrite so we can add the contents of the ToS. |
161 For params see base.View.editPost(). |
189 For params see base.View.editPost(). |
162 """ |
190 """ |