app/soc/views/models/student_proposal.py
changeset 1498 00293057b009
parent 1491 acf7e32de8ca
child 1569 6347d0a4fa7b
equal deleted inserted replaced
1497:1387f0d2cf45 1498:00293057b009
    24 
    24 
    25 import datetime
    25 import datetime
    26 import time
    26 import time
    27 
    27 
    28 from django import forms
    28 from django import forms
       
    29 from django import http
    29 
    30 
    30 from soc.logic import cleaning
    31 from soc.logic import cleaning
    31 from soc.logic import dicts
    32 from soc.logic import dicts
    32 from soc.logic.models import organization as org_logic
    33 from soc.logic.models import organization as org_logic
    33 from soc.logic.models import student as student_logic
    34 from soc.logic.models import student as student_logic
   120         'organization': forms.CharField(label='Organization Link ID',
   121         'organization': forms.CharField(label='Organization Link ID',
   121             widget=widgets.ReadOnlyInput),
   122             widget=widgets.ReadOnlyInput),
   122         'link_id': forms.CharField(widget=forms.HiddenInput)
   123         'link_id': forms.CharField(widget=forms.HiddenInput)
   123         }
   124         }
   124 
   125 
   125     # TODO(ljvderijk) students should be able to withdraw their proposals
   126     new_params['edit_template'] = 'soc/student_proposal/edit.html'
   126 
   127 
   127     params = dicts.merge(params, new_params)
   128     params = dicts.merge(params, new_params)
   128 
   129 
   129     super(View, self).__init__(params=params)
   130     super(View, self).__init__(params=params)
   130 
   131 
   168 
   169 
   169     if entity.mentor:
   170     if entity.mentor:
   170       context['mentor_name'] = entity.mentor.name()
   171       context['mentor_name'] = entity.mentor.name()
   171     else:
   172     else:
   172       context['mentor_name'] = "No mentor assigned"
   173       context['mentor_name'] = "No mentor assigned"
       
   174 
       
   175   @decorators.merge_params
       
   176   @decorators.check_access
       
   177   def edit(self, request, access_type,
       
   178            page_name=None, params=None, seed=None, **kwargs):
       
   179     """If the POST contains (action, Withdraw) the proposal in kwargs
       
   180        will be marked as invalid.
       
   181 
       
   182     For params see base.View.edit()
       
   183     """
       
   184 
       
   185     # check if request.POST contains action
       
   186     post_dict = request.POST
       
   187     if 'action' in post_dict and post_dict['action'] == 'Withdraw':
       
   188       # withdraw this proposal
       
   189       filter = {'scope_path': kwargs['scope_path'],
       
   190                 'link_id': kwargs['link_id']}
       
   191 
       
   192       proposal_logic = params['logic']
       
   193       student_proposal_entity = proposal_logic.getForFields(filter, unique=True)
       
   194 
       
   195       # update the entity mark it as invalid
       
   196       proposal_logic.updateEntityProperties(student_proposal_entity,
       
   197           {'status': 'invalid'})
       
   198 
       
   199       # redirect to the program's homepage
       
   200       redirect_url = redirects.getHomeRedirect(student_proposal_entity.program,
       
   201           {'url_name': 'program'})
       
   202 
       
   203       return http.HttpResponseRedirect(redirect_url)
       
   204 
       
   205     return super(View, self).edit(request=request, access_type=access_type,
       
   206            page_name=page_name, params=params, seed=seed, **kwargs)
   173 
   207 
   174   @decorators.merge_params
   208   @decorators.merge_params
   175   @decorators.check_access
   209   @decorators.check_access
   176   def listOrgs(self, request, access_type,
   210   def listOrgs(self, request, access_type,
   177                page_name=None, params=None, **kwargs):
   211                page_name=None, params=None, **kwargs):