Adding a hidden agreed_to_tos field when the user has signed the ToS.
authorLennard de Rijk <ljvderijk@gmail.com>
Sun, 01 Feb 2009 23:27:28 +0000
changeset 1168 cb282e6baa1c
parent 1167 346117bd30cf
child 1169 c0294f3c28db
Adding a hidden agreed_to_tos field when the user has signed the ToS. This a more cleaner solution then r1774. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
app/soc/templates/soc/user/edit_profile.html
app/soc/views/models/user_self.py
--- a/app/soc/templates/soc/user/edit_profile.html	Sun Feb 01 22:51:14 2009 +0000
+++ b/app/soc/templates/soc/user/edit_profile.html	Sun Feb 01 23:27:28 2009 +0000
@@ -60,7 +60,9 @@
 {% if not user.agreed_to_tos %}
 <tr>
   <td>
+      <div id="ToS" style="overflow:auto" height="200px" width="400px">
       {{ tos_contents|safe|linebreaks }}
+      </div>
   </td>
 </tr>
   {% field_as_table_row form.agreed_to_tos %}
@@ -76,6 +78,7 @@
   <tr><td colspan="4">&nbsp;</td></tr>
 {% else %}
 {% field_as_table_row form.agreed_to_tos_on %}
+{{ form.agreed_to_tos }}
 {% endif %}
 {% endif %}
  </table>
--- a/app/soc/views/models/user_self.py	Sun Feb 01 22:51:14 2009 +0000
+++ b/app/soc/views/models/user_self.py	Sun Feb 01 23:27:28 2009 +0000
@@ -94,6 +94,9 @@
 
     new_params['edit_extra_dynafields'] = {
         'clean_link_id': cleaning.clean_link_id('link_id'),
+        'agreed_to_tos_on': forms.DateTimeField(
+          widget=widgets.ReadOnlyInput(attrs={'disabled':'true'}),
+          required=False),
         }
 
     new_params['sidebar_heading'] = 'User (self)'
@@ -124,20 +127,6 @@
 
     super(View, self).__init__(params=params)
 
-    # create and store the special form when editing your profile after signing the ToS
-    updated_fields = {
-        'agreed_to_tos_on': forms.DateTimeField(
-          widget=widgets.ReadOnlyInput(attrs={'disabled':'true'}),
-          required=False),
-        'clean_agreed_to_tos' : lambda x: True
-          }
-
-    signed_tos_edit_form = dynaform.extendDynaForm(
-        dynaform = self._params['edit_form'],
-        dynafields = updated_fields)
-
-    params['signed_tos_edit_form'] = signed_tos_edit_form
-
 
   @decorators.merge_params
   @decorators.check_access
@@ -156,10 +145,6 @@
     user_entity = user_logic.getForCurrentAccount()
     link_id = user_entity.link_id
 
-    if user_entity.agreed_to_tos:
-      # use the special form
-      params['edit_form'] = params['signed_tos_edit_form']
-
     return self.edit(request, access_type,
          page_name=page_name, params=params, seed=seed, link_id=link_id, **kwargs)
 
@@ -177,12 +162,18 @@
     return super(View, self).editGet(request, entity, context, seed, params=params)
 
   def _editGet(self, request, entity, form):
-    """Sets the content of the agreed_to_tos_on field.
+    """Sets the content of the agreed_to_tos_on field and replaces.
+
+    Also replaces the agreed_to_tos field with a hidden field when the ToS has been signed.
     For params see base.View._editGet().
     """
 
     if entity.agreed_to_tos:
       form.fields['agreed_to_tos_on'].initial = entity.agreed_to_tos_on
+      # replace the 'agreed_to_tos' field with a hidden field so 
+      # that the form checks still pass
+      form.fields['agreed_to_tos'] = forms.fields.CharField(widget=forms.HiddenInput,
+      initial=entity.agreed_to_tos, required=True)
 
   def editPost(self, request, entity, context, params=None):
     """Overwrite so we can add the contents of the ToS.