app/soc/views/models/org_app.py
author Lennard de Rijk <ljvderijk@gmail.com>
Fri, 13 Mar 2009 22:35:39 +0000
changeset 1838 5a8a254af95b
parent 1813 5cc9e055a818
child 1862 e913c635575b
permissions -rw-r--r--
Some textual changes for proposal reviewing. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1182
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
     1
#!/usr/bin/python2.5
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
     2
#
1307
091a21cf3627 Update the copyright notice for 2009.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1297
diff changeset
     3
# Copyright 2009 the Melange authors.
1182
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
     4
#
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
     6
# you may not use this file except in compliance with the License.
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
     7
# You may obtain a copy of the License at
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
     8
#
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    10
#
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    14
# See the License for the specific language governing permissions and
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    15
# limitations under the License.
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    16
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    17
"""Views for Organization App profiles.
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    18
"""
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    19
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    20
__authors__ = [
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    21
    '"Lennard de Rijk" <ljvderijk@gmail.com>',
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    22
  ]
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    23
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    24
1553
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
    25
import os
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
    26
1182
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    27
from django import forms
1294
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
    28
from django.utils import simplejson
1182
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    29
1553
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
    30
from soc.logic import accounts
1205
2e88261aba72 Added validate_new_group to cleaning and removed clean_new_club_link_id.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1201
diff changeset
    31
from soc.logic import cleaning
1182
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    32
from soc.logic import dicts
1553
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
    33
from soc.logic import mail_dispatcher
1205
2e88261aba72 Added validate_new_group to cleaning and removed clean_new_club_link_id.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1201
diff changeset
    34
from soc.logic import models as model_logic
1276
7f460f46a611 Initial implementation of a ToS requirement in org_app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1255
diff changeset
    35
from soc.logic.models import program as program_logic
1182
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    36
from soc.logic.models import org_app as org_app_logic
1566
5388270fb363 contrib template in org_app is now a TextProperty.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1559
diff changeset
    37
from soc.views import helper
1182
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    38
from soc.views.helper import access
1225
1d5c58e24fd3 Org applications can now only be made by a user when a program allows it.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1205
diff changeset
    39
from soc.views.helper import decorators
1185
fe25d98a24c3 Create org_application now shows select program view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1182
diff changeset
    40
from soc.views.helper import redirects
1294
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
    41
from soc.views.helper import responses
1276
7f460f46a611 Initial implementation of a ToS requirement in org_app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1255
diff changeset
    42
from soc.views.helper import widgets
1182
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    43
from soc.views.models import group_app
1185
fe25d98a24c3 Create org_application now shows select program view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1182
diff changeset
    44
from soc.views.models import program as program_view
1182
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    45
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    46
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    47
class View(group_app.View):
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    48
  """View methods for the Organization Application model.
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    49
  """
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    50
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    51
  def __init__(self, params=None):
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    52
    """Defines the fields and methods required for the base View class
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    53
    to provide the user with list, public, create, edit and delete views.
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    54
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    55
    Params:
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    56
      params: a dict with params for this View
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    57
    """
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    58
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    59
    rights = access.Checker(params)
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    60
    rights['create'] = ['checkIsDeveloper']
1615
81f26c9809dc Changed delete rights due to comments on r2138.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
    61
    rights['delete'] = ['checkIsDeveloper']
1200
e68fd70ba076 Added checkCanEditGroupApp to access.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1185
diff changeset
    62
    rights['edit'] = [('checkCanEditGroupApp',
1225
1d5c58e24fd3 Org applications can now only be made by a user when a program allows it.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1205
diff changeset
    63
                       [org_app_logic.logic]),
1d5c58e24fd3 Org applications can now only be made by a user when a program allows it.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1205
diff changeset
    64
                       ('checkIsActivePeriod', ['org_signup', 'scope_path'])]
1182
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    65
    rights['list'] = ['checkIsDeveloper']
1255
9fe8c6c54933 Redone the listing in group_app.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1250
diff changeset
    66
    rights['list_self'] = ['checkIsUser']
1777
50df3e399836 Fix an access bug
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1763
diff changeset
    67
    rights['show'] = [('checkCanEditGroupApp',
1200
e68fd70ba076 Added checkCanEditGroupApp to access.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1185
diff changeset
    68
                       [org_app_logic.logic])]
