Add ToS agreement to org_admin application related forms.
Patch by: Sverre Rabbelier
--- a/app/soc/views/models/group.py Thu Feb 12 20:14:17 2009 +0000
+++ b/app/soc/views/models/group.py Thu Feb 12 20:14:51 2009 +0000
@@ -362,7 +362,6 @@
# call the _list method from base.View to show the list
return self._list(request, params, contents, page_name)
-
def registerRole(self, role_name, role_view):
"""Adds a role to the role_views param.
--- a/app/soc/views/models/org_admin.py Thu Feb 12 20:14:17 2009 +0000
+++ b/app/soc/views/models/org_admin.py Thu Feb 12 20:14:51 2009 +0000
@@ -19,10 +19,12 @@
__authors__ = [
'"Lennard de Rijk" <ljvderijk@gmail.com>'
+ '"Sverre Rabbelier" <sverre@rabbelier.nl>',
]
from django import forms
+from django.utils.translation import ugettext
from soc.logic import dicts
from soc.logic.models import organization as org_logic
@@ -76,6 +78,16 @@
new_params['extra_dynaexclude'] = ['agreed_to_tos']
+ new_params['create_extra_dynafields'] = {
+ 'scope_path': forms.fields.CharField(widget=forms.HiddenInput,
+ required=True),
+ 'admin_agreement': forms.fields.CharField(required=False,
+ widget=widgets.AgreementField),
+ 'agreed_to_admin_agreement': forms.fields.BooleanField(
+ initial=False, required=True,
+ label=ugettext('I agree to the Admin Agreement')),
+ }
+
new_params['allow_invites'] = True
params = dicts.merge(params, new_params)
@@ -88,7 +100,10 @@
# create and store the special form for invited users
updated_fields = {
'link_id': forms.CharField(widget=widgets.ReadOnlyInput(),
- required=False)}
+ required=False),
+ 'admin_agreement': forms.fields.Field(required=False,
+ widget=widgets.AgreementField),
+ }
invited_create_form = dynaform.extendDynaForm(
dynaform = self._params['create_form'],
@@ -99,20 +114,65 @@
def _editPost(self, request, entity, fields):
"""See base.View._editPost().
"""
+
if not entity:
fields['user'] = fields['link_id']
fields['link_id'] = fields['user'].link_id
+ fields['agreed_to_tos'] = fields['agreed_to_admin_agreement']
+
super(View, self)._editPost(request, entity, fields)
def _acceptInvitePost(self, fields, request, context, params, **kwargs):
"""Fills in the fields that were missing in the invited_created_form.
-
+
For params see base.View._acceptInvitePost()
"""
+
# fill in the appropriate fields that were missing in the form
fields['user'] = fields['link_id']
fields['link_id'] = fields['user'].link_id
+ fields['agreed_to_tos'] = fields['agreed_to_admin_agreement']
+
+ def _editGet(self, request, entity, form):
+ """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_admin_agreement'] = forms.fields.BooleanField(
+ widget=forms.HiddenInput, initial=entity.agreed_to_tos,
+ required=True)
+
+ super(View, self)._editGet(request, entity, form)
+
+ def _editContext(self, request, context):
+ """See base.View._editContext.
+ """
+
+ entity = context['entity']
+ form = context['form']
+
+ if 'scope_path' in form.initial:
+ scope_path = form.initial['scope_path']
+ elif 'scope_path' in request.POST:
+ # TODO: do this nicely
+ scope_path = request.POST['scope_path']
+ else:
+ # TODO: is this always sufficient?
+ form.fields['admin_agreement'] = None
+ return
+
+ entity = org_logic.logic.getFromKeyName(scope_path)
+
+ if not (entity and entity.scope and entity.scope.org_admin_agreement):
+ return
+
+ content = entity.scope.org_admin_agreement.content
+
+ form.fields['admin_agreement'].widget.text = content
view = View()
--- a/app/soc/views/models/organization.py Thu Feb 12 20:14:17 2009 +0000
+++ b/app/soc/views/models/organization.py Thu Feb 12 20:14:51 2009 +0000
@@ -154,11 +154,18 @@
submenus.append(submenu)
if roles.get('org_admin'):
+ # add a link to the resign page
submenu = (redirects.getManageRedirect(roles['org_admin'],
{'url_name': 'org_admin'}),
"Resign as Org Admin", 'any_access')
submenus.append(submenu)
+ # add a link to the edit page
+ submenu = (redirects.getEditRedirect(roles['org_admin'],
+ {'url_name': 'org_admin'}),
+ "Edit My Org Admin Profile", 'any_access')
+ submenus.append(submenu)
+
if roles.get('mentor'):
submenu = (redirects.getManageRedirect(roles['mentor'],
{'url_name' : 'mentor'}),