app/soc/views/models/club_app.py
author Lennard de Rijk <ljvderijk@gmail.com>
Fri, 30 Jan 2009 11:16:48 +0000
changeset 1081 81cf69225a24
parent 1080 d533408811ba
child 1083 b8018d7a9f23
permissions -rw-r--r--
Added a cleaning method to club_app view. This ensures that you can't create a application for an already taken Link ID. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
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
#
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
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
970
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 944
diff changeset
    27
from django.utils.translation import ugettext
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
from soc.logic import accounts
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
from soc.logic import cleaning
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
from soc.logic import dicts
821
5afe16b2e86b Send a notifcation if a club application is accepted
Sverre Rabbelier <srabbelier@gmail.com>
parents: 818
diff changeset
    32
from soc.logic.helper import notifications
1081
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
    33
from soc.logic import models as model_logic
882
267e31f1a0b6 Added club_app model and logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 876
diff changeset
    34
from soc.logic.models import club_app as club_app_logic
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
from soc.logic.models import user as user_logic
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    36
from soc.views import helper
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
    37
from soc.views import out_of_band
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
    38
from soc.views.helper import access
876
0c1329d4b514 Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 875
diff changeset
    39
from soc.views.helper import decorators
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
    40
from soc.views.helper import redirects
823
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
    41
from soc.views.helper import lists as list_helper
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    42
from soc.views.models import group_app
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    43
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    44
import soc.logic.dicts
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
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
class View(group_app.View):
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
    48
  """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
    49
  """
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    50
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    51
  def __init__(self, params=None):
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    52
    """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
    53
    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
    54
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    55
    Params:
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    56
      params: a dict with params for this View
818
ddd102e82107 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 803
diff changeset
    57
    """
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    58
1007
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 986
diff changeset
    59
    rights = access.Checker(params)
1012
73f0b61f2d9d Fold checkAgreesToSiteToS into checkIsUser
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    60
    rights['create'] = ['checkIsUser']
1007
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 986
diff changeset
    61
    rights['delete'] = [('checkIsMyApplication', club_app_logic)]
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 986
diff changeset
    62
    rights['edit'] = [('checkIsMyApplication', club_app_logic)]
1012
73f0b61f2d9d Fold checkAgreesToSiteToS into checkIsUser
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    63
    rights['list'] = ['checkIsUser']
1007
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 986
diff changeset
    64
    rights['public'] = [('checkIsMyApplication', club_app_logic)]
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 986
diff changeset
    65
    rights['review'] = ['checkIsHost']
791
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 = {}
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    68
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    69
    new_params['rights'] = rights
882
267e31f1a0b6 Added club_app model and logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 876
diff changeset
    70
    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
    71
1025
1f83f05f522b Add grouping to the existing views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1012
diff changeset
    72
    new_params['sidebar_grouping'] = 'Clubs'
1f83f05f522b Add grouping to the existing views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1012
diff changeset
    73
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    74
    new_params['create_template'] = 'soc/models/twoline_edit.html'
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    75
    new_params['edit_template'] = 'soc/models/twoline_edit.html'
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    76
1080
d533408811ba Changed status in group app model to state.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1025
diff changeset
    77
    new_params['extra_dynaexclude'] = ['applicant', 'backup_admin', 'state',
882
267e31f1a0b6 Added club_app model and logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 876
diff changeset
    78
        'created_on', 'last_modified_on']
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    79
    new_params['create_extra_dynafields'] = {
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    80
        'backup_admin_link_id': forms.CharField(
882
267e31f1a0b6 Added club_app model and logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 876
diff changeset
    81
              label=soc.models.club_app.ClubApplication.backup_admin.verbose_name
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    82
              ),
886
f5847f24c56e Added clean_existing_user_not_equal_to_current to clean the backup Administrator field in an application.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 885
diff changeset
    83
        'clean_backup_admin_link_id': 
905
70eb2493a346 Rename clean_existing_user_not_equal_to_current function to clean_users_not_same in soc.logic.cleaning module and fix affected files.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 902
diff changeset
    84
            cleaning.clean_users_not_same('backup_admin_link_id'),
1081
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
    85
        'clean_link_id' : self.clean_club_app_link_id('link_id')
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    86
        }