1250
b06e6e014658 Fixed access checkers for orgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1246
diff changeset
    69
    rights['review'] = ['checkIsHostForProgramInScope',
1201
0a4c1af700a0 Added checkCanReviewGroupApp to acces.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1200
diff changeset
    70
                        ('checkCanReviewGroupApp', [org_app_logic.logic])]
1250
b06e6e014658 Fixed access checkers for orgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1246
diff changeset
    71
    rights['review_overview'] = ['checkIsHostForProgramInScope']
1294
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
    72
    rights['bulk_accept'] = ['checkIsHostForProgramInScope']
1537
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
    73
    rights['bulk_reject'] = ['checkIsHostForProgramInScope']
1225
1d5c58e24fd3 Org applications can now only be made by a user when a program allows it.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1205
diff changeset
    74
    rights['apply'] = ['checkIsUser',
1559
283046e54c01 Fixed issue 205.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1553
diff changeset
    75
                             ('checkCanCreateOrgApp', ['org_signup']),
283046e54c01 Fixed issue 205.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1553
diff changeset
    76
                       'checkIsNotStudentForProgramInScope']
1182
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    77
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    78
    new_params = {}
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    79
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    80
    new_params['rights'] = rights
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    81
    new_params['logic'] = org_app_logic.logic
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    82
1185
fe25d98a24c3 Create org_application now shows select program view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1182
diff changeset
    83
    new_params['scope_view'] = program_view
fe25d98a24c3 Create org_application now shows select program view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1182
diff changeset
    84
    new_params['scope_redirect'] = redirects.getCreateRedirect
fe25d98a24c3 Create org_application now shows select program view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1182
diff changeset
    85
fe25d98a24c3 Create org_application now shows select program view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1182
diff changeset
    86
    new_params['sidebar_grouping'] = 'Organizations'
1182
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
    87
1813
5cc9e055a818 Define a key order for document and org app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1781
diff changeset
    88
    new_params['list_key_order'] = [
5cc9e055a818 Define a key order for document and org app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1781
diff changeset
    89
        'link_id', 'scope_path', 'name', 'home_page', 'email',
5cc9e055a818 Define a key order for document and org app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1781
diff changeset
    90
        'description', 'why_applying','pub_mailing_list','irc_channel',
5cc9e055a818 Define a key order for document and org app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1781
diff changeset
    91
        'member_criteria', 'prior_participation', 'prior_application',
5cc9e055a818 Define a key order for document and org app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1781
diff changeset
    92
        'license_name', 'ideas', 'dev_mailing_list', 'contrib_template',
5cc9e055a818 Define a key order for document and org app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1781
diff changeset
    93
        'contrib_disappears', 'member_disappears', 'encourage_contribs',
5cc9e055a818 Define a key order for document and org app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1781
diff changeset
    94
        'continued_contribs']
5cc9e055a818 Define a key order for document and org app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1781
diff changeset
    95
1225
1d5c58e24fd3 Org applications can now only be made by a user when a program allows it.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1205
diff changeset
    96
    patterns = [(r'^%(url_name)s/(?P<access_type>apply)/%(scope)s$',
1d5c58e24fd3 Org applications can now only be made by a user when a program allows it.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1205
diff changeset
    97
        'soc.views.models.%(module_name)s.create',
1294
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
    98
        'Create an %(name_plural)s'),
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
    99
        (r'^%(url_name)s/(?P<access_type>bulk_accept)/%(scope)s$',
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   100
        'soc.views.models.%(module_name)s.bulk_accept',
1537
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   101
        'Bulk Acceptation of %(name_plural)s'),
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   102
        (r'^%(url_name)s/(?P<access_type>bulk_reject)/%(scope)s$',
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   103
        'soc.views.models.%(module_name)s.bulk_reject',
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   104
        'Bulk Rejection of %(name_plural)s'),]
1225
1d5c58e24fd3 Org applications can now only be made by a user when a program allows it.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1205
diff changeset
   105
1d5c58e24fd3 Org applications can now only be made by a user when a program allows it.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1205
diff changeset
   106
    new_params['extra_django_patterns'] = patterns
