app/soc/views/models/club.py
changeset 878 fdfab50cc9df
parent 877 b2575da44c36
child 882 267e31f1a0b6
equal deleted inserted replaced
877:b2575da44c36 878:fdfab50cc9df
    32 from soc.logic.models import user as user_logic
    32 from soc.logic.models import user as user_logic
    33 from soc.logic.models import group_app as group_app_logic
    33 from soc.logic.models import group_app as group_app_logic
    34 from soc.logic.models import club as club_logic
    34 from soc.logic.models import club as club_logic
    35 from soc.views import out_of_band
    35 from soc.views import out_of_band
    36 from soc.views.helper import access
    36 from soc.views.helper import access
       
    37 from soc.views.helper import decorators
    37 from soc.views.helper import dynaform
    38 from soc.views.helper import dynaform
    38 from soc.views.helper import widgets
    39 from soc.views.helper import widgets
    39 from soc.views.helper import responses
    40 from soc.views.helper import responses
    40 from soc.views.models import base
    41 from soc.views.models import base
    41 
    42 
    92         dynaform = self._params['create_form'],
    93         dynaform = self._params['create_form'],
    93         dynafields = updated_fields)
    94         dynafields = updated_fields)
    94 
    95 
    95     params['applicant_create_form'] = applicant_create_form
    96     params['applicant_create_form'] = applicant_create_form
    96 
    97 
    97 
    98   @decorators.merge_params
       
    99   @decorators.check_access
    98   def applicant(self, request, access_type,
   100   def applicant(self, request, access_type,
    99                   page_name=None, params=None, **kwargs):
   101                   page_name=None, params=None, **kwargs):
   100     """Handles the creation of a club via an approved club application.
   102     """Handles the creation of a club via an approved club application.
   101 
   103 
   102     Args:
   104     Args:
   104       page_name: the page name displayed in templates as page and header title
   106       page_name: the page name displayed in templates as page and header title
   105       params: a dict with params for this View
   107       params: a dict with params for this View
   106       kwargs: the Key Fields for the specified entity
   108       kwargs: the Key Fields for the specified entity
   107     """
   109     """
   108 
   110 
   109 
       
   110     # merge the params
       
   111     params = dicts.merge(params, self._params)
       
   112 
       
   113     # check if the current user has access to this page
       
   114     try:
       
   115       access.checkAccess(access_type, request, rights=params['rights'])
       
   116     except out_of_band.Error, error:
       
   117       return responses.errorResponse(error, request)
       
   118 
       
   119     # get the context for this webpage
   111     # get the context for this webpage
   120     context = responses.getUniversalContext(request)
   112     context = responses.getUniversalContext(request)
   121     context['page_name'] = page_name
   113     context['page_name'] = page_name
   122 
       
   123 
   114 
   124     if request.method == 'POST':
   115     if request.method == 'POST':
   125       return self.applicantPost(request, context, params, **kwargs)
   116       return self.applicantPost(request, context, params, **kwargs)
   126     else:
   117     else:
   127       # request.method == 'GET'
   118       # request.method == 'GET'
   128       return self.applicantGet(request, context, params, **kwargs)
   119       return self.applicantGet(request, context, params, **kwargs)
   129 
   120 
   130 
       
   131   def applicantGet(self, request, context, params, **kwargs):
   121   def applicantGet(self, request, context, params, **kwargs):
   132     """Handles the GET request concerning the creation of a club via an
   122     """Handles the GET request concerning the creation of a club via an
   133     approved club application.
   123     approved club application.
   134 
   124 
   135     Args:
   125     Args:
   151     form = params['applicant_create_form'](initial=fields)
   141     form = params['applicant_create_form'](initial=fields)
   152 
   142 
   153     # construct the appropriate response
   143     # construct the appropriate response
   154     return super(View, self)._constructResponse(request, entity=None,
   144     return super(View, self)._constructResponse(request, entity=None,
   155         context=context, form=form, params=params)
   145         context=context, form=form, params=params)
   156 
       
   157 
   146 
   158   def applicantPost(self, request, context, params, **kwargs):
   147   def applicantPost(self, request, context, params, **kwargs):
   159     """Handles the POST request concerning the creation of a club via an
   148     """Handles the POST request concerning the creation of a club via an
   160     approved club application.
   149     approved club application.
   161 
   150 
   190     entity = self._logic.updateOrCreateFromKeyName(fields, key_name)
   179     entity = self._logic.updateOrCreateFromKeyName(fields, key_name)
   191 
   180 
   192     # redirect to notifications list to see the admin invite
   181     # redirect to notifications list to see the admin invite
   193     return http.HttpResponseRedirect('/notification/list')
   182     return http.HttpResponseRedirect('/notification/list')
   194 
   183 
   195 
       
   196   def _editGet(self, request, entity, form):
   184   def _editGet(self, request, entity, form):
   197     """See base.View._editGet().
   185     """See base.View._editGet().
   198     """
   186     """
   199 
   187 
   200     # fill in the founded_by with data from the entity
   188     # fill in the founded_by with data from the entity
   201     form.fields['founded_by'].initial = entity.founder.name
   189     form.fields['founded_by'].initial = entity.founder.name
   202     super(View, self)._editGet(request, entity, form)
   190     super(View, self)._editGet(request, entity, form)
   203 
       
   204 
   191 
   205   def _editPost(self, request, entity, fields):
   192   def _editPost(self, request, entity, fields):
   206     """See base.View._editPost().
   193     """See base.View._editPost().
   207     """
   194     """
   208 
   195