app/soc/views/models/student_proposal.py
changeset 2051 cecbef1289a5
parent 2041 9a9307b22312
child 2076 1cd180cc56c9
equal deleted inserted replaced
2050:b3b235acdc6e 2051:cecbef1289a5
   761       # set the mentor field to the current mentor
   761       # set the mentor field to the current mentor
   762       initial['mentor'] = entity.mentor.link_id
   762       initial['mentor'] = entity.mentor.link_id
   763 
   763 
   764     context['form'] = form(initial)
   764     context['form'] = form(initial)
   765 
   765 
       
   766     # create the special form for mentors
       
   767     comment_public = ['public', 'comment']
       
   768     comment_private = ['score']
       
   769     comment_admin = ['rank', 'mentor']
       
   770     class FilterForm(object):
       
   771       def __init__(self, form, fields):
       
   772         self.__form = form
       
   773         self.__fields = fields
       
   774 
       
   775       @property
       
   776       def fields(self):
       
   777         return dict([(k,i) for k, i in self.__form.fields.iteritems() if k in self.__fields])
       
   778 
       
   779       def __iter__(self):
       
   780         for x in self.__form:
       
   781           if x.name not in self.__fields:
       
   782             continue
       
   783           yield x
       
   784 
       
   785       _marker = []
       
   786       def __getattr__(self, key, default=_marker):
       
   787         if default is self._marker:
       
   788           return getattr(self.__form, key)
       
   789         else:
       
   790           return getattr(self.__form, key, default)
       
   791 
       
   792     context['form'] = form(initial)
       
   793     context['comment_public'] = FilterForm(context['form'], comment_public)
       
   794     context['comment_private'] = FilterForm(context['form'], comment_private)
       
   795     context['comment_admin'] = FilterForm(context['form'], comment_admin)
       
   796 
   766     # get all the extra information that should be in the context
   797     # get all the extra information that should be in the context
   767     review_context = self._getDefaultReviewContext(entity, org_admin, mentor)
   798     review_context = self._getDefaultReviewContext(entity, org_admin, mentor)
   768     context = dicts.merge(context, review_context)
   799     context = dicts.merge(context, review_context)
   769 
   800 
   770     template = params['review_template']
   801     template = params['review_template']