1276
7f460f46a611 Initial implementation of a ToS requirement in org_app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1255
diff changeset
   107
    new_params['extra_key_order'] = ['admin_agreement',
7f460f46a611 Initial implementation of a ToS requirement in org_app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1255
diff changeset
   108
                                     'agreed_to_admin_agreement']
1225
1d5c58e24fd3 Org applications can now only be made by a user when a program allows it.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1205
diff changeset
   109
1182
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
   110
    new_params['extra_dynaexclude'] = ['applicant', 'backup_admin', 'status',
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
   111
        'created_on', 'last_modified_on']
1205
2e88261aba72 Added validate_new_group to cleaning and removed clean_new_club_link_id.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1201
diff changeset
   112
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1349
diff changeset
   113
    new_params['create_extra_dynaproperties'] = {
1205
2e88261aba72 Added validate_new_group to cleaning and removed clean_new_club_link_id.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1201
diff changeset
   114
        'scope_path': forms.fields.CharField(widget=forms.HiddenInput,
2e88261aba72 Added validate_new_group to cleaning and removed clean_new_club_link_id.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1201
diff changeset
   115
                                             required=True),
1566
5388270fb363 contrib template in org_app is now a TextProperty.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1559
diff changeset
   116
        'contrib_template': forms.fields.CharField(
5388270fb363 contrib template in org_app is now a TextProperty.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1559
diff changeset
   117
            widget=helper.widgets.FullTinyMCE(
5388270fb363 contrib template in org_app is now a TextProperty.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1559
diff changeset
   118
                attrs={'rows': 25, 'cols': 100})),
1781
f8e85447fbdf Add TinyMCE widget for org apps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1777
diff changeset
   119
        'description': forms.fields.CharField(
f8e85447fbdf Add TinyMCE widget for org apps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1777
diff changeset
   120
            widget=helper.widgets.FullTinyMCE(
f8e85447fbdf Add TinyMCE widget for org apps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1777
diff changeset
   121
                attrs={'rows': 25, 'cols': 100})),
1276
7f460f46a611 Initial implementation of a ToS requirement in org_app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1255
diff changeset
   122
        'admin_agreement': forms.fields.Field(required=False,
7f460f46a611 Initial implementation of a ToS requirement in org_app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1255
diff changeset
   123
            widget=widgets.AgreementField),
7f460f46a611 Initial implementation of a ToS requirement in org_app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1255
diff changeset
   124
        'agreed_to_admin_agreement': forms.fields.BooleanField(
7f460f46a611 Initial implementation of a ToS requirement in org_app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1255
diff changeset
   125
            initial=False, required=True),
1781
f8e85447fbdf Add TinyMCE widget for org apps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1777
diff changeset
   126
f8e85447fbdf Add TinyMCE widget for org apps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1777
diff changeset
   127
        'clean_description': cleaning.clean_html_content('description'),
f8e85447fbdf Add TinyMCE widget for org apps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1777
diff changeset
   128
        'clean_contrib_template': cleaning.clean_html_content('contrib_template'),
1230
b1b1897e4df1 Cleanup in org_app and replace ReferenceProperty with LinkProperty
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1225
diff changeset
   129
        'clean_ideas': cleaning.clean_url('ideas'),
1205
2e88261aba72 Added validate_new_group to cleaning and removed clean_new_club_link_id.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1201
diff changeset
   130
        'clean': cleaning.validate_new_group('link_id', 'scope_path',
2e88261aba72 Added validate_new_group to cleaning and removed clean_new_club_link_id.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1201
diff changeset
   131
            model_logic.organization, org_app_logic)}
2e88261aba72 Added validate_new_group to cleaning and removed clean_new_club_link_id.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1201
diff changeset
   132
2e88261aba72 Added validate_new_group to cleaning and removed clean_new_club_link_id.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1201
diff changeset
   133
    # get rid of the clean method
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1349
diff changeset
   134
    new_params['edit_extra_dynaproperties'] = {
1205
2e88261aba72 Added validate_new_group to cleaning and removed clean_new_club_link_id.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1201
diff changeset
   135
        'clean': (lambda x: x.cleaned_data)}
1182
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
   136
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
   137
    new_params['name'] = "Organization Application"
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
   138
    new_params['name_plural'] = "Organization Applications"
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
   139
    new_params['name_short'] = "Org App"
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
   140
    new_params['url_name'] = "org_app"
