app/soc/views/models/mentor.py
author Sverre Rabbelier <srabbelier@gmail.com>
Sat, 24 Oct 2009 16:23:31 -0700
changeset 3043 187c1709756b
parent 3032 f3886d1b00a5
child 3055 7f922641ccc9
permissions -rw-r--r--
GSoC Views
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1137
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     2
#
1307
091a21cf3627 Update the copyright notice for 2009.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1284
diff changeset
     3
# Copyright 2009 the Melange authors.
1137
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     4
#
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     8
#
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    10
#
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    16
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    17
"""Views for Organization Mentors.
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    18
"""
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    19
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    20
__authors__ = [
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    21
    '"Lennard de Rijk" <ljvderijk@gmail.com>'
1284
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
    22
    '"Sverre Rabbelier" <sverre@rabbelier.nl>',
1137
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    23
  ]
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    24
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    25
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    26
from django import forms
1284
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
    27
from django.utils.translation import ugettext
1137
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    28
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    29
from soc.logic import dicts
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    30
from soc.logic.models import organization as org_logic
3029
3c09b9396e2e Added logic paramters to two access checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2919
diff changeset
    31
from soc.logic.models import student as student_logic
1137
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    32
from soc.views.helper import access
1583
1e4c785f1adf Added decorators
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1526
diff changeset
    33
from soc.views.helper import decorators
1137
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    34
from soc.views.helper import dynaform
1726
711c8dcab67e Add a link to the full agreement text
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1659
diff changeset
    35
from soc.views.helper import redirects
1433
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    36
from soc.views.helper import params as params_helper
1137
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    37
from soc.views.helper import widgets
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    38
from soc.views.models import organization as org_view
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    39
from soc.views.models import role
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    40
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    41
import soc.logic.models.mentor
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    42
import soc.logic.models.org_admin
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    43
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    44
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    45
class View(role.View):
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    46
  """View methods for the Organization Mentors model.
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    47
  """
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    48
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    49
  def __init__(self, params=None):
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    50
    """Defines the fields and methods required for the base View class
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    51
    to provide the user with list, public, create, edit and delete views.
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    52
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    53
    Params:
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    54
      params: a dict with params for this View
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    55
    """
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    56
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    57
    rights = access.Checker(params)
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    58
    rights['create'] = ['checkIsDeveloper']
2919
cb677410c0f1 Using the new checkIsMyActiveRole check where necessary.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2667
diff changeset
    59
    rights['edit'] = [('checkIsMyActiveRole', soc.logic.models.mentor.logic)]
1137
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    60
    rights['delete'] = ['checkIsDeveloper']
1526
5c31184594a5 Convert everything to use the new access methods
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1433
diff changeset
    61
    rights['invite'] = [('checkHasActiveRoleForScope',
1386
0c205ce4e27d Org admins can now send out invitations and users can now request to become a mentor.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1384
diff changeset
    62
                         soc.logic.models.org_admin.logic)]
1377
101759701e51 Students can not become a mentor or org_admin in the same program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1343
diff changeset
    63
    rights['accept_invite'] = [('checkCanCreateFromRequest', 'mentor'),
3029
3c09b9396e2e Added logic paramters to two access checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2919
diff changeset
    64
        ('checkIsNotStudentForProgramOfOrg', [org_logic.logic,
3c09b9396e2e Added logic paramters to two access checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2919
diff changeset
    65
                                              student_logic.logic])]
3c09b9396e2e Added logic paramters to two access checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2919
diff changeset
    66
    rights['request'] = [
3c09b9396e2e Added logic paramters to two access checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2919
diff changeset
    67
        ('checkIsNotStudentForProgramOfOrg',
3c09b9396e2e Added logic paramters to two access checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2919
diff changeset
    68
            [org_logic.logic, student_logic.logic]),
3032
f3886d1b00a5 Changed checkCanMakeRequestToGroup to use Logic instance instead of module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3029
diff changeset
    69
        ('checkCanMakeRequestToGroup', org_logic.logic)]
1386
0c205ce4e27d Org admins can now send out invitations and users can now request to become a mentor.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1384
diff changeset
    70
    rights['process_request'] = [
0c205ce4e27d Org admins can now send out invitations and users can now request to become a mentor.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1384
diff changeset
    71
        ('checkHasActiveRoleForScope', soc.logic.models.org_admin.logic),
1137
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    72
        ('checkCanProcessRequest', 'mentor')]
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    73
    rights['manage'] = [
1184
bd9c6101d41d Use .logic in checkIsAllowedToManageRole at the caller
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1163
diff changeset
    74
        ('checkIsAllowedToManageRole', [soc.logic.models.mentor.logic,
bd9c6101d41d Use .logic in checkIsAllowedToManageRole at the caller
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1163
diff changeset
    75
             soc.logic.models.org_admin.logic])]
