app/soc/views/models/org_app.py
author Pawel Solyga <Pawel.Solyga@gmail.com>
Thu, 05 Feb 2009 20:33:47 +0000
changeset 1221 0130e63704ac
parent 1205 2e88261aba72
child 1225 1d5c58e24fd3
permissions -rw-r--r--
Remove extra whitespaces in soc.views.models.organization module. Patch by: Pawel Solyga Reviewed by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1182
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
     1
#!/usr/bin/python2.5
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
     2
#
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
     3
# Copyright 2008 the Melange authors.
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
     4
#
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
     6
# you may not use this file except in compliance with the License.
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
     7
# You may obtain a copy of the License at
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
     8
#
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    10
#
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    14
# See the License for the specific language governing permissions and
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    15
# limitations under the License.
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    16
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    17
"""Views for Organization App profiles.
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    18
"""
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    19
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    20
__authors__ = [
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    21
    '"Lennard de Rijk" <ljvderijk@gmail.com>',
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    22
  ]
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    23
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    24
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    25
from django import forms
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    26
1205
2e88261aba72 Added validate_new_group to cleaning and removed clean_new_club_link_id.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1201
diff changeset
    27
from soc.logic import cleaning
1182
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    28
from soc.logic import dicts
1205
2e88261aba72 Added validate_new_group to cleaning and removed clean_new_club_link_id.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1201
diff changeset
    29
from soc.logic import models as model_logic
1182
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    30
from soc.logic.models import org_app as org_app_logic
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    31
from soc.views.helper import access
1185
fe25d98a24c3 Create org_application now shows select program view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1182
diff changeset
    32
from soc.views.helper import redirects
1182
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    33
from soc.views.models import group_app
1185
fe25d98a24c3 Create org_application now shows select program view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1182
diff changeset
    34
from soc.views.models import program as program_view
1182
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    35
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    36
import soc.logic.dicts
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    37
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    38
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    39
class View(group_app.View):
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    40
  """View methods for the Organization Application model.
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    41
  """
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    42
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    43
  def __init__(self, params=None):
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    44
    """Defines the fields and methods required for the base View class
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    45
    to provide the user with list, public, create, edit and delete views.
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    46
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    47
    Params:
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    48
      params: a dict with params for this View
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    49
    """
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    50
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    51
    #TODO(ljvderijk) do the right rights check
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    52
    rights = access.Checker(params)
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    53
    rights['create'] = ['checkIsDeveloper']
1200
e68fd70ba076 Added checkCanEditGroupApp to access.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1185
diff changeset
    54
    rights['delete'] = [('checkCanEditGroupApp',
e68fd70ba076 Added checkCanEditGroupApp to access.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1185
diff changeset
    55
                       [org_app_logic.logic])]
e68fd70ba076 Added checkCanEditGroupApp to access.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1185
diff changeset
    56
    rights['edit'] = [('checkCanEditGroupApp',
e68fd70ba076 Added checkCanEditGroupApp to access.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1185
diff changeset
    57
                       [org_app_logic.logic])]
1182
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    58
    rights['list'] = ['checkIsDeveloper']
1200
e68fd70ba076 Added checkCanEditGroupApp to access.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1185
diff changeset
    59
    rights['public'] = [('checkCanEditGroupApp',
e68fd70ba076 Added checkCanEditGroupApp to access.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1185
diff changeset
    60
                       [org_app_logic.logic])]
1201
0a4c1af700a0 Added checkCanReviewGroupApp to acces.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1200
diff changeset
    61
    rights['review'] = ['checkIsDeveloper',
0a4c1af700a0 Added checkCanReviewGroupApp to acces.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1200
diff changeset
    62
                        ('checkCanReviewGroupApp', [org_app_logic.logic])]
1182
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    63
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    64
    new_params = {}
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    65
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    66
    new_params['rights'] = rights
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    67
    new_params['logic'] = org_app_logic.logic
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    68
1185
fe25d98a24c3 Create org_application now shows select program view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1182
diff changeset
    69
    new_params['scope_view'] = program_view
fe25d98a24c3 Create org_application now shows select program view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1182
diff changeset
    70
    new_params['scope_redirect'] = redirects.getCreateRedirect
fe25d98a24c3 Create org_application now shows select program view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1182
diff changeset
    71
fe25d98a24c3 Create org_application now shows select program view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1182
diff changeset
    72
    new_params['sidebar_grouping'] = 'Organizations'
1182
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    73
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    74
    new_params['extra_dynaexclude'] = ['applicant', 'backup_admin', 'status',
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    75
        'created_on', 'last_modified_on']
1205
2e88261aba72 Added validate_new_group to cleaning and removed clean_new_club_link_id.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1201
diff changeset
    76
1182
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    77
    new_params['create_extra_dynafields'] = {
1205
2e88261aba72 Added validate_new_group to cleaning and removed clean_new_club_link_id.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1201
diff changeset
    78
        'scope_path': forms.fields.CharField(widget=forms.HiddenInput,
2e88261aba72 Added validate_new_group to cleaning and removed clean_new_club_link_id.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1201
diff changeset
    79
                                             required=True),
2e88261aba72 Added validate_new_group to cleaning and removed clean_new_club_link_id.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1201
diff changeset
    80
        'clean': cleaning.validate_new_group('link_id', 'scope_path',
2e88261aba72 Added validate_new_group to cleaning and removed clean_new_club_link_id.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1201
diff changeset
    81
            model_logic.organization, org_app_logic)}
2e88261aba72 Added validate_new_group to cleaning and removed clean_new_club_link_id.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1201
diff changeset
    82
2e88261aba72 Added validate_new_group to cleaning and removed clean_new_club_link_id.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1201
diff changeset
    83
    # get rid of the clean method
2e88261aba72 Added validate_new_group to cleaning and removed clean_new_club_link_id.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1201
diff changeset
    84
    new_params['edit_extra_dynafields'] = {
2e88261aba72 Added validate_new_group to cleaning and removed clean_new_club_link_id.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1201
diff changeset
    85
        'clean': (lambda x: x.cleaned_data)}
1182
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    86
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    87
    new_params['name'] = "Organization Application"
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    88
    new_params['name_plural'] = "Organization Applications"
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    89
    new_params['name_short'] = "Org App"
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    90
    new_params['url_name'] = "org_app"
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    91
    new_params['group_url_name'] = 'org'
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    92
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    93
    new_params['review_template'] = 'soc/org_app/review.html'
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    94
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    95
    params = dicts.merge(params, new_params)
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    96
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    97
    super(View, self).__init__(params=params)
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    98
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    99
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
   100
view = View()
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
   101
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
   102
create = view.create
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
   103
delete = view.delete
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
   104
edit = view.edit
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
   105
list = view.list
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
   106
public = view.public
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
   107
export = view.export
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
   108
review = view.review
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
   109
review_overview = view.reviewOverview
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
   110