app/soc/views/models/student_proposal.py
changeset 2076 1cd180cc56c9
parent 2051 cecbef1289a5
child 2091 dd3eb2770205
equal deleted inserted replaced
2075:c6bdfd560d91 2076:1cd180cc56c9
   232       {'name': 'rank',
   232       {'name': 'rank',
   233          'base': forms.IntegerField,
   233          'base': forms.IntegerField,
   234          'label': 'Set to rank',
   234          'label': 'Set to rank',
   235          'help_text':
   235          'help_text':
   236              'Set this proposal to the given rank (ignores the given score)',
   236              'Set this proposal to the given rank (ignores the given score)',
   237          'example_text': 'A rank will only be assigned if the review is private!',
   237          'example_text': 'A rank will only be assigned if the '
       
   238             'review is private!',
   238          'min_value': 1,
   239          'min_value': 1,
   239          'required': False,
   240          'required': False,
   240          'passthrough': ['min_value', 'required', 'help_text'],
   241          'passthrough': ['min_value', 'required', 'help_text'],
   241       },
   242       },
   242       {'name': 'mentor',
   243       {'name': 'mentor',
   269   def _editPost(self, request, entity, fields):
   270   def _editPost(self, request, entity, fields):
   270     """See base.View._editPost().
   271     """See base.View._editPost().
   271     """
   272     """
   272 
   273 
   273     if not entity:
   274     if not entity:
   274       fields['link_id'] = 't%i' %(int(time.time()*100))
   275       fields['link_id'] = 't%i' % (int(time.time()*100))
   275     else:
   276     else:
   276       fields['link_id'] = entity.link_id
   277       fields['link_id'] = entity.link_id
   277 
   278 
   278     # fill in the scope via call to super
   279     # fill in the scope via call to super
   279     super(View, self)._editPost(request, entity, fields)
   280     super(View, self)._editPost(request, entity, fields)
   360 
   361 
   361         if not reviewer:
   362         if not reviewer:
   362           # no org_admin found, maybe it's a mentor?
   363           # no org_admin found, maybe it's a mentor?
   363           reviewer = mentor_logic.logic.getForFields(fields, unique=True)
   364           reviewer = mentor_logic.logic.getForFields(fields, unique=True)
   364 
   365 
   365       # create the review (reviewer might be None if a Host or Developer is posting)
   366       # create the review (reviewer might be None 
       
   367       # if a Host or Developer is posting)
   366       self._createReviewFor(entity, reviewer, comment, is_public=True)
   368       self._createReviewFor(entity, reviewer, comment, is_public=True)
   367 
   369 
   368     # redirect to the same page
   370     # redirect to the same page
   369     return http.HttpResponseRedirect('')
   371     return http.HttpResponseRedirect('')
   370 
   372 
   530 
   532 
   531     from soc.views.models import organization as org_view
   533     from soc.views.models import organization as org_view
   532 
   534 
   533     student_entity = student_logic.logic.getFromKeyName(kwargs['scope_path'])
   535     student_entity = student_logic.logic.getFromKeyName(kwargs['scope_path'])
   534 
   536 
   535     filter = {'scope' : student_entity.scope,
   537     filter = {'scope': student_entity.scope,
   536               'status': 'active'}
   538               'status': 'active'}
   537 
   539 
   538     list_params = org_view.view.getParams().copy()
   540     list_params = org_view.view.getParams().copy()
   539     list_params['list_description'] = ('List of %(name_plural)s you can send '
   541     list_params['list_description'] = ('List of %(name_plural)s you can send '
   540         'your proposal to.') % list_params
   542         'your proposal to.') % list_params
   583           error, request, template=params['error_public'])
   585           error, request, template=params['error_public'])
   584 
   586 
   585     # get the context for this webpage
   587     # get the context for this webpage
   586     context = responses.getUniversalContext(request)
   588     context = responses.getUniversalContext(request)
   587     responses.useJavaScript(context, params['js_uses_all'])
   589     responses.useJavaScript(context, params['js_uses_all'])
   588     context['page_name'] = '%s "%s" from %s' %(page_name, entity.title,
   590     context['page_name'] = '%s "%s" from %s' % (page_name, entity.title,
   589                                                entity.scope.name())
   591                                                 entity.scope.name())
   590     context['entity'] = entity
   592     context['entity'] = entity
   591     context['entity_type'] = params['name']
   593     context['entity_type'] = params['name']
   592     context['entity_type_url'] = params['url_name']
   594     context['entity_type_url'] = params['url_name']
   593 
   595 
   594     # get the roles important for reviewing an application
   596     # get the roles important for reviewing an application
   648 
   650 
   649       # try to see if the rank is given and adjust the given_score if needed
   651       # try to see if the rank is given and adjust the given_score if needed
   650       rank = fields['rank']
   652       rank = fields['rank']
   651       if rank:
   653       if rank:
   652         ranker = self._logic.getRankerFor(entity)
   654         ranker = self._logic.getRankerFor(entity)
   653         # if a very high rank is filled in use the highest one that returns a score
   655         # if a very high rank is filled in use the highest 
       
   656         # one that returns a score
   654         rank = min(ranker.TotalRankedScores(), rank)
   657         rank = min(ranker.TotalRankedScores(), rank)
   655         # ranker uses zero-based ranking
   658         # ranker uses zero-based ranking
   656         score_and_rank = ranker.FindScore(rank-1)
   659         score_and_rank = ranker.FindScore(rank-1)
   657         # get the score at the requested rank
   660         # get the score at the requested rank
   658         score_at_rank = score_and_rank[0][0]
   661         score_at_rank = score_and_rank[0][0]
   766     # create the special form for mentors
   769     # create the special form for mentors
   767     comment_public = ['public', 'comment']
   770     comment_public = ['public', 'comment']
   768     comment_private = ['score']
   771     comment_private = ['score']
   769     comment_admin = ['rank', 'mentor']
   772     comment_admin = ['rank', 'mentor']
   770     class FilterForm(object):
   773     class FilterForm(object):
       
   774       """Helper class used for form filtering.
       
   775       """
   771       def __init__(self, form, fields):
   776       def __init__(self, form, fields):
   772         self.__form = form
   777         self.__form = form
   773         self.__fields = fields
   778         self.__fields = fields
   774 
   779 
   775       @property
   780       @property
   776       def fields(self):
   781       def fields(self):
   777         return dict([(k,i) for k, i in self.__form.fields.iteritems() if k in self.__fields])
   782         """Property that returns all fields as dictionary."""
       
   783         fields = self.__form.fields.iteritems()
       
   784         return dict([(k, i) for k, i in fields if k in self.__fields])
   778 
   785 
   779       def __iter__(self):
   786       def __iter__(self):
   780         for x in self.__form:
   787         for field in self.__form:
   781           if x.name not in self.__fields:
   788           if field.name not in self.__fields:
   782             continue
   789             continue
   783           yield x
   790           yield field
   784 
   791 
   785       _marker = []
   792       _marker = []
   786       def __getattr__(self, key, default=_marker):
   793       def __getattr__(self, key, default=_marker):
   787         if default is self._marker:
   794         if default is self._marker:
   788           return getattr(self.__form, key)
   795           return getattr(self.__form, key)
   931 
   938 
   932     # update the proposal
   939     # update the proposal
   933     properties = {'mentor': mentor_entity}
   940     properties = {'mentor': mentor_entity}
   934     self._logic.updateEntityProperties(entity, properties)
   941     self._logic.updateEntityProperties(entity, properties)
   935 
   942 
   936   def _createReviewFor(self, entity, reviewer, comment, score=0, is_public=True):
   943   def _createReviewFor(self, entity, reviewer, comment, 
   937     """Creates a review for the given proposal and sends out a message to all followers.
   944                        score=0, is_public=True):
       
   945     """Creates a review for the given proposal and sends 
       
   946        out a message to all followers.
   938 
   947 
   939     Args:
   948     Args:
   940       entity: Student Proposal entity for which the review should be created
   949       entity: Student Proposal entity for which the review should be created
   941       reviewer: A role entity of the reviewer (if possible, else None)
   950       reviewer: A role entity of the reviewer (if possible, else None)
   942       comment: The textual contents of the review
   951       comment: The textual contents of the review
   943       score: The score of the review (only used if the review is not public)
   952       score: The score of the review (only used if the review is not public)
   944       is_public: Determines if the review is a public review
   953       is_public: Determines if the review is a public review
   945     """
   954     """
   946 
   955 
   947     import time
       
   948 
       
   949     from soc.logic.helper import notifications as notifications_helper
   956     from soc.logic.helper import notifications as notifications_helper
   950     from soc.logic.models.review import logic as review_logic
   957     from soc.logic.models.review import logic as review_logic
   951     from soc.logic.models.review_follower import logic as review_follower_logic
   958     from soc.logic.models.review_follower import logic as review_follower_logic
   952 
   959 
   953     # create the fields for the review entity
   960     # create the fields for the review entity
   954     fields = {'link_id': 't%i' %(int(time.time()*100)),
   961     fields = {'link_id': 't%i' % (int(time.time()*100)),
   955         'scope': entity,
   962         'scope': entity,
   956         'scope_path': entity.key().name(),
   963         'scope_path': entity.key().name(),
   957         'author': user_logic.logic.getForCurrentAccount(),
   964         'author': user_logic.logic.getForCurrentAccount(),
   958         'content': comment,
   965         'content': comment,
   959         'is_public': is_public,
   966         'is_public': is_public,