app/soc/views/models/org_admin.py
author Lennard de Rijk <ljvderijk@gmail.com>
Sat, 31 Jan 2009 19:02:53 +0000
changeset 1128 18d0e10b02f7
child 1163 d8c50be19232
permissions -rw-r--r--
Added a view and templates for the organization admin. This means that org admins can now be created/invited. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1128
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     2
#
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     4
#
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     8
#
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    10
#
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    16
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    17
"""Views for Organization Admins.
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    18
"""
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    19
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    20
__authors__ = [
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    21
    '"Lennard de Rijk" <ljvderijk@gmail.com>'
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    22
  ]
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    23
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    24
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    25
from django import forms
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    26
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    27
from soc.logic import dicts
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    28
from soc.logic.models import organization as org_logic
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    29
from soc.views.helper import access
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    30
from soc.views.helper import dynaform
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    31
from soc.views.helper import widgets
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    32
from soc.views.models import organization as org_view
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    33
from soc.views.models import role
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    34
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    35
import soc.logic.models.org_admin
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    36
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    37
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    38
class View(role.View):
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    39
  """View methods for the Organization Admin model.
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    40
  """
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    41
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    42
  def __init__(self, params=None):
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    43
    """Defines the fields and methods required for the base View class
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    44
    to provide the user with list, public, create, edit and delete views.
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    45
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    46
    Params:
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    47
      params: a dict with params for this View
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    48
    """
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    49
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    50
    rights = access.Checker(params)
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    51
    rights['create'] = ['checkIsDeveloper']
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    52
    rights['edit'] = [('checkIsMyActiveRole', soc.logic.models.org_admin)]
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    53
    rights['delete'] = ['checkIsDeveloper']
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    54
    # TODO accessCheck checkIsAdministratorForOrg
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    55
    rights['invite'] = ['checkIsDeveloper']
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    56
    rights['accept_invite'] = [('checkCanCreateFromRequest', 'org_admin')]
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    57
    # TODO accessCheck checkIsAdministratorForOrg
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    58
    rights['process_request'] = ['checkIsDeveloper',
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    59
        ('checkCanProcessRequest', 'org_admin')]
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    60
    rights['manage'] = [
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    61
        ('checkIsAllowedToManageRole', [soc.logic.models.org_admin,
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    62
             soc.logic.models.org_admin])]
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    63
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    64
    new_params = {}
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    65
    new_params['logic'] = soc.logic.models.org_admin.logic
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    66
    new_params['group_logic'] = org_logic.logic
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    67
    new_params['group_view'] = org_view.view
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    68
    new_params['rights'] = rights
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    69
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    70
    new_params['scope_view'] = org_view
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    71
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    72
    new_params['name'] = "Organization Admin"
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    73
    new_params['module_name'] = "org_admin"
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    74
    new_params['sidebar_grouping'] = 'Organizations'
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    75
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    76
    new_params['extra_dynaexclude'] = ['agreed_to_tos']
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    77
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    78
    new_params['allow_invites'] = True
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    79
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    80
    params = dicts.merge(params, new_params)
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    81
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    82
    super(View, self).__init__(params=params)
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    83
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    84
    # register the role with the group_view
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    85
    params['group_view'].registerRole(params['module_name'], self)
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    86
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    87
    # create and store the special form for invited users
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    88
    updated_fields = {
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    89
        'link_id': forms.CharField(widget=widgets.ReadOnlyInput(),
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    90
            required=False)}
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    91
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    92
    invited_create_form = dynaform.extendDynaForm(
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    93
        dynaform = self._params['create_form'],
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    94
        dynafields = updated_fields)
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    95
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    96
    params['invited_create_form'] = invited_create_form
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    97
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    98
  def _editPost(self, request, entity, fields):
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    99
    """See base.View._editPost().
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   100
    """
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   101
    if not entity:
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   102
      fields['user'] = fields['link_id']
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   103
      fields['link_id'] = fields['user'].link_id
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   104
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   105
    super(View, self)._editPost(request, entity, fields)
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   106
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   107
  def _acceptInvitePost(self, fields, request, context, params, **kwargs):
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   108
    """Fills in the fields that were missing in the invited_created_form.
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   109
    
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   110
    For params see base.View._acceptInvitePost()
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   111
    """
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   112
    # fill in the appropriate fields that were missing in the form
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   113
    fields['user'] = fields['link_id']
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   114
    fields['link_id'] = fields['user'].link_id
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   115
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   116
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   117
view = View()
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   118
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   119
accept_invite = view.acceptInvite
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   120
create = view.create
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   121
delete = view.delete
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   122
edit = view.edit
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   123
invite = view.invite
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   124
list = view.list
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   125
manage = view.manage
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   126
process_request = view.processRequest
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   127
public = view.public
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   128
export = view.export