app/soc/views/models/mentor.py
author Sverre Rabbelier <srabbelier@gmail.com>
Thu, 05 Feb 2009 23:52:27 +0000
changeset 1230 b1b1897e4df1
parent 1203 38225f2ad3a6
child 1248 f318538394d9
permissions -rw-r--r--
Cleanup in org_app and replace ReferenceProperty with LinkProperty Using LinkProperty allows the org to host their idea's list on Melange through the Document system, and then specify the URL of that document. This also makes it possible for the orgs to specify a document that is not hosted on Melange. Patch by: Sverre Rabbelier
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
#
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
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>'
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    22
  ]
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
from django import forms
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    26
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    27
from soc.logic import dicts
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    28
from soc.logic.models import organization as org_logic
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    29
from soc.views.helper import access
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    30
from soc.views.helper import dynaform
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    31
from soc.views.helper import widgets
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    32
from soc.views.models import organization as org_view
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    33
from soc.views.models import role
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    34
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    35
import soc.logic.models.mentor
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    36
import soc.logic.models.org_admin
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    37
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    38
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    39
class View(role.View):
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    40
  """View methods for the Organization Mentors model.
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    41
  """
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    42
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    43
  def __init__(self, params=None):
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    44
    """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
    45
    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
    46
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    47
    Params:
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    48
      params: a dict with params for this View
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    49
    """
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    50
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    51
    rights = access.Checker(params)
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    52
    rights['create'] = ['checkIsDeveloper']
1203
38225f2ad3a6 Renamed checkHasRole to checkHasActiveRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1184
diff changeset
    53
    rights['edit'] = [('checkHasActiveRole', soc.logic.models.mentor.logic)]
1137
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    54
    rights['delete'] = ['checkIsDeveloper']
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    55
    # TODO accessCheck checkIsAdministratorForOrg
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    56
    rights['invite'] = ['checkIsDeveloper']
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    57
    rights['accept_invite'] = [('checkCanCreateFromRequest', 'mentor')]
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    58
    # TODO accessCheck checkIsAdministratorForOrg
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    59
    rights['process_request'] = ['checkIsDeveloper',
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    60
        ('checkCanProcessRequest', 'mentor')]
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    61
    rights['manage'] = [
1184
bd9c6101d41d Use .logic in checkIsAllowedToManageRole at the caller
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1163
diff changeset
    62
        ('checkIsAllowedToManageRole', [soc.logic.models.mentor.logic,
bd9c6101d41d Use .logic in checkIsAllowedToManageRole at the caller
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1163
diff changeset
    63
             soc.logic.models.org_admin.logic])]
1137
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    64
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    65
    new_params = {}
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    66
    new_params['logic'] = soc.logic.models.mentor.logic
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    67
    new_params['group_logic'] = org_logic.logic
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    68
    new_params['group_view'] = org_view.view
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    69
    new_params['rights'] = rights
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    70
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    71
    new_params['scope_view'] = org_view
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    72
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    73
    new_params['name'] = "Mentor"
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    74
    new_params['module_name'] = "mentor"
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    75
    new_params['sidebar_grouping'] = 'Organizations'
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['extra_dynaexclude'] = ['agreed_to_tos']
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    78
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    79
    new_params['allow_requests_and_invites'] = True
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    80
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    81
    params = dicts.merge(params, new_params)
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    82
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    83
    super(View, self).__init__(params=params)
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
    # register the role with the group_view
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    86
    params['group_view'].registerRole(params['module_name'], self)
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    87
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    88
    # create and store the special form for invited users
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    89
    updated_fields = {
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    90
        'link_id': forms.CharField(widget=widgets.ReadOnlyInput(),
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    91
            required=False)}
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    92
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    93
    invited_create_form = dynaform.extendDynaForm(
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    94
        dynaform = self._params['create_form'],
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    95
        dynafields = updated_fields)
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    96
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    97
    params['invited_create_form'] = invited_create_form
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    98
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    99
  def _editPost(self, request, entity, fields):
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   100
    """See base.View._editPost().
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   101
    """
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   102
    if not entity:
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   103
      fields['user'] = fields['link_id']
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   104
      fields['link_id'] = fields['user'].link_id
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   105
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   106
    super(View, self)._editPost(request, entity, fields)
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   107
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   108
  def _acceptInvitePost(self, fields, request, context, params, **kwargs):
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   109
    """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
   110
    
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   111
    For params see base.View._acceptInvitePost()
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   112
    """
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   113
    # 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
   114
    fields['user'] = fields['link_id']
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   115
    fields['link_id'] = fields['user'].link_id
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
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   118
view = View()
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   119
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   120
accept_invite = view.acceptInvite
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   121
create = view.create
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   122
delete = view.delete
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   123
edit = view.edit
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   124
invite = view.invite
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   125
list = view.list
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   126
manage = view.manage
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   127
process_request = view.processRequest
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   128
request = view.request
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   129
public = view.public
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   130
export = view.export
91b6bfe09579 Added view for mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   131