# HG changeset patch # User Lennard de Rijk # Date 1237226708 0 # Node ID da52a47b5a6bb85200f42621af870baeb42f7e1c # Parent bcb73072aa66e34b950bb822aa8d9b12d88fa66c Send out a message on a new StudentProposal review to all followers. Updated docstring in notifications helper to be clearer about the method's intentions. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed diff -r bcb73072aa66 -r da52a47b5a6b app/soc/logic/helper/notifications.py --- a/app/soc/logic/helper/notifications.py Mon Mar 16 18:02:01 2009 +0000 +++ b/app/soc/logic/helper/notifications.py Mon Mar 16 18:05:08 2009 +0000 @@ -130,7 +130,7 @@ def sendNewReviewNotification(to_user, review, reviewed_name, redirect_url): - """Sends out a notification to the follower with the given redirect URL. + """Sends out a notification to alert the user of a new Review. Args: to_user: The user who should receive a notification diff -r bcb73072aa66 -r da52a47b5a6b app/soc/views/models/student_proposal.py --- a/app/soc/views/models/student_proposal.py Mon Mar 16 18:02:01 2009 +0000 +++ b/app/soc/views/models/student_proposal.py Mon Mar 16 18:05:08 2009 +0000 @@ -892,7 +892,7 @@ self._logic.updateEntityProperties(entity, properties) def _createReviewFor(self, entity, reviewer, comment, score=0, is_public=True): - """Creates a review for the given proposal. + """Creates a review for the given proposal and sends out a message to all followers. Args: entity: Student Proposal entity for which the review should be created @@ -900,14 +900,13 @@ comment: The textual contents of the review score: The score of the review (only used if the review is not public) is_public: Determines if the review is a public review - - Returns: - - The newly created review """ import time + from soc.logic.helper import notifications as notifications_helper from soc.logic.models.review import logic as review_logic + from soc.logic.models.review_follower import logic as review_follower_logic # create the fields for the review entity fields = {'link_id': 't%i' %(int(time.time()*100)), @@ -923,9 +922,32 @@ if not is_public: fields['score'] = score + # create a new Review key_name = review_logic.getKeyNameFromFields(fields) + review_entity = review_logic.updateOrCreateFromKeyName(fields, key_name) + + # get all followers + fields = {'scope': entity} + + if is_public: + fields['subscribed_public'] = True + else: + fields['subscribed_private'] = True - return review_logic.updateOrCreateFromKeyName(fields, key_name) + followers = review_follower_logic.getForFields(fields) + + if is_public: + # redirect to public page + redirect_url = redirects.getPublicRedirect(entity, self._params) + else: + # redirect to review page + redirect_url = redirects.getReviewRedirect(entity, self._params) + + for follower in followers: + # sent to every follower except the reviewer + #if follower.user.key() != review_entity.author.key(): + notifications_helper.sendNewReviewNotification(follower.user, + review_entity, entity.title, redirect_url) view = View()