app/soc/views/models/club_app.py
author Lennard de Rijk <ljvderijk@gmail.com>
Tue, 28 Jul 2009 11:23:11 +0200
changeset 2685 506cda0463e8
parent 2076 1cd180cc56c9
permissions -rw-r--r--
Added columns to the manage project page that show the amount of evaluations. The total possible amount of evaluations that is shown is based on surveys which have at least one Record.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
1307
091a21cf3627 Update the copyright notice for 2009.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1255
diff changeset
     3
# Copyright 2009 the Melange authors.
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
#
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
#
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    17
"""Views for Club App profiles.
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
"""
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
__authors__ = [
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    21
    '"Sverre Rabbelier" <sverre@rabbelier.nl>',
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
    22
    '"Lennard de Rijk" <ljvderijk@gmail.com>',
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    23
  ]
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    24
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    25
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    26
from django import forms
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
from soc.logic import cleaning
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
from soc.logic import dicts
1081
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
    30
from soc.logic import models as model_logic
1163
d8c50be19232 Cleaned up access.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1138
diff changeset
    31
from soc.logic.models import host as host_logic
882
267e31f1a0b6 Added club_app model and logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 876
diff changeset
    32
from soc.logic.models import club_app as club_app_logic
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
    33
from soc.views.helper import access
1583
1e4c785f1adf Added decorators
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1533
diff changeset
    34
from soc.views.helper import decorators
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
from soc.views.models import group_app
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    36
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    37
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    38
class View(group_app.View):
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
    39
  """View methods for the Club Application model.
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    40
  """
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    42
  def __init__(self, params=None):
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    43
    """Defines the fields and methods required for the base View class
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    44
    to provide the user with list, public, create, edit and delete views.
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
    Params:
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
      params: a dict with params for this View
818
ddd102e82107 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 803
diff changeset
    48
    """
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    49
1007
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 986
diff changeset
    50
    rights = access.Checker(params)
1012
73f0b61f2d9d Fold checkAgreesToSiteToS into checkIsUser
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    51
    rights['create'] = ['checkIsUser']
1615
81f26c9809dc Changed delete rights due to comments on r2138.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
    52
    rights['delete'] = ['checkIsDeveloper']
1200
e68fd70ba076 Added checkCanEditGroupApp to access.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1180
diff changeset
    53
    rights['edit'] = [('checkCanEditGroupApp',
e68fd70ba076 Added checkCanEditGroupApp to access.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1180
diff changeset
    54
                       [club_app_logic.logic])]
1255
9fe8c6c54933 Redone the listing in group_app.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1248
diff changeset
    55
    rights['list'] = ['checkIsDeveloper']
9fe8c6c54933 Redone the listing in group_app.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1248
diff changeset
    56
    rights['list_self'] = ['checkIsUser']
1777
50df3e399836 Fix an access bug
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1662
diff changeset
    57
    rights['show'] = [('checkCanEditGroupApp',
1200
e68fd70ba076 Added checkCanEditGroupApp to access.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1180
diff changeset
    58
                         [club_app_logic.logic])]
1225
1d5c58e24fd3 Org applications can now only be made by a user when a program allows it.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1205
diff changeset
    59
    # TODO(ljvderijk) make sure host role check is fixed
1248
f318538394d9 Rename checkHasActiveRole to checkHasActiveRoleForScope
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1246
diff changeset
    60
    rights['review'] = [('checkHasActiveRoleForScope', host_logic.logic),
1201
0a4c1af700a0 Added checkCanReviewGroupApp to acces.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1200
diff changeset
    61
                        ('checkCanReviewGroupApp', [club_app_logic.logic])]
1662
1ccf04cbca15 Fix too long lines soc.views.models.club_admin, club_app and club_member modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1615
diff changeset
    62
    rights['review_overview'] = [('checkHasActiveRoleForScope', 
1ccf04cbca15 Fix too long lines soc.views.models.club_admin, club_app and club_member modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1615
diff changeset
    63
                                  host_logic.logic)]
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    64
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    65
    new_params = {}
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    66
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    67
    new_params['rights'] = rights
882
267e31f1a0b6 Added club_app model and logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 876
diff changeset
    68
    new_params['logic'] = club_app_logic.logic
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    69
1025
1f83f05f522b Add grouping to the existing views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1012
diff changeset
    70
    new_params['sidebar_grouping'] = 'Clubs'
