app/soc/views/models/group_app.py
author Lennard de Rijk <ljvderijk@gmail.com>
Sat, 07 Feb 2009 21:43:27 +0000
changeset 1244 20494064bc3f
parent 1238 af56ae7397ab
child 1246 756fd7195213
permissions -rw-r--r--
Should be part of r1855. FOSDEM got the best of me :). 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 Group App.
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>',
1138
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
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
1138
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
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
1138
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    29
from soc.logic import accounts
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    30
from soc.logic import cleaning
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
from soc.logic import dicts
1138
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    32
from soc.logic.helper import notifications
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    33
from soc.logic.models import group_app as group_app_logic
1138
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    34
from soc.logic.models import user as user_logic
1139
7a6f94ffcc87 Changed the url regexpr for review and added 2 missing imports.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1138
diff changeset
    35
from soc.views import helper
7a6f94ffcc87 Changed the url regexpr for review and added 2 missing imports.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1138
diff changeset
    36
from soc.views import out_of_band
1138
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    37
from soc.views.helper import decorators
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    38
from soc.views.helper import lists as list_helper
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    39
from soc.views.helper import redirects
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    40
from soc.views.helper import responses
1229
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1225
diff changeset
    41
from soc.views.helper import widgets
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    42
from soc.views.models import base
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.models.group_app
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(base.View):
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    48
  """View methods for the Group App model.
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
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    57
    """
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    58
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    59
    new_params = {}
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    60
    new_params['logic'] = soc.logic.models.group_app.logic
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    61
799
30a912906a57 Construct names automatically from base name.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 791
diff changeset
    62
    new_params['name'] = "Group Application"
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    63
    new_params['name_short'] = "Group App"
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    64
1138
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    65
    # use the twoline templates for these questionnaires
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    66
    new_params['create_template'] = 'soc/models/twoline_edit.html'
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    67
    new_params['edit_template'] = 'soc/models/twoline_edit.html'
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    68
1244
20494064bc3f Should be part of r1855.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1238
diff changeset
    69
    patterns = [(r'^%(url_name)s/(?P<access_type>review_overview)$',
1138
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    70
        'soc.views.models.%(module_name)s.review_overview',
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    71
        'Review %(name_plural)s'),
1139
7a6f94ffcc87 Changed the url regexpr for review and added 2 missing imports.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1138
diff changeset
    72
        (r'^%(url_name)s/(?P<access_type>review)/%(key_fields)s$',
1138
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    73
          'soc.views.models.%(module_name)s.review',
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    74
          'Review %(name_short)s')]
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    75
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    76
    new_params['extra_django_patterns'] = patterns
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    77
1244
20494064bc3f Should be part of r1855.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1238
diff changeset
    78
    new_params['sidebar_additional'] = [
20494064bc3f Should be part of r1855.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1238
diff changeset
    79
        ('/%(url_name)s/review_overview' % params,
20494064bc3f Should be part of r1855.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1238
diff changeset
    80
         'Review %(name_plural)s' % params, 'review_overview')]
20494064bc3f Should be part of r1855.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1238
diff changeset
    81
1138
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    82
    new_params['extra_dynaexclude'] = ['applicant', 'backup_admin', 'status',
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    83
        'created_on', 'last_modified_on']
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    84
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    85
    new_params['create_extra_dynafields'] = {
1229
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1225
diff changeset
    86
        'backup_admin_link_id': widgets.ReferenceField(
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1225
diff changeset
    87
              reference_url='user',
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1225
diff changeset
    88
              label=params['logic'].getModel().backup_admin.verbose_name),
1138
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    89
        'clean_backup_admin_link_id': 
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    90
            cleaning.clean_users_not_same('backup_admin_link_id'),
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    91
        }
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    92
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    93
    new_params['edit_extra_dynafields'] = {
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    94
        'clean_link_id' : cleaning.clean_link_id('link_id'),
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    95
        }
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    96
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
    97
    params = dicts.merge(params, new_params, sub_merge=True)
791
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    98
30da180c4bca Added the club_app view, logic and model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    99
    super(View, self).__init__(params=params)
858
e79e7a22326f Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents: 799
diff changeset
   100
1138
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   101
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   102
  def _editGet(self, request, entity, form):
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   103
    """See base.View._editGet().
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   104
    """
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   105
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   106
    form.fields['backup_admin_link_id'].initial = entity.backup_admin.link_id
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   107
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   108
    super(View, self)._editGet(request, entity, form)
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   109
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   110
  def _editPost(self, request, entity, fields):
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   111
    """See base.View._editPost().
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   112
    """
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   113
1202
8060f33a164f Added removal of an existing group application when someone else is applying.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1196
diff changeset
   114
    if not entity:
