app/soc/views/models/student_proposal.py
changeset 1882 72b42ffee2a1
parent 1853 6cd70644892d
child 1883 ce564c03d90a
--- 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'])