818
ddd102e82107 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 803
diff changeset
    87
1080
d533408811ba Changed status in group app model to state.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1025
diff changeset
    88
    new_params['edit_extra_dynafields'] = {
d533408811ba Changed status in group app model to state.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1025
diff changeset
    89
        'clean_link_id' : cleaning.clean_link_id('link_id'),
d533408811ba Changed status in group app model to state.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1025
diff changeset
    90
        }
d533408811ba Changed status in group app model to state.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1025
diff changeset
    91
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
    92
    patterns = [(r'^%(url_name)s/(?P<access_type>review)$',
875
03c674f510d8 Renamed showReviewOverview to review_overview and reviewOverview
Sverre Rabbelier <srabbelier@gmail.com>
parents: 858
diff changeset
    93
        'soc.views.models.%(module_name)s.review_overview',
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
    94
        'Review %(name_plural)s'),
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
    95
        (r'^%(url_name)s/(?P<access_type>review)/%(lnp)s$',
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
    96
          'soc.views.models.%(module_name)s.review',
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
    97
          'Review %(name_short)s')]
818
ddd102e82107 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 803
diff changeset
    98
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
    99
    new_params['extra_django_patterns'] = patterns
818
ddd102e82107 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 803
diff changeset
   100
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   101
    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
   102
    new_params['name_plural'] = "Club Applications"
799
30a912906a57 Construct names automatically from base name.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 798
diff changeset
   103
    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
   104
    new_params['url_name'] = "club_app"
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   105
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   106
    new_params['sidebar_additional'] = [
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   107
        ('/%(url_name)s/review' % new_params,
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   108
         'Review %(name_plural)s' % new_params, 'review')]
818
ddd102e82107 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 803
diff changeset
   109
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   110
    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
   111
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   112
    params = dicts.merge(params, new_params)
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   113
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   114
    super(View, self).__init__(params=params)
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   115
876
0c1329d4b514 Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 875
diff changeset
   116
  @decorators.merge_params
0c1329d4b514 Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 875
diff changeset
   117
  @decorators.check_access
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   118
  def list(self, request, access_type,
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   119
           page_name=None, params=None, filter=None):
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   120
    """Lists all notifications that the current logged in user has stored.
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   121
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   122
    for parameters see base.list()
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   123
    """
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   124
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   125
    # get the current user
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   126
    user_entity = user_logic.logic.getForCurrentAccount()
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   127
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   128
    is_developer = accounts.isDeveloper(user=user_entity)
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   129
823
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   130
    filter = {
1080
d533408811ba Changed status in group app model to state.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1025
diff changeset
   131
        'state': 'needs review',
823
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   132
        }
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   133
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   134
    if not is_developer:
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   135
      # only select the applications for this user so construct a filter
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   136
      filter['applicant'] = user_entity
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   137
893
2dba566e4bf8 Added Ignored applications to the list view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 892
diff changeset
   138
    # get all the pending applications
823
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   139
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   140
    pa_params = params.copy() # pending applications
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   141
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   142
    if is_developer:
970
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 944
diff changeset
   143
      pa_params['list_description'] = ugettext(
836
1abdbedf4208 Add missing 'of' word to list description strings in soc.views.models.club_app module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 823
diff changeset
   144
          "An overview of all pending club applications.")
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   145
    else:
970
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 944
diff changeset
   146
      pa_params['list_description'] = ugettext(
823
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   147
          "An overview of your pending club applications.")
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   148
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   149
    pa_list = list_helper.getListContent(
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   150
        request, pa_params, filter, 0)
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   151
893
2dba566e4bf8 Added Ignored applications to the list view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 892
diff changeset
   152
    # get all the reviewed applications now