1f83f05f522b Add grouping to the existing views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1012
diff changeset
    71
1875
69d60793092a Specify the type of Link ID used
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1777
diff changeset
    72
    new_params['create_dynafields'] = [
69d60793092a Specify the type of Link ID used
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1777
diff changeset
    73
        {'name': 'link_id',
69d60793092a Specify the type of Link ID used
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1777
diff changeset
    74
         'base': forms.fields.CharField,
69d60793092a Specify the type of Link ID used
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1777
diff changeset
    75
         'label': 'Club Link ID',
69d60793092a Specify the type of Link ID used
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1777
diff changeset
    76
         },
69d60793092a Specify the type of Link ID used
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1777
diff changeset
    77
        ]
69d60793092a Specify the type of Link ID used
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1777
diff changeset
    78
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1343
diff changeset
    79
    new_params['create_extra_dynaproperties'] = {
1205
2e88261aba72 Added validate_new_group to cleaning and removed clean_new_club_link_id.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1203
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: 1203
diff changeset
    81
            model_logic.club, club_app_logic)}
2e88261aba72 Added validate_new_group to cleaning and removed clean_new_club_link_id.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1203
diff changeset
    82
2e88261aba72 Added validate_new_group to cleaning and removed clean_new_club_link_id.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1203
diff changeset
    83
    # get rid of the clean method
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1343
diff changeset
    84
    new_params['edit_extra_dynaproperties'] = {
1205
2e88261aba72 Added validate_new_group to cleaning and removed clean_new_club_link_id.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1203
diff changeset
    85
        'clean': (lambda x: x.cleaned_data)}
818
ddd102e82107 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 803
diff changeset
    86
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    87
    new_params['name'] = "Club Application"
803
9d0ed410bfd5 Fixed missing params in views/models/club_app.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 799
diff changeset
    88
    new_params['name_plural'] = "Club Applications"
799
30a912906a57 Construct names automatically from base name.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 798
diff changeset
    89
    new_params['name_short'] = "Club App"
803
9d0ed410bfd5 Fixed missing params in views/models/club_app.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 799
diff changeset
    90
    new_params['url_name'] = "club_app"
1533
50fb3a9b6615 Fix for Issue 218.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
    91
    new_params['group_name'] = "Club"
1138
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1115
diff changeset
    92
    new_params['group_url_name'] = 'club'
818
ddd102e82107 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 803
diff changeset
    93
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
    94
    new_params['review_template'] = 'soc/club_app/review.html'
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
    95
1246
756fd7195213 Fixing r1855 that was bugged by Tortoise ^_^.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1244
diff changeset
    96
    new_params['sidebar_additional'] = [
1255
9fe8c6c54933 Redone the listing in group_app.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1248
diff changeset
    97
        ('/%(url_name)s/list_self/' % new_params,
9fe8c6c54933 Redone the listing in group_app.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1248
diff changeset
    98
         'List all my %(name_plural)s' % new_params, 'list_self'),
1246
756fd7195213 Fixing r1855 that was bugged by Tortoise ^_^.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1244
diff changeset
    99
        ('/%(url_name)s/review_overview/' % new_params,
756fd7195213 Fixing r1855 that was bugged by Tortoise ^_^.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1244
diff changeset
   100
         'Review %(name_plural)s' % new_params, 'review_overview')]
756fd7195213 Fixing r1855 that was bugged by Tortoise ^_^.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1244
diff changeset
   101
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   102
    params = dicts.merge(params, new_params)
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   103
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   104
    super(View, self).__init__(params=params)
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   105
1080
d533408811ba Changed status in group app model to state.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1025
diff changeset
   106
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   107
view = View()
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   108
1584
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   109
admin = decorators.view(view.admin)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   110
create = decorators.view(view.create)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   111
delete = decorators.view(view.delete)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   112
edit = decorators.view(view.edit)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   113
list = decorators.view(view.list)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   114
list_self = decorators.view(view.listSelf)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   115
public = decorators.view(view.public)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   116
export = decorators.view(view.export)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   117
review = decorators.view(view.review)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
   118
review_overview = decorators.view(view.reviewOverview)
858
e79e7a22326f Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents: 836
diff changeset
   119