Added getOrCreateTaskSubscriptionForTask to TaskSubscription Logic.
authorLennard de Rijk <ljvderijk@gmail.com>
Fri, 18 Sep 2009 18:53:14 +0200
changeset 2952 c063bb466376
parent 2951 c904033c58e1
child 2953 3c024d61290c
Added getOrCreateTaskSubscriptionForTask to TaskSubscription Logic.
app/soc/modules/ghop/logic/models/task_subscription.py
--- a/app/soc/modules/ghop/logic/models/task_subscription.py	Fri Sep 18 18:40:17 2009 +0200
+++ b/app/soc/modules/ghop/logic/models/task_subscription.py	Fri Sep 18 18:53:14 2009 +0200
@@ -43,5 +43,25 @@
     super(Logic, self).__init__(model, base_model=base_model,
                                 id_based=id_based)
 
+  def getOrCreateTaskSubscriptionForTask(self, task_entity):
+    """Gets or creates a TaskSubscription entity for the given GHOPTask.
+
+    Args:
+      task_entity: GHOPTask entity
+
+    Returns:
+      Existing TaskSubscription entity iff any exists, otherwise a new
+      TaskSubscription entity.
+    """
+
+    fields = {'task': task_entity}
+
+    task_subscription = self.getForFields(fields, unique=True)
+
+    if not task_subscription:
+      task_subscription = self.updateOrCreateFromFields(fields)
+
+    return task_subscription
+
 
 logic = Logic()