823
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   153
893
2dba566e4bf8 Added Ignored applications to the list view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 892
diff changeset
   154
    # re-use the old filter, but set to only reviewed and accepted
1080
d533408811ba Changed status in group app model to state.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1025
diff changeset
   155
    filter['state'] = 'accepted'
823
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   156
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   157
    aa_params = params.copy() # accepted applications
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   158
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   159
    if is_developer:
970
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 944
diff changeset
   160
      aa_params['list_description'] = ugettext(
836
1abdbedf4208 Add missing 'of' word to list description strings in soc.views.models.club_app module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 823
diff changeset
   161
          "An overview of all accepted club applications.")
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   162
    else:
970
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 944
diff changeset
   163
      aa_params['list_description'] = ugettext(
823
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   164
          "An overview of your accepted club applications.")
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   165
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   166
    aa_params['url_name'] = 'club'
885
f46b689e19eb Changed the redirect in club application overview to the correct page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 884
diff changeset
   167
    aa_params['list_action'] = (redirects.getApplicantRedirect, aa_params)
823
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   168
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   169
    aa_list = list_helper.getListContent(
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   170
        request, aa_params, filter, 1)
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   171
893
2dba566e4bf8 Added Ignored applications to the list view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 892
diff changeset
   172
    # get all the reviewed applications that were denied
823
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   173
893
2dba566e4bf8 Added Ignored applications to the list view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 892
diff changeset
   174
    # re use the old filter, but this time only for denied apps
1080
d533408811ba Changed status in group app model to state.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1025
diff changeset
   175
    filter['state'] = 'rejected'
823
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   176
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   177
    da_params = params.copy() # denied applications
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   178
823
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   179
    if is_developer:
970
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 944
diff changeset
   180
      da_params['list_description'] = ugettext(
836
1abdbedf4208 Add missing 'of' word to list description strings in soc.views.models.club_app module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 823
diff changeset
   181
          "An overview of all denied club applications.")
823
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   182
    else:
970
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 944
diff changeset
   183
      da_params['list_description'] = ugettext(
823
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   184
          "An overview of your denied club applications.")
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   185
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   186
    da_list = list_helper.getListContent(
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   187
        request, da_params, filter, 2)
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   188
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   189
    contents = [pa_list, aa_list, da_list]
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   190
893
2dba566e4bf8 Added Ignored applications to the list view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 892
diff changeset
   191
    if is_developer:
2dba566e4bf8 Added Ignored applications to the list view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 892
diff changeset
   192
      # re use the old filter, but this time only for ignored apps
1080
d533408811ba Changed status in group app model to state.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1025
diff changeset
   193
      filter['state'] = 'ignored'
893
2dba566e4bf8 Added Ignored applications to the list view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 892
diff changeset
   194
2dba566e4bf8 Added Ignored applications to the list view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 892
diff changeset
   195
      ia_params = params.copy() # ignored applications
2dba566e4bf8 Added Ignored applications to the list view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 892
diff changeset
   196
970
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 944
diff changeset
   197
      ia_params['list_description'] = ugettext(
893
2dba566e4bf8 Added Ignored applications to the list view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 892
diff changeset
   198
          "An overview of all ignored club applications.")
2dba566e4bf8 Added Ignored applications to the list view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 892
diff changeset
   199
2dba566e4bf8 Added Ignored applications to the list view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 892
diff changeset
   200
      ia_list = list_helper.getListContent(
894
11afeeba198c Corrected the list index parameters in soc/views/models/club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 893
diff changeset
   201
          request, ia_params, filter, 3)
893
2dba566e4bf8 Added Ignored applications to the list view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 892
diff changeset
   202
2dba566e4bf8 Added Ignored applications to the list view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 892
diff changeset
   203
      contents += [ia_list]
2dba566e4bf8 Added Ignored applications to the list view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 892
diff changeset
   204