1137
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    76
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    77
    new_params = {}
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    78
    new_params['logic'] = soc.logic.models.mentor.logic
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    79
    new_params['group_logic'] = org_logic.logic
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    80
    new_params['group_view'] = org_view.view
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    81
    new_params['rights'] = rights
2133
7f77e0be852e Make mentor pickable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2076
diff changeset
    82
    new_params['pickable'] = True
7f77e0be852e Make mentor pickable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2076
diff changeset
    83
    new_params['cache_pick_order'] = ['link_id', 'name']
1137
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    84
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    85
    new_params['scope_view'] = org_view
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    86
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    87
    new_params['name'] = "Mentor"
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    88
    new_params['module_name'] = "mentor"
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    89
    new_params['sidebar_grouping'] = 'Organizations'
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    90
1387
857e6cc8ebc1 Added required program property to org_admin and mentor.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1386
diff changeset
    91
    new_params['extra_dynaexclude'] = ['agreed_to_tos', 'program']
1137
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    92
1433
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    93
    new_params['create_dynafields'] = [
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    94
        {'name': 'scope_path',
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    95
         'base': forms.fields.CharField,
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    96
         'widget': forms.HiddenInput,
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    97
         'required': True,
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    98
         },
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    99
        {'name': 'mentor_agreement',
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   100
         'base': forms.fields.CharField,
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   101
         'required': False,
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   102
         'widget': widgets.AgreementField,
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   103
         'group': ugettext("5. Terms of Service"),
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   104
         },
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   105
        {'name': 'agreed_to_mentor_agreement',
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   106
         'base': forms.fields.BooleanField,
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   107
         'initial': False,
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   108
         'required':True,
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   109
         'label': ugettext('I agree to the Mentor Agreement'),
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   110
         'group': ugettext("5. Terms of Service"),
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   111
         },
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   112
        ]
1284
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   113
1137
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   114
    new_params['allow_requests_and_invites'] = True
1384
bb22ea156567 Role overview membership is now determined by setting show_in_roles_overview param to true in the view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1377
diff changeset
   115
    new_params['show_in_roles_overview'] = True
1137
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   116
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   117
    params = dicts.merge(params, new_params)
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   118
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   119
    super(View, self).__init__(params=params)
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   120
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   121
    # register the role with the group_view
2667
260aaea36e49 Use role_name to register the Role with the Group View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2177
diff changeset
   122
    self._params['group_view'].registerRole(self._logic.role_name, self)
1137
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   123
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   124
    # create and store the special form for invited users
1433
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   125
    dynafields = [
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   126
        {'name': 'link_id',
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   127
         'base': forms.CharField,
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   128
         'widget': widgets.ReadOnlyInput(),
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   129
         'required': False,
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   130
         },
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   131
        {'name': 'mentor_agreement',
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   132
         'base': forms.fields.Field,
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   133
         'required': False,
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   134
         'widget': widgets.AgreementField,
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   135
         'group': ugettext("5. Terms of Service"),
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   136
        },
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   137
        ]
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   138
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   139
    dynaproperties = params_helper.getDynaFields(dynafields)
1137
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   140
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   141
    invited_create_form = dynaform.extendDynaForm(
1433
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   142
        dynaform=self._params['create_form'],
4724e3b99702 Convert mentor.py to use DynaFields as an example
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   143
        dynaproperties=dynaproperties)
1137
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   144
2177
e2c193e1f631 Do not rely on dicts.merge to change target
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2133
diff changeset
   145
    self._params['invited_create_form'] = invited_create_form
1137
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   146
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   147
  def _editPost(self, request, entity, fields):
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   148
    """See base.View._editPost().
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   149
    """
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   150
    if not entity:
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   151
      fields['user'] = fields['link_id']
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   152
      fields['link_id'] = fields['user'].link_id
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   153
1659
ed1a0f139a21 Fix too long lines and fix the bug where undefined variable was used in _editPost method in soc.views.models.mentor module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1584
diff changeset
   154
      group_logic = self._params['group_logic']
1387
857e6cc8ebc1 Added required program property to org_admin and mentor.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1386
diff changeset
   155
      group_entity = group_logic.getFromKeyName(fields['scope_path'])
857e6cc8ebc1 Added required program property to org_admin and mentor.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1386
diff changeset
   156
      fields['program'] = group_entity.scope
