app/soc/views/models/org_app.py
changeset 1294 359987b7027d
parent 1276 7f460f46a611
child 1296 64918d0c97ea
equal deleted inserted replaced
1293:d5ea34c4fc43 1294:359987b7027d
    21     '"Lennard de Rijk" <ljvderijk@gmail.com>',
    21     '"Lennard de Rijk" <ljvderijk@gmail.com>',
    22   ]
    22   ]
    23 
    23 
    24 
    24 
    25 from django import forms
    25 from django import forms
       
    26 from django.utils import simplejson
    26 
    27 
    27 from soc.logic import cleaning
    28 from soc.logic import cleaning
    28 from soc.logic import dicts
    29 from soc.logic import dicts
    29 from soc.logic import models as model_logic
    30 from soc.logic import models as model_logic
    30 from soc.logic.models import program as program_logic
    31 from soc.logic.models import program as program_logic
    31 from soc.logic.models import org_app as org_app_logic
    32 from soc.logic.models import org_app as org_app_logic
    32 from soc.views.helper import access
    33 from soc.views.helper import access
    33 from soc.views.helper import decorators
    34 from soc.views.helper import decorators
    34 from soc.views.helper import redirects
    35 from soc.views.helper import redirects
       
    36 from soc.views.helper import responses
    35 from soc.views.helper import widgets
    37 from soc.views.helper import widgets
    36 from soc.views.models import group_app
    38 from soc.views.models import group_app
    37 from soc.views.models import program as program_view
    39 from soc.views.models import program as program_view
    38 
    40 
    39 import soc.logic.dicts
    41 import soc.logic.dicts
    64     rights['public'] = [('checkCanEditGroupApp',
    66     rights['public'] = [('checkCanEditGroupApp',
    65                        [org_app_logic.logic])]
    67                        [org_app_logic.logic])]
    66     rights['review'] = ['checkIsHostForProgramInScope',
    68     rights['review'] = ['checkIsHostForProgramInScope',
    67                         ('checkCanReviewGroupApp', [org_app_logic.logic])]
    69                         ('checkCanReviewGroupApp', [org_app_logic.logic])]
    68     rights['review_overview'] = ['checkIsHostForProgramInScope']
    70     rights['review_overview'] = ['checkIsHostForProgramInScope']
       
    71     rights['bulk_accept'] = ['checkIsHostForProgramInScope']
    69     rights['apply'] = ['checkIsUser',
    72     rights['apply'] = ['checkIsUser',
    70                              ('checkCanCreateOrgApp', ['org_signup'])]
    73                              ('checkCanCreateOrgApp', ['org_signup'])]
    71 
    74 
    72     new_params = {}
    75     new_params = {}
    73 
    76 
    79 
    82 
    80     new_params['sidebar_grouping'] = 'Organizations'
    83     new_params['sidebar_grouping'] = 'Organizations'
    81 
    84 
    82     patterns = [(r'^%(url_name)s/(?P<access_type>apply)/%(scope)s$',
    85     patterns = [(r'^%(url_name)s/(?P<access_type>apply)/%(scope)s$',
    83         'soc.views.models.%(module_name)s.create',
    86         'soc.views.models.%(module_name)s.create',
    84         'Create an %(name_plural)s'),]
    87         'Create an %(name_plural)s'),
       
    88         (r'^%(url_name)s/(?P<access_type>bulk_accept)/%(scope)s$',
       
    89         'soc.views.models.%(module_name)s.bulk_accept',
       
    90         'Bulk Acceptation of %(name_plural)s'),]
    85 
    91 
    86     new_params['extra_django_patterns'] = patterns
    92     new_params['extra_django_patterns'] = patterns
    87     new_params['extra_key_order'] = ['admin_agreement',
    93     new_params['extra_key_order'] = ['admin_agreement',
    88                                      'agreed_to_admin_agreement']
    94                                      'agreed_to_admin_agreement']
    89 
    95 
   116 
   122 
   117     params = dicts.merge(params, new_params)
   123     params = dicts.merge(params, new_params)
   118 
   124 
   119     super(View, self).__init__(params=params)
   125     super(View, self).__init__(params=params)
   120 
   126 
       
   127   @ decorators.merge_params
       
   128   def reviewOverview(self, request, access_type,
       
   129                page_name=None, params=None, **kwargs):
       
   130 
       
   131     params['list_template'] = 'soc/org_app/review_overview.html'
       
   132 
       
   133     return super(View, self).reviewOverview(request, access_type,
       
   134         page_name=page_name, params=params, **kwargs)
       
   135 
   121   def _editContext(self, request, context):
   136   def _editContext(self, request, context):
   122     """See base.View._editContext.
   137     """See base.View._editContext.
   123     """
   138     """
   124 
   139 
   125     entity = context['entity']
   140     entity = context['entity']
   143     content = entity.org_admin_agreement.content
   158     content = entity.org_admin_agreement.content
   144 
   159 
   145     form.fields['admin_agreement'].widget.text = content
   160     form.fields['admin_agreement'].widget.text = content
   146 
   161 
   147 
   162 
       
   163   @decorators.merge_params
       
   164   @decorators.check_access
       
   165   def bulkAccept(self, request, access_type,
       
   166                page_name=None, params=None, **kwargs):
       
   167     """Returns a HTTP Response containing JSON information needed 
       
   168        to bulk-accept orgs.
       
   169     """
       
   170 
       
   171     program_entity = program_logic.logic.getFromKeyName(kwargs['scope_path'])
       
   172 
       
   173     # get all pre-accepted org applications for the given program
       
   174     filter = {'scope' : program_entity,
       
   175               'status' : 'pre-accepted'}
       
   176     org_app_entities = org_app_logic.logic.getForFields(filter=filter)
       
   177 
       
   178     # convert each application into a dictionary containing only the fields
       
   179     # given by the dict_filter
       
   180     dict_filter = ['link_id', 'name']
       
   181     org_apps = [dicts.filter(i.toDict(), dict_filter) for i in org_app_entities]
       
   182 
       
   183     to_json = {
       
   184         'program' : program_entity.name,
       
   185         'applications': org_apps,
       
   186         }
       
   187 
       
   188     json = simplejson.dumps(to_json)
       
   189 
       
   190     # use the standard JSON template to return our response
       
   191     context = {'json': json}
       
   192     template = 'soc/json.html'
       
   193 
       
   194     return responses.respond(request, template, context)
       
   195 
       
   196 
   148 view = View()
   197 view = View()
   149 
   198 
       
   199 bulk_accept = view.bulkAccept
   150 create = view.create
   200 create = view.create
   151 delete = view.delete
   201 delete = view.delete
   152 edit = view.edit
   202 edit = view.edit
   153 list = view.list
   203 list = view.list
   154 list_self = view.listSelf
   204 list_self = view.listSelf