app/soc/views/models/org_admin.py
author Sverre Rabbelier <srabbelier@gmail.com>
Fri, 13 Feb 2009 22:36:45 +0000
changeset 1307 091a21cf3627
parent 1283 438dceed3132
child 1313 ec79c190f5ca
permissions -rw-r--r--
Update the copyright notice for 2009. Patch by: Sverre Rabbelier
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
#
1307
091a21cf3627 Update the copyright notice for 2009.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1283
diff changeset
     3
# Copyright 2009 the Melange authors.
1128
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>'
1283
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
    22
    '"Sverre Rabbelier" <sverre@rabbelier.nl>',
1128
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
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    26
from django import forms
1283
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
    27
from django.utils.translation import ugettext
1128
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    28
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    29
from soc.logic import dicts
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    30
from soc.logic.models import organization as org_logic
1163
d8c50be19232 Cleaned up access.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1128
diff changeset
    31
from soc.logic.models import org_admin as org_admin_logic
1128
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    32
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
    33
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
    34
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
    35
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
    36
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
    37
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    38
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
    39
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
class View(role.View):
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    42
  """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
    43
  """
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    44
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    45
  def __init__(self, params=None):
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    46
    """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
    47
    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
    48
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    49
    Params:
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    50
      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
    51
    """
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    52
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    53
    rights = access.Checker(params)
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    54
    rights['create'] = ['checkIsDeveloper']
1248
f318538394d9 Rename checkHasActiveRole to checkHasActiveRoleForScope
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1203
diff changeset
    55
    rights['edit'] = [('checkHasActiveRoleForScope', org_admin_logic.logic)]
1128
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    56
    rights['delete'] = ['checkIsDeveloper']
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['invite'] = ['checkIsDeveloper']
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    59
    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
    60
    # TODO accessCheck checkIsAdministratorForOrg
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    61
    rights['process_request'] = ['checkIsDeveloper',
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    62
        ('checkCanProcessRequest', 'org_admin')]
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    63
    rights['manage'] = [
1184
bd9c6101d41d Use .logic in checkIsAllowedToManageRole at the caller
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1163
diff changeset
    64
        ('checkIsAllowedToManageRole', [soc.logic.models.org_admin.logic,
bd9c6101d41d Use .logic in checkIsAllowedToManageRole at the caller
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1163
diff changeset
    65
             soc.logic.models.org_admin.logic])]
1128
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    66
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    67
    new_params = {}
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    68
    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
    69
    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
    70
    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
    71
    new_params['rights'] = rights
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    72
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    73
    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
    74
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    75
    new_params['name'] = "Organization Admin"
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    76
    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
    77
    new_params['sidebar_grouping'] = 'Organizations'
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    78
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    79
    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
    80
1283
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
    81
    new_params['create_extra_dynafields'] = {
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
    82
        'scope_path': forms.fields.CharField(widget=forms.HiddenInput,
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
    83
                                             required=True),
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
    84
        'admin_agreement': forms.fields.CharField(required=False,
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
    85
            widget=widgets.AgreementField),
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
    86
        'agreed_to_admin_agreement': forms.fields.BooleanField(
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
    87
            initial=False, required=True,
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
    88
            label=ugettext('I agree to the Admin Agreement')),
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
    89
        }
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
    90
1128
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    91
    new_params['allow_invites'] = True
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    92
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    93
    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
    94
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    95
    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
    96
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    97
    # 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
    98
    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
    99
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   100
    # 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
   101
    updated_fields = {
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   102
        'link_id': forms.CharField(widget=widgets.ReadOnlyInput(),
1283
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   103
            required=False),
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   104
        'admin_agreement': forms.fields.Field(required=False,
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   105
            widget=widgets.AgreementField),
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   106
        }
1128
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   107
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   108
    invited_create_form = dynaform.extendDynaForm(
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   109
        dynaform = self._params['create_form'],
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   110
        dynafields = updated_fields)
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
    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
   113
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   114
  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
   115
    """See base.View._editPost().
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   116
    """
1283
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   117
1128
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   118
    if not entity:
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   119
      fields['user'] = fields['link_id']
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   120
      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
   121
1283
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   122
    fields['agreed_to_tos'] = fields['agreed_to_admin_agreement']
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   123
1128
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   124
    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
   125
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   126
  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
   127
    """Fills in the fields that were missing in the invited_created_form.
1283
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   128
1128
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   129
    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
   130
    """
1283
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   131
1128
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   132
    # 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
   133
    fields['user'] = fields['link_id']
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   134
    fields['link_id'] = fields['user'].link_id
1283
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   135
    fields['agreed_to_tos'] = fields['agreed_to_admin_agreement']
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   136
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   137
  def _editGet(self, request, entity, form):
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   138
    """Sets the content of the agreed_to_tos_on field and replaces.
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   139
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   140
    Also replaces the agreed_to_tos field with a hidden field when the ToS has been signed.
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   141
    For params see base.View._editGet().
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   142
    """
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   143
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   144
    if entity.agreed_to_tos:
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   145
      form.fields['agreed_to_admin_agreement'] = forms.fields.BooleanField(
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   146
          widget=forms.HiddenInput, initial=entity.agreed_to_tos,
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   147
          required=True)
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   148
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   149
    super(View, self)._editGet(request, entity, form)
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   150
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   151
  def _editContext(self, request, context):
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   152
    """See base.View._editContext.
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   153
    """
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   154
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   155
    entity = context['entity']
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   156
    form = context['form']
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   157
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   158
    if 'scope_path' in form.initial:
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   159
      scope_path = form.initial['scope_path']
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   160
    elif 'scope_path' in request.POST:
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   161
      # TODO: do this nicely
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   162
      scope_path = request.POST['scope_path']
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   163
    else:
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   164
      # TODO: is this always sufficient?
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   165
      form.fields['admin_agreement'] = None
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   166
      return
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   167
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   168
    entity = org_logic.logic.getFromKeyName(scope_path)
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   169
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   170
    if not (entity and entity.scope and entity.scope.org_admin_agreement):
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   171
      return
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   172
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   173
    content = entity.scope.org_admin_agreement.content
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   174
438dceed3132 Add ToS agreement to org_admin application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1248
diff changeset
   175
    form.fields['admin_agreement'].widget.text = content
1128
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   176
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   177
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   178
view = View()
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   179
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   180
accept_invite = view.acceptInvite
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   181
create = view.create
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   182
delete = view.delete
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   183
edit = view.edit
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   184
invite = view.invite
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   185
list = view.list
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   186
manage = view.manage
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   187
process_request = view.processRequest
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   188
public = view.public
18d0e10b02f7 Added a view and templates for the organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   189
export = view.export