8060f33a164f Added removal of an existing group application when someone else is applying.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1196
diff changeset
   115
      # set the applicant field to the current user
1217
aeabe6bed55b Reverted r1819 and making an application will now reserve the link_id indefinitely.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1204
diff changeset
   116
      fields['applicant'] = user_logic.logic.getForCurrentAccount()
1202
8060f33a164f Added removal of an existing group application when someone else is applying.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1196
diff changeset
   117
8060f33a164f Added removal of an existing group application when someone else is applying.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1196
diff changeset
   118
    #set the backup_admin field with the cleaned link_id
8060f33a164f Added removal of an existing group application when someone else is applying.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1196
diff changeset
   119
    fields['backup_admin'] = fields['backup_admin_link_id']
1138
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   120
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   121
    # the application has either been created or edited so
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   122
    # the status needs to be set accordingly
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   123
    fields['status'] = 'needs review'
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   124
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   125
    super(View, self)._editPost(request, entity, fields)
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   126
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   127
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   128
  def _public(self, request, entity, context):
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   129
    """See base._public().
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   130
    """
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   131
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   132
    context['entity_type_url'] = self._params['url_name']
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   133
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   134
    super(View, self)._public(request, entity, context)
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   135
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   136
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   137
  @decorators.merge_params
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   138
  @decorators.check_access
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   139
  def list(self, request, access_type,
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   140
           page_name=None, params=None, filter=None):
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   141
    """Lists all notifications that the current logged in user has stored.
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   142
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   143
    for parameters see base.list()
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   144
    """
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   145
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   146
    # get the current user
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   147
    user_entity = user_logic.logic.getForCurrentAccount()
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   148
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   149
    is_developer = accounts.isDeveloper(user=user_entity)
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   150
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   151
    filter = {
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   152
        'status': 'needs review',
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   153
        }
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   154
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   155
    if not is_developer:
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   156
      # only select the applications for this user so construct a filter
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   157
      filter['applicant'] = user_entity
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   158
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   159
    # get all the pending applications
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   160
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   161
    pa_params = params.copy() # pending applications
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   162
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   163
    if is_developer:
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   164
      pa_params['list_description'] = ugettext(
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   165
          "An overview of all pending %(name_plural)s.") % params
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   166
    else:
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   167
      pa_params['list_description'] = ugettext(
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   168
          "An overview of your pending %(name_plural)s.") % params
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   169
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   170
    pa_list = list_helper.getListContent(
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   171
        request, pa_params, filter, 0)
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   172
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   173
    # get all the reviewed applications now
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   174
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   175
    # re-use the old filter, but set to only reviewed and accepted
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   176
    filter['status'] = 'accepted'
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   177
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   178
    aa_params = params.copy() # accepted applications
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   179
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   180
    if is_developer:
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   181
      aa_params['list_description'] = ugettext(
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   182
          "An overview of all accepted %(name_plural)s.") % params
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   183
    else:
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   184
      aa_params['list_description'] = ugettext(
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   185
          "An overview of your accepted %(name_plural)s.") % params
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   186
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   187
    aa_params['url_name'] = params['group_url_name']
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   188
    aa_params['list_action'] = (redirects.getApplicantRedirect, aa_params)
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   189
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   190
    aa_list = list_helper.getListContent(
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   191
        request, aa_params, filter, 1)
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   192
1232
3bce6205e24e Added pre-accpeted status to group_app.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1229
diff changeset
   193
    if is_developer:
3bce6205e24e Added pre-accpeted status to group_app.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1229
diff changeset
   194
      # re use the old filter, but this time only for pre-accepted apps
3bce6205e24e Added pre-accpeted status to group_app.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1229
diff changeset
   195
      filter['status'] = 'pre-accepted'
3bce6205e24e Added pre-accpeted status to group_app.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1229
diff changeset
   196
3bce6205e24e Added pre-accpeted status to group_app.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1229
diff changeset
   197
      pa_params = params.copy() # pre-accepted applications
3bce6205e24e Added pre-accpeted status to group_app.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1229
diff changeset
   198
3bce6205e24e Added pre-accpeted status to group_app.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1229
diff changeset
   199
      pa_params['list_description'] = ugettext(
3bce6205e24e Added pre-accpeted status to group_app.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1229
diff changeset
   200
          "An overview of all pre-accepted %(name_plural)s.") % params
3bce6205e24e Added pre-accpeted status to group_app.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1229
diff changeset
   201