823
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   205
    # call the _list method from base to display the list
c11a103f103d Add a 'pending/accepted/denied' seperation to club_app list
Sverre Rabbelier <srabbelier@gmail.com>
parents: 821
diff changeset
   206
    return self._list(request, params, contents, page_name)
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   207
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   208
  def _editGet(self, request, entity, form):
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   209
    """See base.View._editGet().
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   210
    """
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   211
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   212
    form.fields['backup_admin_link_id'].initial = entity.backup_admin.link_id
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   213
939
b341698bf3b1 Make reference picker work for create too
Sverre Rabbelier <srabbelier@gmail.com>
parents: 905
diff changeset
   214
    super(View, self)._editGet(request, entity, form)
b341698bf3b1 Make reference picker work for create too
Sverre Rabbelier <srabbelier@gmail.com>
parents: 905
diff changeset
   215
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   216
  def _editPost(self, request, entity, fields):
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   217
    """See base.View._editPost().
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   218
    """
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   219
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   220
    fields['backup_admin'] = fields['backup_admin_link_id']
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   221
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   222
    if not entity:
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   223
      fields['applicant'] = user_logic.logic.getForCurrentAccount()
818
ddd102e82107 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 803
diff changeset
   224
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   225
    # the application has either been created or edited so
1080
d533408811ba Changed status in group app model to state.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1025
diff changeset
   226
    # the state needs to be set accordingly
d533408811ba Changed status in group app model to state.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1025
diff changeset
   227
    fields['state'] = 'needs review'
818
ddd102e82107 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 803
diff changeset
   228
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   229
  def _public(self, request, entity, context):
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   230
    """See base._public().
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   231
    """
818
ddd102e82107 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 803
diff changeset
   232
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   233
    context['entity_type_url'] = self._params['url_name']
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   234
876
0c1329d4b514 Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 875
diff changeset
   235
  @decorators.merge_params
0c1329d4b514 Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 875
diff changeset
   236
  @decorators.check_access
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   237
  def review(self, request, access_type,
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   238
             page_name=None, params=None, **kwargs):
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   239
    """Handles the view containing the review of an application.
818
ddd102e82107 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 803
diff changeset
   240
ddd102e82107 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 803
diff changeset
   241
    accepted (true or false) in the GET data will mark
ddd102e82107 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 803
diff changeset
   242
    the application accordingly.
ddd102e82107 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 803
diff changeset
   243
ddd102e82107 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 803
diff changeset
   244
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   245
    For params see base.View.public().
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   246
    """
818
ddd102e82107 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 803
diff changeset
   247
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   248
    # create default template context for use with any templates
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   249
    context = helper.responses.getUniversalContext(request)
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   250
    context['page_name'] = page_name
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   251
    entity = None
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   252
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   253
    try:
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   254
      key_fields = self._logic.getKeyFieldsFromDict(kwargs)
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   255
      entity = self._logic.getIfFields(key_fields)
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   256
    except out_of_band.Error, error:
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   257
      return helper.responses.errorResponse(
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   258
          error, request, template=params['error_public'], context=context)
818
ddd102e82107 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 803
diff changeset
   259
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   260
    get_dict = request.GET
818
ddd102e82107 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 803
diff changeset
   261
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   262
    # check to see if we can make a decision for this application
1080
d533408811ba Changed status in group app model to state.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1025
diff changeset
   263
    if 'state' in get_dict.keys():
d533408811ba Changed status in group app model to state.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1025
diff changeset
   264
      state_value = get_dict['state']
818
ddd102e82107 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 803
diff changeset
   265
1080
d533408811ba Changed status in group app model to state.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1025
diff changeset
   266
      if state_value in ['accepted', 'rejected', 'ignored']:
d533408811ba Changed status in group app model to state.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1025
diff changeset
   267
        # this application has been properly reviewed update the state
d533408811ba Changed status in group app model to state.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1025
diff changeset
   268
        fields = {'state' : state_value}