1533
50fb3a9b6615 Fix for Issue 218.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1506
diff changeset
   141
    new_params['group_name'] = "Organization"
1182
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
   142
    new_params['group_url_name'] = 'org'
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
   143
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
   144
    new_params['review_template'] = 'soc/org_app/review.html'
1553
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   145
    new_params['accepted_mail_template'] = 'soc/org_app/mail/accepted.html'
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   146
    new_params['rejected_mail_template'] = 'soc/org_app/mail/rejected.html'
1182
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
   147
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
   148
    params = dicts.merge(params, new_params)
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
   149
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
   150
    super(View, self).__init__(params=params)
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
   151
1294
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   152
  @ decorators.merge_params
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   153
  def reviewOverview(self, request, access_type,
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   154
               page_name=None, params=None, **kwargs):
1645
c7e05dafaede Style fixes plus removal of unused imports, add missing docstring and fix too long lines in soc.views.models.org_app module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1615
diff changeset
   155
    """View that allows to see organization application review overview.
c7e05dafaede Style fixes plus removal of unused imports, add missing docstring and fix too long lines in soc.views.models.org_app module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1615
diff changeset
   156
c7e05dafaede Style fixes plus removal of unused imports, add missing docstring and fix too long lines in soc.views.models.org_app module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1615
diff changeset
   157
       For Args see base.View.public().
c7e05dafaede Style fixes plus removal of unused imports, add missing docstring and fix too long lines in soc.views.models.org_app module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1615
diff changeset
   158
    """
1294
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   159
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   160
    params['list_template'] = 'soc/org_app/review_overview.html'
1537
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   161
    context = {
1645
c7e05dafaede Style fixes plus removal of unused imports, add missing docstring and fix too long lines in soc.views.models.org_app module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1615
diff changeset
   162
        'bulk_accept_link': '/org_app/bulk_accept/%(scope_path)s' % (kwargs),
c7e05dafaede Style fixes plus removal of unused imports, add missing docstring and fix too long lines in soc.views.models.org_app module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1615
diff changeset
   163
        'bulk_reject_link': '/org_app/bulk_reject/%(scope_path)s' % (kwargs),}
1294
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   164
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   165
    return super(View, self).reviewOverview(request, access_type,
1296
64918d0c97ea Implemented the 2nd part of bulk acceptance.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
   166
        page_name=page_name, params=params, context=context, **kwargs)
1294
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   167
1276
7f460f46a611 Initial implementation of a ToS requirement in org_app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1255
diff changeset
   168
  def _editContext(self, request, context):
7f460f46a611 Initial implementation of a ToS requirement in org_app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1255
diff changeset
   169
    """See base.View._editContext.
7f460f46a611 Initial implementation of a ToS requirement in org_app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1255
diff changeset
   170
    """
7f460f46a611 Initial implementation of a ToS requirement in org_app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1255
diff changeset
   171
7f460f46a611 Initial implementation of a ToS requirement in org_app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1255
diff changeset
   172
    entity = context['entity']
7f460f46a611 Initial implementation of a ToS requirement in org_app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1255
diff changeset
   173
    form = context['form']
7f460f46a611 Initial implementation of a ToS requirement in org_app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1255
diff changeset
   174
7f460f46a611 Initial implementation of a ToS requirement in org_app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1255
diff changeset
   175
    if 'scope_path' in form.initial:
7f460f46a611 Initial implementation of a ToS requirement in org_app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1255
diff changeset
   176
      scope_path = form.initial['scope_path']
7f460f46a611 Initial implementation of a ToS requirement in org_app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1255
diff changeset
   177
    elif 'scope_path' in request.POST:
7f460f46a611 Initial implementation of a ToS requirement in org_app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1255
diff changeset
   178
      scope_path = request.POST['scope_path']
7f460f46a611 Initial implementation of a ToS requirement in org_app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1255
diff changeset
   179
    else:
7f460f46a611 Initial implementation of a ToS requirement in org_app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1255
diff changeset
   180
      del form.fields['admin_agreement']
7f460f46a611 Initial implementation of a ToS requirement in org_app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1255
diff changeset
   181
      return
7f460f46a611 Initial implementation of a ToS requirement in org_app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1255
diff changeset
   182
