app/soc/views/models/club_app.py
changeset 818 ddd102e82107
parent 803 9d0ed410bfd5
child 821 5afe16b2e86b
equal deleted inserted replaced
817:98996e11b604 818:ddd102e82107
    48     """Defines the fields and methods required for the base View class
    48     """Defines the fields and methods required for the base View class
    49     to provide the user with list, public, create, edit and delete views.
    49     to provide the user with list, public, create, edit and delete views.
    50 
    50 
    51     Params:
    51     Params:
    52       params: a dict with params for this View
    52       params: a dict with params for this View
    53     """    
    53     """
    54 
    54 
    55     rights = {}
    55     rights = {}
    56     rights['create'] = [access.checkIsUser]
    56     rights['create'] = [access.checkIsUser]
    57     rights['delete'] = [access.checkIsMyApplication]
    57     rights['delete'] = [access.checkIsMyApplication]
    58     rights['edit'] = [access.checkIsMyApplication]
    58     rights['edit'] = [access.checkIsMyApplication]
    73         'backup_admin_link_id': forms.CharField(
    73         'backup_admin_link_id': forms.CharField(
    74               label=group_app_model.GroupApplication.backup_admin.verbose_name
    74               label=group_app_model.GroupApplication.backup_admin.verbose_name
    75               ),
    75               ),
    76         'clean_backup_admin_link_id': cleaning.clean_existing_user('backup_admin_link_id'),
    76         'clean_backup_admin_link_id': cleaning.clean_existing_user('backup_admin_link_id'),
    77         }
    77         }
    78     
    78 
    79     patterns = [(r'^%(url_name)s/(?P<access_type>review)$',
    79     patterns = [(r'^%(url_name)s/(?P<access_type>review)$',
    80         'soc.views.models.%(module_name)s.showReviewOverview',
    80         'soc.views.models.%(module_name)s.showReviewOverview',
    81         'Review %(name_plural)s'),
    81         'Review %(name_plural)s'),
    82         (r'^%(url_name)s/(?P<access_type>review)/%(lnp)s$',
    82         (r'^%(url_name)s/(?P<access_type>review)/%(lnp)s$',
    83           'soc.views.models.%(module_name)s.review',
    83           'soc.views.models.%(module_name)s.review',
    84           'Review %(name_short)s')]
    84           'Review %(name_short)s')]
    85     
    85 
    86     new_params['extra_django_patterns'] = patterns
    86     new_params['extra_django_patterns'] = patterns
    87     
    87 
    88     new_params['name'] = "Club Application"
    88     new_params['name'] = "Club Application"
    89     new_params['name_plural'] = "Club Applications"
    89     new_params['name_plural'] = "Club Applications"
    90     new_params['name_short'] = "Club App"
    90     new_params['name_short'] = "Club App"
    91     new_params['url_name'] = "club_app"
    91     new_params['url_name'] = "club_app"
    92 
    92 
    93     new_params['sidebar_additional'] = [
    93     new_params['sidebar_additional'] = [
    94         ('/%(url_name)s/review' % new_params,
    94         ('/%(url_name)s/review' % new_params,
    95          'Review %(name_plural)s' % new_params, 'review')]
    95          'Review %(name_plural)s' % new_params, 'review')]
    96     
    96 
    97     new_params['review_template'] = 'soc/club_app/review.html'
    97     new_params['review_template'] = 'soc/club_app/review.html'
    98 
    98 
    99     params = dicts.merge(params, new_params)
    99     params = dicts.merge(params, new_params)
   100 
   100 
   101     super(View, self).__init__(params=params)
   101     super(View, self).__init__(params=params)
   144 
   144 
   145     fields['backup_admin'] = fields['backup_admin_link_id']
   145     fields['backup_admin'] = fields['backup_admin_link_id']
   146 
   146 
   147     if not entity:
   147     if not entity:
   148       fields['applicant'] = user_logic.logic.getForCurrentAccount()
   148       fields['applicant'] = user_logic.logic.getForCurrentAccount()
   149       
   149 
   150     # the application has either been created or edited so
   150     # the application has either been created or edited so
   151     # the review status needs to be set accordingly
   151     # the review status needs to be set accordingly
   152     fields['reviewed'] = False
   152     fields['reviewed'] = False
   153     fields['accepted'] = False
   153     fields['accepted'] = False
   154       
   154 
   155   def _public(self, request, entity, context):
   155   def _public(self, request, entity, context):
   156     """See base._public().
   156     """See base._public().
   157     """
   157     """
   158     
   158 
   159     context['entity_type_url'] = self._params['url_name']
   159     context['entity_type_url'] = self._params['url_name']
   160 
       
   161 
   160 
   162   def review(self, request, access_type,
   161   def review(self, request, access_type,
   163              page_name=None, params=None, **kwargs):
   162              page_name=None, params=None, **kwargs):
   164     """Handles the view containing the review of an application.
   163     """Handles the view containing the review of an application.
   165     
   164 
   166     accepted (true or false) in the GET data will mark 
   165     accepted (true or false) in the GET data will mark
   167     the application accordingly. 
   166     the application accordingly.
   168     
   167 
   169     
   168 
   170     For params see base.View.public().
   169     For params see base.View.public().
   171     """
   170     """
   172     
   171 
   173     params = dicts.merge(params, self._params)
   172     params = dicts.merge(params, self._params)
   174     
   173 
   175     try:
   174     try:
   176       access.checkAccess(access_type, request, rights=params['rights'])
   175       access.checkAccess(access_type, request, rights=params['rights'])
   177     except out_of_band.Error, error:
   176     except out_of_band.Error, error:
   178       return helper.responses.errorResponse(error, request)
   177       return helper.responses.errorResponse(error, request)
   179     
   178 
   180     # create default template context for use with any templates
   179     # create default template context for use with any templates
   181     context = helper.responses.getUniversalContext(request)
   180     context = helper.responses.getUniversalContext(request)
   182     context['page_name'] = page_name
   181     context['page_name'] = page_name
   183     entity = None
   182     entity = None
   184 
   183 
   186       key_fields = self._logic.getKeyFieldsFromDict(kwargs)
   185       key_fields = self._logic.getKeyFieldsFromDict(kwargs)
   187       entity = self._logic.getIfFields(key_fields)
   186       entity = self._logic.getIfFields(key_fields)
   188     except out_of_band.Error, error:
   187     except out_of_band.Error, error:
   189       return helper.responses.errorResponse(
   188       return helper.responses.errorResponse(
   190           error, request, template=params['error_public'], context=context)
   189           error, request, template=params['error_public'], context=context)
   191     
   190 
   192     get_dict = request.GET
   191     get_dict = request.GET
   193     
   192 
   194     # check to see if we can make a decision for this application
   193     # check to see if we can make a decision for this application
   195     if 'accepted' in get_dict.keys():
   194     if 'accepted' in get_dict.keys():
   196       accepted_value = get_dict['accepted']
   195       accepted_value = get_dict['accepted']
   197       
   196 
   198       fields = {'reviewed' : False}
   197       fields = {'reviewed' : False}
   199       
   198 
   200       if accepted_value == 'true':
   199       if accepted_value == 'true':
   201         # the application has been accepted
   200         # the application has been accepted
   202         fields['accepted'] = True
   201         fields['accepted'] = True
   203         fields['reviewed'] = True
   202         fields['reviewed'] = True
   204       elif accepted_value == 'false':
   203       elif accepted_value == 'false':
   205         # the application has been denied
   204         # the application has been denied
   206         fields['accepted'] = False
   205         fields['accepted'] = False
   207         fields['reviewed'] = True
   206         fields['reviewed'] = True
   208       
   207 
   209       if fields['reviewed']: 
   208       if fields['reviewed']:
   210         # the application has either been denied or accepted
   209         # the application has either been denied or accepted
   211         # mark it as reviewed and update accordingly
   210         # mark it as reviewed and update accordingly
   212         application = self._logic.getFromFields(link_id=kwargs['link_id'])
   211         application = self._logic.getFromFields(link_id=kwargs['link_id'])
   213         self._logic.updateModelProperties(application, fields)
   212         self._logic.updateModelProperties(application, fields)
   214         
   213 
   215         return self.showReviewOverview(request, access_type, 
   214         return self.showReviewOverview(request, access_type,
   216             page_name=page_name, params=params, **kwargs)
   215             page_name=page_name, params=params, **kwargs)
   217 
   216 
   218     # the application has nog been reviewed so show the information
   217     # the application has not been reviewed so show the information
   219     # using the appropriate review template
   218     # using the appropriate review template
   220     params['public_template'] = params['review_template']
   219     params['public_template'] = params['review_template']
   221 
   220 
   222     return super(View, self).public(request, access_type,
   221     return super(View, self).public(request, access_type,
   223         page_name=page_name, params=params, **kwargs)
   222         page_name=page_name, params=params, **kwargs)
   241 
   240 
   242     ur_list = helper.lists.getListContent(
   241     ur_list = helper.lists.getListContent(
   243         request, ur_params, filter, 0)
   242         request, ur_params, filter, 0)
   244 
   243 
   245     # only select the requests that haven't been turned into a group yet
   244     # only select the requests that haven't been turned into a group yet
   246     filter = {'accepted' : True, 
   245     filter = {'accepted' : True,
   247         'application_completed' : False}
   246         'application_completed' : False}
   248 
   247 
   249     uh_params = params.copy()
   248     uh_params = params.copy()
   250     uh_params['list_description'] = ugettext_lazy('A list of all applications '
   249     uh_params['list_description'] = ugettext_lazy('A list of all applications '
   251         'that have been accepted but not turned into a Club yet')
   250         'that have been accepted but not turned into a Club yet')
   255         request, uh_params, filter, 0)
   254         request, uh_params, filter, 0)
   256 
   255 
   257     #only select the requests the have been denied
   256     #only select the requests the have been denied
   258     filter = {'reviewed' : True,
   257     filter = {'reviewed' : True,
   259         'accepted' : False}
   258         'accepted' : False}
   260     
   259 
   261     den_params = params.copy()
   260     den_params = params.copy()
   262     den_params['list_description'] = ugettext_lazy('A list of all applications '
   261     den_params['list_description'] = ugettext_lazy('A list of all applications '
   263         'that have been denied')
   262         'that have been denied')
   264     den_params ['list_action'] = (redirects.getReviewRedirect, params)
   263     den_params ['list_action'] = (redirects.getReviewRedirect, params)
   265     
   264 
   266     den_list = helper.lists.getListContent(
   265     den_list = helper.lists.getListContent(
   267         request, den_params, filter, 0)
   266         request, den_params, filter, 0)
   268     
   267 
   269     # fill contents with all the needed lists
   268     # fill contents with all the needed lists
   270     contents = [ur_list, uh_list, den_list]
   269     contents = [ur_list, uh_list, den_list]
   271     
   270 
   272     # call the _list method from base to display the list
   271     # call the _list method from base to display the list
   273     return self._list(request, params, contents, page_name)
   272     return self._list(request, params, contents, page_name)
   274 
   273 
   275 view = View()
   274 view = View()
   276 
   275