818
ddd102e82107 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 803
diff changeset
   269
986
e9611a2288ca Rename ModelProperties to EntityProperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 970
diff changeset
   270
        self._logic.updateEntityProperties(entity, fields)
893
2dba566e4bf8 Added Ignored applications to the list view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 892
diff changeset
   271
        
1080
d533408811ba Changed status in group app model to state.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1025
diff changeset
   272
        if state_value == 'accepted':
893
2dba566e4bf8 Added Ignored applications to the list view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 892
diff changeset
   273
          # the application has been accepted send out a notification
2dba566e4bf8 Added Ignored applications to the list view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 892
diff changeset
   274
          notifications.sendNewClubNotification(entity)
818
ddd102e82107 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 803
diff changeset
   275
875
03c674f510d8 Renamed showReviewOverview to review_overview and reviewOverview
Sverre Rabbelier <srabbelier@gmail.com>
parents: 858
diff changeset
   276
        return self.reviewOverview(request, access_type,
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   277
            page_name=page_name, params=params, **kwargs)
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   278
818
ddd102e82107 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 803
diff changeset
   279
    # the application has not been reviewed so show the information
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   280
    # using the appropriate review template
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   281
    params['public_template'] = params['review_template']
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   282
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   283
    return super(View, self).public(request, access_type,
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   284
        page_name=page_name, params=params, **kwargs)
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   285
876
0c1329d4b514 Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 875
diff changeset
   286
  @decorators.merge_params
0c1329d4b514 Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 875
diff changeset
   287
  @decorators.check_access
875
03c674f510d8 Renamed showReviewOverview to review_overview and reviewOverview
Sverre Rabbelier <srabbelier@gmail.com>
parents: 858
diff changeset
   288
  def reviewOverview(self, request, access_type,
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   289
             page_name=None, params=None, **kwargs):
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   290
    """Displays multiple lists of applications that are in different
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   291
    states of the application process.
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   292
    """
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   293
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   294
    params = dicts.merge(params, self._params)
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   295
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   296
    # only select the requests that haven't been reviewed yet
1080
d533408811ba Changed status in group app model to state.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1025
diff changeset
   297
    filter = {'state' : 'needs review'}
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   298
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   299
    ur_params = params.copy()
970
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 944
diff changeset
   300
    ur_params['list_description'] = ugettext('A list of all unhandled '
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   301
        'applications.')
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   302
    ur_params ['list_action'] = (redirects.getReviewRedirect, params)
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   303
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   304
    ur_list = helper.lists.getListContent(
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   305
        request, ur_params, filter, 0)
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   306
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   307
    # only select the requests that haven't been turned into a group yet
1080
d533408811ba Changed status in group app model to state.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1025
diff changeset
   308
    filter['state'] = 'accepted'
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   309
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   310
    uh_params = params.copy()
970
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 944
diff changeset
   311
    uh_params['list_description'] = ugettext('A list of all applications '
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   312
        'that have been accepted but not turned into a Club yet')
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   313
    uh_params ['list_action'] = (redirects.getReviewRedirect, params)
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   314
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   315
    uh_list = helper.lists.getListContent(
894
11afeeba198c Corrected the list index parameters in soc/views/models/club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 893
diff changeset
   316
        request, uh_params, filter, 1)
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   317
893
2dba566e4bf8 Added Ignored applications to the list view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 892
diff changeset
   318
    # only select the requests the have been rejected
1080
d533408811ba Changed status in group app model to state.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1025
diff changeset
   319
    filter ['state'] = 'rejected'
818
ddd102e82107 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 803
diff changeset
   320
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   321
    den_params = params.copy()
970
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 944
diff changeset
   322
    den_params['list_description'] = ugettext('A list of all applications '
902
0cc7a76f0eb3 Fixed one style error and one typo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 897
diff changeset
   323
        'that have been rejected')
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   324
    den_params ['list_action'] = (redirects.getReviewRedirect, params)