7f460f46a611 Initial implementation of a ToS requirement in org_app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1255
diff changeset
   183
    entity = program_logic.logic.getFromKeyName(scope_path)
7f460f46a611 Initial implementation of a ToS requirement in org_app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1255
diff changeset
   184
1763
6bd59cad39a5 Addressed comments by Pawel
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1754
diff changeset
   185
    if not (entity and entity.org_admin_agreement):
6bd59cad39a5 Addressed comments by Pawel
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1754
diff changeset
   186
      return
1726
711c8dcab67e Add a link to the full agreement text
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1645
diff changeset
   187
1763
6bd59cad39a5 Addressed comments by Pawel
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1754
diff changeset
   188
    agreement = entity.org_admin_agreement
1276
7f460f46a611 Initial implementation of a ToS requirement in org_app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1255
diff changeset
   189
1726
711c8dcab67e Add a link to the full agreement text
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1645
diff changeset
   190
    content = agreement.content
711c8dcab67e Add a link to the full agreement text
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1645
diff changeset
   191
    params = {'url_name': 'document'}
1276
7f460f46a611 Initial implementation of a ToS requirement in org_app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1255
diff changeset
   192
1726
711c8dcab67e Add a link to the full agreement text
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1645
diff changeset
   193
    widget = form.fields['admin_agreement'].widget
711c8dcab67e Add a link to the full agreement text
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1645
diff changeset
   194
    widget.text = content
711c8dcab67e Add a link to the full agreement text
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1645
diff changeset
   195
    widget.url = redirects.getPublicRedirect(agreement, params)
1276
7f460f46a611 Initial implementation of a ToS requirement in org_app
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1255
diff changeset
   196
1296
64918d0c97ea Implemented the 2nd part of bulk acceptance.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
   197
  def _review(self, request, params, app_entity, status, **kwargs):
1553
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   198
    """Sends out an email if an org_app has been accepted or rejected.
1296
64918d0c97ea Implemented the 2nd part of bulk acceptance.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
   199
64918d0c97ea Implemented the 2nd part of bulk acceptance.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
   200
    For params see group_app.View._review().
64918d0c97ea Implemented the 2nd part of bulk acceptance.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
   201
    """
64918d0c97ea Implemented the 2nd part of bulk acceptance.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
   202
1553
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   203
    if status == 'accepted' or status == 'rejected':
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   204
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   205
      default_sender = mail_dispatcher.getDefaultMailSender()
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   206
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   207
      if not default_sender:
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   208
        # no default sender abort
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   209
        return
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   210
      else:
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   211
        (sender_name, sender) = default_sender
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   212
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   213
      # construct the contents of the email
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   214
      user_entity = app_entity.applicant
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   215
      to = accounts.denormalizeAccount(user_entity.account).email()
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   216
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   217
      context = {'sender': sender,
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   218
              'to': to,
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   219
              'sender_name': sender_name,
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   220
              'to_name': user_entity.name,
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   221
              'program_name': app_entity.scope.name}
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   222
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   223
      if status == 'accepted':
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   224
        # use the accepted template and subject
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   225
        template = params['accepted_mail_template']
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   226
        context['subject'] = 'Congratulations!'
1754
63fa0e7f8f47 Made all links in e-mail verbatim to solve Issue 250.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1726
diff changeset
   227
        context['HTTP_host'] = 'http://%s' %(os.environ['HTTP_HOST'])
1553
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   228
      elif status == 'rejected':
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   229
        # use the rejected template and subject
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   230
        template = params['rejected_mail_template']
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   231
        context['subject'] = 'Thank you for your application'
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   232
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   233
      # send out the constructed email
451c804c6aab Added sending of an email upon Organization Application acceptance or rejection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1537
diff changeset
   234
      mail_dispatcher.sendMailFromTemplate(template, context)
1296
64918d0c97ea Implemented the 2nd part of bulk acceptance.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
   235
1294
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   236
  @decorators.merge_params
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   237
  @decorators.check_access
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   238
  def bulkAccept(self, request, access_type,
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   239
               page_name=None, params=None, **kwargs):
