app/soc/views/models/org_app.py
changeset 1276 7f460f46a611
parent 1255 9fe8c6c54933
child 1294 359987b7027d
equal deleted inserted replaced
1275:75332102f83b 1276:7f460f46a611
    25 from django import forms
    25 from django import forms
    26 
    26 
    27 from soc.logic import cleaning
    27 from soc.logic import cleaning
    28 from soc.logic import dicts
    28 from soc.logic import dicts
    29 from soc.logic import models as model_logic
    29 from soc.logic import models as model_logic
       
    30 from soc.logic.models import program as program_logic
    30 from soc.logic.models import org_app as org_app_logic
    31 from soc.logic.models import org_app as org_app_logic
    31 from soc.views.helper import access
    32 from soc.views.helper import access
    32 from soc.views.helper import decorators
    33 from soc.views.helper import decorators
    33 from soc.views.helper import redirects
    34 from soc.views.helper import redirects
       
    35 from soc.views.helper import widgets
    34 from soc.views.models import group_app
    36 from soc.views.models import group_app
    35 from soc.views.models import program as program_view
    37 from soc.views.models import program as program_view
    36 
    38 
    37 import soc.logic.dicts
    39 import soc.logic.dicts
    38 
    40 
    80     patterns = [(r'^%(url_name)s/(?P<access_type>apply)/%(scope)s$',
    82     patterns = [(r'^%(url_name)s/(?P<access_type>apply)/%(scope)s$',
    81         'soc.views.models.%(module_name)s.create',
    83         'soc.views.models.%(module_name)s.create',
    82         'Create an %(name_plural)s'),]
    84         'Create an %(name_plural)s'),]
    83 
    85 
    84     new_params['extra_django_patterns'] = patterns
    86     new_params['extra_django_patterns'] = patterns
       
    87     new_params['extra_key_order'] = ['admin_agreement',
       
    88                                      'agreed_to_admin_agreement']
    85 
    89 
    86     new_params['extra_dynaexclude'] = ['applicant', 'backup_admin', 'status',
    90     new_params['extra_dynaexclude'] = ['applicant', 'backup_admin', 'status',
    87         'created_on', 'last_modified_on']
    91         'created_on', 'last_modified_on']
    88 
    92 
    89     new_params['create_extra_dynafields'] = {
    93     new_params['create_extra_dynafields'] = {
    90         'scope_path': forms.fields.CharField(widget=forms.HiddenInput,
    94         'scope_path': forms.fields.CharField(widget=forms.HiddenInput,
    91                                              required=True),
    95                                              required=True),
       
    96         'admin_agreement': forms.fields.Field(required=False,
       
    97             widget=widgets.AgreementField),
       
    98         'agreed_to_admin_agreement': forms.fields.BooleanField(
       
    99             initial=False, required=True),
    92         'clean_ideas': cleaning.clean_url('ideas'),
   100         'clean_ideas': cleaning.clean_url('ideas'),
    93         'clean_contrib_template': cleaning.clean_url('contrib_template'),
   101         'clean_contrib_template': cleaning.clean_url('contrib_template'),
    94         'clean': cleaning.validate_new_group('link_id', 'scope_path',
   102         'clean': cleaning.validate_new_group('link_id', 'scope_path',
    95             model_logic.organization, org_app_logic)}
   103             model_logic.organization, org_app_logic)}
    96 
   104 
   108 
   116 
   109     params = dicts.merge(params, new_params)
   117     params = dicts.merge(params, new_params)
   110 
   118 
   111     super(View, self).__init__(params=params)
   119     super(View, self).__init__(params=params)
   112 
   120 
       
   121   def _editContext(self, request, context):
       
   122     """See base.View._editContext.
       
   123     """
       
   124 
       
   125     entity = context['entity']
       
   126     form = context['form']
       
   127 
       
   128     if 'scope_path' in form.initial:
       
   129       scope_path = form.initial['scope_path']
       
   130     elif 'scope_path' in request.POST:
       
   131       # TODO: do this nicely
       
   132       scope_path = request.POST['scope_path']
       
   133     else:
       
   134       # TODO: is this always sufficient?
       
   135       del form.fields['admin_agreement']
       
   136       return
       
   137 
       
   138     entity = program_logic.logic.getFromKeyName(scope_path)
       
   139 
       
   140     if not entity or not entity.org_admin_agreement:
       
   141       return
       
   142 
       
   143     content = entity.org_admin_agreement.content
       
   144 
       
   145     form.fields['admin_agreement'].widget.text = content
       
   146 
   113 
   147 
   114 view = View()
   148 view = View()
   115 
   149 
   116 create = view.create
   150 create = view.create
   117 delete = view.delete
   151 delete = view.delete