# HG changeset patch # User Lennard de Rijk # Date 1237145371 0 # Node ID 72b42ffee2a1955b41842f8a52acc83a9beb34c0 # Parent a479ea5bc6431e3ccc68ac4fbc9818bdaba01737 Everyone that is able to see the StudentProposals public page can subscribe to public review updates. Note: No messages will be sent yet. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed diff -r a479ea5bc643 -r 72b42ffee2a1 app/soc/templates/soc/student_proposal/public.html --- a/app/soc/templates/soc/student_proposal/public.html Sun Mar 15 19:26:10 2009 +0000 +++ b/app/soc/templates/soc/student_proposal/public.html Sun Mar 15 19:29:31 2009 +0000 @@ -55,6 +55,17 @@ + {% if is_subscribed %} + + + + {% else %} + + + + {% endif %} diff -r a479ea5bc643 -r 72b42ffee2a1 app/soc/views/models/student_proposal.py --- a/app/soc/views/models/student_proposal.py Sun Mar 15 19:26:10 2009 +0000 +++ b/app/soc/views/models/student_proposal.py Sun Mar 15 19:29:31 2009 +0000 @@ -371,6 +371,36 @@ rest see base.View.public() """ + from soc.logic.models.review_follower import logic as review_follower_logic + + get_dict = request.GET + + if get_dict.get('subscription') and ( + get_dict['subscription'] in ['on', 'off']): + + subscription = get_dict['subscription'] + + # get the current user + user_entity = user_logic.logic.getForCurrentAccount() + + # create the fields that should be in the ReviewFollower entity + fields = {'link_id': user_entity.link_id, + 'scope': entity, + 'scope_path': entity.key().name(), + 'user': user_entity + } + # get the keyname for the ReviewFollower entity + key_name = review_follower_logic.getKeyNameFromFields(fields) + + # determine if we should set subscribed_public to True or False + if subscription == 'on': + fields['subscribed_public'] = True + elif subscription == 'off': + fields['subscribed_public'] = False + + # update the ReviewFollower + review_follower_logic.updateOrCreateFromKeyName(fields, key_name) + # get some entity specific context self.updatePublicContext(context, entity, params) @@ -389,6 +419,7 @@ """ from soc.logic.models.review import logic as review_logic + from soc.logic.models.review_follower import logic as review_follower_logic student_entity = entity.scope @@ -401,6 +432,14 @@ # show the proposal edit link context['edit_link'] = redirects.getEditRedirect(entity, params) + # check if the current user is subscribed to this proposal's public reviews + fields = {'user': user_entity, + 'scope': entity, + 'subscribed_public': True} + + context['is_subscribed'] = review_follower_logic.getForFields(fields, + unique=True) + context['public_reviews'] = review_logic.getReviewsForEntity(entity, is_public=True, order=['created'])