app/soc/views/models/student_proposal.py
changeset 1894 da52a47b5a6b
parent 1890 a8a5da24212c
child 1895 564b066c313c
equal deleted inserted replaced
1893:bcb73072aa66 1894:da52a47b5a6b
   890     # update the proposal
   890     # update the proposal
   891     properties = {'mentor': mentor_entity}
   891     properties = {'mentor': mentor_entity}
   892     self._logic.updateEntityProperties(entity, properties)
   892     self._logic.updateEntityProperties(entity, properties)
   893 
   893 
   894   def _createReviewFor(self, entity, reviewer, comment, score=0, is_public=True):
   894   def _createReviewFor(self, entity, reviewer, comment, score=0, is_public=True):
   895     """Creates a review for the given proposal.
   895     """Creates a review for the given proposal and sends out a message to all followers.
   896 
   896 
   897     Args:
   897     Args:
   898       entity: Student Proposal entity for which the review should be created
   898       entity: Student Proposal entity for which the review should be created
   899       reviewer: A role entity of the reviewer (if possible, else None)
   899       reviewer: A role entity of the reviewer (if possible, else None)
   900       comment: The textual contents of the review
   900       comment: The textual contents of the review
   901       score: The score of the review (only used if the review is not public)
   901       score: The score of the review (only used if the review is not public)
   902       is_public: Determines if the review is a public review
   902       is_public: Determines if the review is a public review
   903 
       
   904     Returns:
       
   905       - The newly created review
       
   906     """
   903     """
   907 
   904 
   908     import time
   905     import time
   909 
   906 
       
   907     from soc.logic.helper import notifications as notifications_helper
   910     from soc.logic.models.review import logic as review_logic
   908     from soc.logic.models.review import logic as review_logic
       
   909     from soc.logic.models.review_follower import logic as review_follower_logic
   911 
   910 
   912     # create the fields for the review entity
   911     # create the fields for the review entity
   913     fields = {'link_id': 't%i' %(int(time.time()*100)),
   912     fields = {'link_id': 't%i' %(int(time.time()*100)),
   914         'scope': entity,
   913         'scope': entity,
   915         'scope_path': entity.key().name(),
   914         'scope_path': entity.key().name(),
   921 
   920 
   922     # add the given score if the review is not public
   921     # add the given score if the review is not public
   923     if not is_public:
   922     if not is_public:
   924       fields['score'] = score
   923       fields['score'] = score
   925 
   924 
       
   925     # create a new Review
   926     key_name = review_logic.getKeyNameFromFields(fields)
   926     key_name = review_logic.getKeyNameFromFields(fields)
   927 
   927     review_entity = review_logic.updateOrCreateFromKeyName(fields, key_name)
   928     return review_logic.updateOrCreateFromKeyName(fields, key_name)
   928 
       
   929     # get all followers
       
   930     fields = {'scope': entity}
       
   931 
       
   932     if is_public:
       
   933       fields['subscribed_public'] = True
       
   934     else:
       
   935       fields['subscribed_private'] = True
       
   936 
       
   937     followers = review_follower_logic.getForFields(fields)
       
   938 
       
   939     if is_public:
       
   940       # redirect to public page
       
   941       redirect_url = redirects.getPublicRedirect(entity, self._params)
       
   942     else:
       
   943       # redirect to review page
       
   944       redirect_url = redirects.getReviewRedirect(entity, self._params)
       
   945 
       
   946     for follower in followers:
       
   947       # sent to every follower except the reviewer
       
   948       #if follower.user.key() != review_entity.author.key():
       
   949         notifications_helper.sendNewReviewNotification(follower.user,
       
   950             review_entity, entity.title, redirect_url)
   929 
   951 
   930 
   952 
   931 view = View()
   953 view = View()
   932 
   954 
   933 admin = decorators.view(view.admin)
   955 admin = decorators.view(view.admin)