Use getOrCreateTaskSubscriptionForTask in the TaskSubscription View.
authorLennard de Rijk <ljvderijk@gmail.com>
Fri, 18 Sep 2009 18:55:57 +0200
changeset 2953 3c024d61290c
parent 2952 c063bb466376
child 2954 9ea3b04d929c
Use getOrCreateTaskSubscriptionForTask in the TaskSubscription View.
app/soc/modules/ghop/views/models/task_subscription.py
--- a/app/soc/modules/ghop/views/models/task_subscription.py	Fri Sep 18 18:53:14 2009 +0200
+++ b/app/soc/modules/ghop/views/models/task_subscription.py	Fri Sep 18 18:55:57 2009 +0200
@@ -95,23 +95,17 @@
 
     user_account = user_logic.logic.getForCurrentAccount()
 
-    fields = {
-        'task': task_entity,
-        }
-
-    entity = ghop_task_subscription_logic.logic.getForFields(
-        fields, unique=True)
+    entity = params['logic'].getOrCreateTaskSubscriptionForTask(task_entity)
 
     subscribers = db.get(entity.subscribers)
 
     # TODO: this should not loop over all subscribers but use GET argument
     remove = False
 
-    if entity:
-      for subscriber in subscribers:
-        if subscriber.key() == user_account.key():
-          remove = True
-          break 
+    for subscriber in subscribers:
+      if subscriber.key() == user_account.key():
+        remove = True
+        break
 
     if remove:
       subscribers.remove(subscriber)