Add ToS agreement to mentor application related forms.
Patch by: Sverre Rabbelier
--- a/app/soc/views/models/mentor.py Thu Feb 12 20:14:51 2009 +0000
+++ b/app/soc/views/models/mentor.py Thu Feb 12 20:15:20 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),
+ 'mentor_agreement': forms.fields.CharField(required=False,
+ widget=widgets.AgreementField),
+ 'agreed_to_mentor_agreement': forms.fields.BooleanField(
+ initial=False, required=True,
+ label=ugettext('I agree to the Mentor Agreement')),
+ }
+
new_params['allow_requests_and_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),
+ 'mentor_agreement': forms.fields.Field(required=False,
+ widget=widgets.AgreementField),
+ }
invited_create_form = dynaform.extendDynaForm(
dynaform = self._params['create_form'],
@@ -103,6 +118,8 @@
fields['user'] = fields['link_id']
fields['link_id'] = fields['user'].link_id
+ fields['agreed_to_tos'] = fields['agreed_to_mentor_agreement']
+
super(View, self)._editPost(request, entity, fields)
def _acceptInvitePost(self, fields, request, context, params, **kwargs):
@@ -110,10 +127,51 @@
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_mentor_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_mentor_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['mentor_agreement'] = None
+ return
+
+ entity = org_logic.logic.getFromKeyName(scope_path)
+
+ if not (entity and entity.scope and entity.scope.mentor_agreement):
+ return
+
+ content = entity.scope.mentor_agreement.content
+
+ form.fields['mentor_agreement'].widget.text = content
view = View()
--- a/app/soc/views/models/organization.py Thu Feb 12 20:14:51 2009 +0000
+++ b/app/soc/views/models/organization.py Thu Feb 12 20:15:20 2009 +0000
@@ -167,11 +167,18 @@
submenus.append(submenu)
if roles.get('mentor'):
+ # add a link to the resign page
submenu = (redirects.getManageRedirect(roles['mentor'],
{'url_name' : 'mentor'}),
"Resign as Mentor", 'any_access')
submenus.append(submenu)
+ # add a link to the edit page
+ submenu = (redirects.getEditRedirect(roles['mentor'],
+ {'url_name': 'mentor'}),
+ "Edit My Org Mentor Profile", 'any_access')
+ submenus.append(submenu)
+
return submenus