857e6cc8ebc1 Added required program property to org_admin and mentor.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1386
diff changeset
   157
1284
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   158
    fields['agreed_to_tos'] = fields['agreed_to_mentor_agreement']
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   159
1137
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   160
    super(View, self)._editPost(request, entity, fields)
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   161
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   162
  def _acceptInvitePost(self, fields, request, context, params, **kwargs):
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   163
    """Fills in the fields that were missing in the invited_created_form.
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   164
    
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   165
    For params see base.View._acceptInvitePost()
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   166
    """
1284
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   167
1137
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   168
    # fill in the appropriate fields that were missing in the form
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   169
    fields['user'] = fields['link_id']
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   170
    fields['link_id'] = fields['user'].link_id
1284
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   171
    fields['agreed_to_tos'] = fields['agreed_to_mentor_agreement']
1137
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   172
1387
857e6cc8ebc1 Added required program property to org_admin and mentor.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1386
diff changeset
   173
    group_logic = params['group_logic']
857e6cc8ebc1 Added required program property to org_admin and mentor.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1386
diff changeset
   174
    group_entity = group_logic.getFromKeyName(fields['scope_path'])
857e6cc8ebc1 Added required program property to org_admin and mentor.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1386
diff changeset
   175
    fields['program'] = group_entity.scope
857e6cc8ebc1 Added required program property to org_admin and mentor.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1386
diff changeset
   176
1284
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   177
  def _editGet(self, request, entity, form):
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   178
    """Sets the content of the agreed_to_tos_on field and replaces.
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   179
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   180
    Also replaces the agreed_to_tos field with a hidden field when the ToS has been signed.
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   181
    For params see base.View._editGet().
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   182
    """
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   183
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   184
    if entity.agreed_to_tos:
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   185
      form.fields['agreed_to_mentor_agreement'] = forms.fields.BooleanField(
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   186
          widget=forms.HiddenInput, initial=entity.agreed_to_tos,
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   187
          required=True)
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   188
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   189
    super(View, self)._editGet(request, entity, form)
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   190
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   191
  def _editContext(self, request, context):
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   192
    """See base.View._editContext.
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   193
    """
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   194
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   195
    entity = context['entity']
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   196
    form = context['form']
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   197
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   198
    if 'scope_path' in form.initial:
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   199
      scope_path = form.initial['scope_path']
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   200
    elif 'scope_path' in request.POST:
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   201
      scope_path = request.POST['scope_path']
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   202
    else:
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   203
      form.fields['mentor_agreement'] = None
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   204
      return
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   205
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   206
    entity = org_logic.logic.getFromKeyName(scope_path)
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   207
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   208
    if not (entity and entity.scope and entity.scope.mentor_agreement):
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   209
      return
92f7a24d8f42 Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   210
1726
711c8dcab67e Add a link to the full agreement text
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1659
diff changeset
   211
    agreement = entity.scope.mentor_agreement
711c8dcab67e Add a link to the full agreement text
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1659
diff changeset
   212
711c8dcab67e Add a link to the full agreement text
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1659
diff changeset
   213
    content = agreement.content
711c8dcab67e Add a link to the full agreement text
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1659
diff changeset
   214
    params = {'url_name': 'document'}
711c8dcab67e Add a link to the full agreement text
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1659
diff changeset
   215
711c8dcab67e Add a link to the full agreement text
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1659
diff changeset
   216
    widget = form.fields['mentor_agreement'].widget
711c8dcab67e Add a link to the full agreement text
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1659
diff changeset
   217
    widget.text = content
711c8dcab67e Add a link to the full agreement text
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1659
diff changeset
   218
    widget.url = redirects.getPublicRedirect(agreement, params)
711c8dcab67e Add a link to the full agreement text
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1659
diff changeset
   219
1137
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   220
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   221
view = View()
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   222
1584
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   223
accept_invite = decorators.view(view.acceptInvite)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   224
admin = decorators.view(view.admin)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   225
create = decorators.view(view.create)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   226
delete = decorators.view(view.delete)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   227
edit = decorators.view(view.edit)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   228
invite = decorators.view(view.invite)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   229
list = decorators.view(view.list)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   230
manage = decorators.view(view.manage)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   231
process_request = decorators.view(view.processRequest)
2076
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2020
diff changeset
   232
role_request = decorators.view(view.request)
1584
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   233
public = decorators.view(view.public)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   234
export = decorators.view(view.export)
2133
7f77e0be852e Make mentor pickable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2076
diff changeset
   235
pick = decorators.view(view.pick)
1137
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   236