1537
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   240
    """Returns a HTTP Response containing JSON information needed
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   241
       to bulk-accept orgs.
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   242
    """
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   243
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   244
    program_keyname = kwargs['scope_path']
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   245
    return self._bulkReview(request, params, 'pre-accepted', 'accepted',
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   246
        program_keyname)
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   247
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   248
  @decorators.merge_params
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   249
  @decorators.check_access
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   250
  def bulkReject(self, request, access_type,
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   251
               page_name=None, params=None, **kwargs):
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   252
    """Returns a HTTP Response containing JSON information needed
1294
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   253
       to bulk-accept orgs.
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   254
    """
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   255
1537
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   256
    program_keyname = kwargs['scope_path']
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   257
    return self._bulkReview(request, params, 'pre-rejected', 'rejected',
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   258
                            program_keyname)
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   259
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   260
  def _bulkReview(self, request, params, from_status, to_status,
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   261
                  program_keyname):
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   262
    """Returns a HTTP Response containing JSON information needed
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   263
       to bulk-review organization applications.
1294
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   264
1537
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   265
       Args:
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   266
         request: Standard Django HTTP Request object
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   267
         params: Params for this view
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   268
         from_status: The status for the applications which should
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   269
                      be reviewed (can be a list)
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   270
         to_status: The status to which all applications should be changed to
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   271
         program_keyname: The keyname for the program to which
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   272
                          the application belongs
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   273
    """
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   274
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   275
    # get the program entity from the keyname
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   276
    program_entity = program_logic.logic.getFromKeyName(program_keyname)
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   277
1645
c7e05dafaede Style fixes plus removal of unused imports, add missing docstring and fix too long lines in soc.views.models.org_app module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1615
diff changeset
   278
    # get all the organization applications for the 
c7e05dafaede Style fixes plus removal of unused imports, add missing docstring and fix too long lines in soc.views.models.org_app module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1615
diff changeset
   279
    # given program and from_status
1537
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   280
    filter = {'scope': program_entity,
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   281
              'status': from_status}
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   282
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   283
    org_app_entities = params['logic'].getForFields(filter=filter)
1294
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   284
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   285
    # convert each application into a dictionary containing only the fields
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   286
    # given by the dict_filter
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   287
    dict_filter = ['link_id', 'name']
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   288
    org_apps = [dicts.filter(i.toDict(), dict_filter) for i in org_app_entities]
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   289
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   290
    to_json = {
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   291
        'program' : program_entity.name,
1297
033fa805b361 Added number of applications and their type to the bulkaccept JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1296
diff changeset
   292
        'nr_applications' : len(org_apps),
033fa805b361 Added number of applications and their type to the bulkaccept JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1296
diff changeset
   293
        'application_type' : params['name_plural'],
1294
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   294
        'applications': org_apps,
1537
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   295
        'link' : '/%s/review/%s/(link_id)?status=%s' %(
fb89938aa078 Added bulk reject to org_app view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1533
diff changeset
   296
            params['url_name'] ,program_entity.key().name(), to_status),
1294
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   297
        }
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   298
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   299
    json = simplejson.dumps(to_json)
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   300
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   301
    # use the standard JSON template to return our response
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   302
    context = {'json': json}
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   303
    template = 'soc/json.html'
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   304
1506
b908d671624e Solved the JSON caching problem for bulk acceptance.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   305
    return responses.respond(request, template, context)
1294
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   306
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1276
diff changeset
   307
1182
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
   308
view = View()
5bea281505f4 Fixed EOL damage in org_app and access checks
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1151
diff changeset
   309
1584
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1566
diff changeset
   310
admin = decorators.view(view.admin)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1566
diff changeset
   311
bulk_accept = decorators.view(view.bulkAccept)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1566
diff changeset
   312
bulk_reject = decorators.view(view.bulkReject)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1566
diff changeset
   313
create = decorators.view(view.create)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1566
diff changeset
   314
delete = decorators.view(view.delete)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1566
diff changeset
   315
edit = decorators.view(view.edit)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1566
diff changeset
   316
list = decorators.view(view.list)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1566
diff changeset
   317
list_self = decorators.view(view.listSelf)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1566
diff changeset
   318
public = decorators.view(view.public)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1566
diff changeset
   319
export = decorators.view(view.export)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1566
diff changeset
   320
review = decorators.view(view.review)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1566
diff changeset
   321
review_overview = decorators.view(view.reviewOverview)