818
ddd102e82107 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 803
diff changeset
   325
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   326
    den_list = helper.lists.getListContent(
894
11afeeba198c Corrected the list index parameters in soc/views/models/club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 893
diff changeset
   327
        request, den_params, filter, 2)
818
ddd102e82107 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 803
diff changeset
   328
893
2dba566e4bf8 Added Ignored applications to the list view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 892
diff changeset
   329
    # only select the request that have been ignored
1080
d533408811ba Changed status in group app model to state.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1025
diff changeset
   330
    filter ['state'] = 'ignored'
893
2dba566e4bf8 Added Ignored applications to the list view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 892
diff changeset
   331
2dba566e4bf8 Added Ignored applications to the list view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 892
diff changeset
   332
    ign_params = params.copy()
970
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 944
diff changeset
   333
    ign_params['list_description'] = ugettext('A list of all applications '
893
2dba566e4bf8 Added Ignored applications to the list view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 892
diff changeset
   334
        'that have been ignored')
2dba566e4bf8 Added Ignored applications to the list view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 892
diff changeset
   335
    ign_params ['list_action'] = (redirects.getReviewRedirect, params)
2dba566e4bf8 Added Ignored applications to the list view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 892
diff changeset
   336
2dba566e4bf8 Added Ignored applications to the list view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 892
diff changeset
   337
    ign_list = helper.lists.getListContent(
894
11afeeba198c Corrected the list index parameters in soc/views/models/club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 893
diff changeset
   338
        request, ign_params, filter, 3)
893
2dba566e4bf8 Added Ignored applications to the list view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 892
diff changeset
   339
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   340
    # fill contents with all the needed lists
893
2dba566e4bf8 Added Ignored applications to the list view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 892
diff changeset
   341
    contents = [ur_list, uh_list, den_list, ign_list]
818
ddd102e82107 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 803
diff changeset
   342
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   343
    # call the _list method from base to display the list
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   344
    return self._list(request, params, contents, page_name)
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   345
1081
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   346
  def clean_club_app_link_id(self, field_name):
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   347
    """Cleans the link_id in the club application form
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   348
    """
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   349
    def wrapper(self):
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   350
      # validate the link_id
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   351
      club_link_id = cleaning.clean_link_id(field_name)(self)
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   352
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   353
      # check if there is already an application with the given link_id
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   354
      fields = {'link_id': club_link_id,
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   355
                'state': ['accepted','ignored','needs review','completed']}
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   356
      club_app_entity = club_app_logic.logic.getForFields(fields, unique=True)
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   357
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   358
      if club_app_entity:
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   359
        raise forms.ValidationError(
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   360
            ugettext('This link ID is already in use, please specify another one'))
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   361
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   362
      # check if there is already a club with the given link_id
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   363
      fields['state'] = ['new', 'active', 'inactive']
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   364
      club_logic = model_logic.club
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   365
      club_entity = club_logic.logic.getForFields(fields, unique=True)
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   366
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   367
      if club_entity:
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   368
        raise forms.ValidationError(
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   369
            ugettext('This link ID is already in use, please specify another one'))
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   370
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   371
      return club_link_id
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   372
    return wrapper
81cf69225a24 Added a cleaning method to club_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1080
diff changeset
   373
1080
d533408811ba Changed status in group app model to state.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1025
diff changeset
   374
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   375
view = View()
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   376
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   377
create = view.create
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   378
delete = view.delete
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   379
edit = view.edit
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   380
list = view.list
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   381
public = view.public
858
e79e7a22326f Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents: 836
diff changeset
   382
export = view.export
797
0bc3f950d7cf Added basic review functionality for club applications.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 791
diff changeset
   383
review = view.review
875
03c674f510d8 Renamed showReviewOverview to review_overview and reviewOverview
Sverre Rabbelier <srabbelier@gmail.com>
parents: 858
diff changeset
   384
review_overview = 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
   385