app/soc/views/models/organization.py
author Lennard de Rijk <ljvderijk@gmail.com>
Mon, 02 Feb 2009 20:07:52 +0000
changeset 1190 449b9d93d890
parent 1154 77276e2c46f7
child 1205 2e88261aba72
permissions -rw-r--r--
Probably fixed a bug on the live instance. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
682
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
#
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
#
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    17
"""Views for Organizations.
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
"""
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
__authors__ = [
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    21
    '"Sverre Rabbelier" <sverre@rabbelier.nl>',
1126
4fc86db70a76 Added organization view and templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1079
diff changeset
    22
    '"Lennard de Rijk" <ljvderijk@gmail.com>',
682
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    23
  ]
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    24
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    25
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    26
from django import forms
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
690
14e9f484412c Fix imports sorting in soc.views.models.organization.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 682
diff changeset
    28
from soc.logic import cleaning
682
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
from soc.logic import dicts
1154
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1126
diff changeset
    30
from soc.logic.models import org_app as org_app_logic
1126
4fc86db70a76 Added organization view and templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1079
diff changeset
    31
from soc.views.helper import access
1154
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1126
diff changeset
    32
from soc.views.helper import dynaform
682
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    33
from soc.views.helper import redirects
1154
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1126
diff changeset
    34
from soc.views.helper import widgets
682
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
from soc.views.models import group
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    36
from soc.views.models import program as program_view
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    37
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    38
import soc.models.organization
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    39
import soc.logic.models.organization
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    40
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    42
class View(group.View):
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    43
  """View methods for the Organization model.
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    44
  """
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
  def __init__(self, params=None):
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
    """Defines the fields and methods required for the base View class
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    48
    to provide the user with list, public, create, edit and delete views.
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    49
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    50
    Params:
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    51
      original_params: a dict with params for this View
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    52
    """
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    53
1126
4fc86db70a76 Added organization view and templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1079
diff changeset
    54
    # TODO do the proper access checks
4fc86db70a76 Added organization view and templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1079
diff changeset
    55
    rights = access.Checker(params)
4fc86db70a76 Added organization view and templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1079
diff changeset
    56
    rights['create'] = ['checkIsDeveloper']
4fc86db70a76 Added organization view and templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1079
diff changeset
    57
    rights['edit'] = ['checkIsDeveloper']
4fc86db70a76 Added organization view and templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1079
diff changeset
    58
    rights['delete'] = ['checkIsDeveloper']
4fc86db70a76 Added organization view and templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1079
diff changeset
    59
    rights['home'] = ['allow']
4fc86db70a76 Added organization view and templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1079
diff changeset
    60
    rights['list'] = ['checkIsDeveloper']
4fc86db70a76 Added organization view and templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1079
diff changeset
    61
    rights['list_requests'] = ['checkIsDeveloper']
4fc86db70a76 Added organization view and templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1079
diff changeset
    62
    rights['list_roles'] = ['checkIsDeveloper']
1154
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1126
diff changeset
    63
    rights['applicant'] = ['checkIsDeveloper']
1126
4fc86db70a76 Added organization view and templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1079
diff changeset
    64
682
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    65
    new_params = {}
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    66
    new_params['logic'] = soc.logic.models.organization.logic
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    67
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    68
    new_params['scope_view'] = program_view
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    69
    new_params['scope_redirect'] = redirects.getCreateRedirect
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    70
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    71
    new_params['name'] = "Organization"
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    72
    new_params['url_name'] = "org"
1126
4fc86db70a76 Added organization view and templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1079
diff changeset
    73
    new_params['sidebar_grouping'] = 'Organizations'
682
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    74
1126
4fc86db70a76 Added organization view and templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1079
diff changeset
    75
    new_params['public_template'] = 'soc/organization/public.html'
4fc86db70a76 Added organization view and templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1079
diff changeset
    76
    new_params['list_row'] = 'soc/organization/list/row.html'
4fc86db70a76 Added organization view and templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1079
diff changeset
    77
    new_params['list_heading'] = 'soc/organization/list/heading.html'
4fc86db70a76 Added organization view and templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1079
diff changeset
    78
1154
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1126
diff changeset
    79
    new_params['application_logic'] = org_app_logic
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1126
diff changeset
    80
    new_params['group_applicant_url'] = True
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1126
diff changeset
    81
1126
4fc86db70a76 Added organization view and templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1079
diff changeset
    82
    #TODO(ljvderijk) add cleaning methods to not overwrite existing orgs
682
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    83
    new_params['create_extra_dynafields'] = {
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    84
        'scope_path': forms.CharField(widget=forms.HiddenInput,
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    85
                                   required=True),
1079
be1aacb33b0f Changed clean_link_id to be in a wrapper form as well.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 934
diff changeset
    86
        'clean_link_id': cleaning.clean_link_id('link_id'),
682
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    87
        }
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    88
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    89
    params = dicts.merge(params, new_params)
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    90
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    91
    super(View, self).__init__(params=params)
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    92
1154
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1126
diff changeset
    93
    # create and store the special form for applicants
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1126
diff changeset
    94
    updated_fields = {
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1126
diff changeset
    95
        'link_id': forms.CharField(widget=widgets.ReadOnlyInput(),
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1126
diff changeset
    96
            required=False),
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1126
diff changeset
    97
        'clean_link_id': cleaning.clean_link_id('link_id')}
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1126
diff changeset
    98
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1126
diff changeset
    99
    applicant_create_form = dynaform.extendDynaForm(
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1126
diff changeset
   100
        dynaform = self._params['create_form'],
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1126
diff changeset
   101
        dynafields = updated_fields)
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1126
diff changeset
   102
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1126
diff changeset
   103
    params['applicant_create_form'] = applicant_create_form
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1126
diff changeset
   104
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1126
diff changeset
   105
1126
4fc86db70a76 Added organization view and templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1079
diff changeset
   106
    # TODO(ljvderijk) define several menu items for organizations
4fc86db70a76 Added organization view and templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1079
diff changeset
   107
    #def _getExtraMenuItems(self, role_description, params=None):
4fc86db70a76 Added organization view and templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1079
diff changeset
   108
682
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   109
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   110
view = View()
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   111
1154
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1126
diff changeset
   112
applicant = view.applicant
682
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   113
create = view.create
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   114
delete = view.delete
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   115
edit = view.edit
1126
4fc86db70a76 Added organization view and templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1079
diff changeset
   116
home = view.home
682
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   117
list = view.list
1126
4fc86db70a76 Added organization view and templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1079
diff changeset
   118
list_requests = view.listRequests
4fc86db70a76 Added organization view and templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1079
diff changeset
   119
list_roles = view.listRoles
682
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   120
public = view.public
858
e79e7a22326f Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents: 799
diff changeset
   121
export = view.export
934
9fcc08971efe Add a 'pick' view to the appropriate views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 858
diff changeset
   122
pick = view.pick