3bce6205e24e Added pre-accpeted status to group_app.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1229
diff changeset
   202
      pa_list = list_helper.getListContent(
3bce6205e24e Added pre-accpeted status to group_app.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1229
diff changeset
   203
          request, pa_params, filter, 4)
3bce6205e24e Added pre-accpeted status to group_app.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1229
diff changeset
   204
3bce6205e24e Added pre-accpeted status to group_app.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1229
diff changeset
   205
      contents += [pa_list]
3bce6205e24e Added pre-accpeted status to group_app.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1229
diff changeset
   206
1138
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   207
    # get all the reviewed applications that were denied
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   208
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   209
    # re use the old filter, but this time only for denied apps
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   210
    filter['status'] = 'rejected'
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   211
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   212
    da_params = params.copy() # denied applications
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   213
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   214
    if is_developer:
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   215
      da_params['list_description'] = ugettext(
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   216
          "An overview of all denied %(name_plural)s.") % params
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   217
    else:
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   218
      da_params['list_description'] = ugettext(
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   219
          "An overview of your denied %(name_plural)s.") % params
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   220
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   221
    da_list = list_helper.getListContent(
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   222
        request, da_params, filter, 2)
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   223
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   224
    contents = [pa_list, aa_list, da_list]
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   225
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   226
    if is_developer:
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   227
      # re use the old filter, but this time only for ignored apps
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   228
      filter['status'] = 'ignored'
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   229
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   230
      ia_params = params.copy() # ignored applications
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   231
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   232
      ia_params['list_description'] = ugettext(
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   233
          "An overview of all ignored %(name_plural)s.") % params
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   234
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   235
      ia_list = list_helper.getListContent(
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   236
          request, ia_params, filter, 3)
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   237
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   238
      contents += [ia_list]
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   239
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   240
    # call the _list method from base to display the list
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   241
    return self._list(request, params, contents, page_name)
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   242
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   243
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   244
  @decorators.merge_params
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   245
  @decorators.check_access
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   246
  def review(self, request, access_type,
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   247
             page_name=None, params=None, **kwargs):
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   248
    """Handles the view containing the review of an application.
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   249
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   250
    accepted (true or false) in the GET data will mark
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   251
    the application accordingly.
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   252
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   253
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   254
    For params see base.View.public().
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   255
    """
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   256
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   257
    # create default template context for use with any templates
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   258
    context = responses.getUniversalContext(request)
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   259
    context['page_name'] = page_name
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   260
    entity = None
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   261
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   262
    try:
1218
569a3fe9cb88 Cleaned up getKeyNameFromFields in Logic base.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1217
diff changeset
   263
      entity = self._logic.getFromKeyFieldsOr404(kwargs)
1138
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   264
    except out_of_band.Error, error:
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   265
      return helper.responses.errorResponse(
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   266
          error, request, template=params['error_public'], context=context)
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   267
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   268
    get_dict = request.GET
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   269
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   270
    # check to see if we can make a decision for this application
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   271
    if 'status' in get_dict.keys():
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   272
      status_value = get_dict['status']
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   273
1232
3bce6205e24e Added pre-accpeted status to group_app.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1229
diff changeset
   274
      if status_value in ['accepted', 'rejected', 'ignored', 'pre-accepted']:
1138
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   275
        # this application has been properly reviewed update the status
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   276
1196
11dbdf12d7c2 Only do the update routine when the status changes for group_app's and role requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1139
diff changeset
   277
        # only update if the status changes
11dbdf12d7c2 Only do the update routine when the status changes for group_app's and role requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1139
diff changeset
   278
        if entity.status != status_value:
11dbdf12d7c2 Only do the update routine when the status changes for group_app's and role requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1139
diff changeset
   279
          fields = {'status' : status_value}
1138
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   280
1196
11dbdf12d7c2 Only do the update routine when the status changes for group_app's and role requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1139
diff changeset
   281
          self._logic.updateEntityProperties(entity, fields)
11dbdf12d7c2 Only do the update routine when the status changes for group_app's and role requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1139
diff changeset
   282
11dbdf12d7c2 Only do the update routine when the status changes for group_app's and role requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1139
diff changeset
   283
          if status_value == 'accepted':
11dbdf12d7c2 Only do the update routine when the status changes for group_app's and role requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1139
diff changeset
   284
            # the application has been accepted send out a notification
11dbdf12d7c2 Only do the update routine when the status changes for group_app's and role requests.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1139
diff changeset
   285
            notifications.sendNewGroupNotification(entity, params)
1138
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   286
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   287
        return self.reviewOverview(request, access_type,
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   288
            page_name=page_name, params=params, **kwargs)
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   289
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   290
    # the application has not been reviewed so show the information
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   291
    # using the appropriate review template
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   292
    params['public_template'] = params['review_template']
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   293
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   294
    return super(View, self).public(request, access_type,
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   295
        page_name=page_name, params=params, **kwargs)
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   296
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   297
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   298
  @decorators.merge_params
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   299
  @decorators.check_access
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   300
  def reviewOverview(self, request, access_type,
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   301
             page_name=None, params=None, **kwargs):
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   302
    """Displays multiple lists of applications that are in a different
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   303
    status of the application process.
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   304
    """
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   305
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   306
    params = dicts.merge(params, self._params)
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   307
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   308
    # only select the requests that haven't been reviewed yet
1244
20494064bc3f Should be part of r1855.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1238
diff changeset
   309
    filter = {'status' : 'needs review'}
1138
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   310
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   311
    ur_params = params.copy()
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   312
    ur_params['list_description'] = ugettext('A list of all unhandled '
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   313
        '%(name_plural)s.') % params
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   314
    ur_params ['list_action'] = (redirects.getReviewRedirect, params)
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   315
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   316
    ur_list = list_helper.getListContent(
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   317
        request, ur_params, filter, 0)
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   318
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   319
    # only select the requests that haven't been turned into a group yet
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   320
    filter['status'] = 'accepted'
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   321
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   322
    uh_params = params.copy()
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   323
    uh_params['list_description'] = ugettext('A list of all %(name_plural)s '
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   324
        'that have been accepted but not completed yet') % params
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   325
    uh_params ['list_action'] = (redirects.getReviewRedirect, params)
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   326
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   327
    uh_list = list_helper.getListContent(
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   328
        request, uh_params, filter, 1)
1232
3bce6205e24e Added pre-accpeted status to group_app.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1229
diff changeset
   329
    
3bce6205e24e Added pre-accpeted status to group_app.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1229
diff changeset
   330
    # only select the requests that have been pre-accpeted
3bce6205e24e Added pre-accpeted status to group_app.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1229
diff changeset
   331
    filter['status'] = 'pre-accepted'
3bce6205e24e Added pre-accpeted status to group_app.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1229
diff changeset
   332
3bce6205e24e Added pre-accpeted status to group_app.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1229
diff changeset
   333
    pa_params = params.copy()
3bce6205e24e Added pre-accpeted status to group_app.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1229
diff changeset
   334
    pa_params['list_description'] = ugettext(
3bce6205e24e Added pre-accpeted status to group_app.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1229
diff changeset
   335
        "An overview of all pre-accepted %(name_plural)s.") % params
3bce6205e24e Added pre-accpeted status to group_app.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1229
diff changeset
   336
    pa_params ['list_action'] = (redirects.getReviewRedirect, params)
3bce6205e24e Added pre-accpeted status to group_app.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1229
diff changeset
   337
3bce6205e24e Added pre-accpeted status to group_app.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1229
diff changeset
   338
    pa_list = list_helper.getListContent(
1244
20494064bc3f Should be part of r1855.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1238
diff changeset
   339
        request, pa_params, filter, 4)
1138
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   340
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   341
    # only select the requests the have been rejected
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   342
    filter ['status'] = 'rejected'
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   343
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   344
    den_params = params.copy()
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   345
    den_params['list_description'] = ugettext('A list of all %(name_plural)s '
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   346
        'that have been rejected') % params
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   347
    den_params ['list_action'] = (redirects.getReviewRedirect, params)
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   348
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   349
    den_list = list_helper.getListContent(
1244
20494064bc3f Should be part of r1855.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1238
diff changeset
   350
        request, den_params, filter, 2)
1138
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   351
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   352
    # only select the request that have been ignored
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   353
    filter ['status'] = 'ignored'
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   354
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   355
    ign_params = params.copy()
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   356
    ign_params['list_description'] = ugettext('A list of all %(name_plural)s '
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   357
        'that have been ignored') % params
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   358
    ign_params ['list_action'] = (redirects.getReviewRedirect, params)
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   359
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   360
    ign_list = list_helper.getListContent(
1244
20494064bc3f Should be part of r1855.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1238
diff changeset
   361
        request, ign_params, filter, 3)
1138
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   362
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   363
    # fill contents with all the needed lists
1232
3bce6205e24e Added pre-accpeted status to group_app.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1229
diff changeset
   364
    contents = [ur_list, uh_list, pa_list, den_list, ign_list]
1138
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   365
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   366
    # call the _list method from base to display the list
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   367
    return self._list(request, params, contents, page_name)
18ef39338211 Refactored review and reviewoverview out of club_app.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 858
diff changeset
   368