app/soc/modules/ghop/logic/models/task_subscription.py
author Daniel Hans <Daniel.M.Hans@gmail.com>
Mon, 02 Nov 2009 23:38:43 +0100
changeset 3074 ebda36efbd61
parent 2952 c063bb466376
permissions -rw-r--r--
HtmlSanitizer becomes Python 2.6 compatible. The Cleaner class must not have any arguments when calling __init__ function for the object class, because in this case Python 2.6 raises TypeError (while previous versions just ignored them).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2819
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     2
#
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     3
# Copyright 2009 the Melange authors.
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     4
#
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     8
#
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    10
#
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    16
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    17
"""GHOPTaskSubscription (Model) query functions.
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    18
"""
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    19
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    20
__authors__ = [
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    21
    '"Madhusudan.C.S" <madhusudancs@gmail.com>'
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    22
  ]
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    23
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    24
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    25
from soc.logic.models import base
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    26
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    27
import soc.models.base
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    28
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    29
import soc.modules.ghop.models.task_subscription
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    30
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    31
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    32
class Logic(base.Logic):
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    33
  """Logic methods for the GHOPTaskSubsciption model.
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    34
  """
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    35
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    36
  def __init__(
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    37
      self,
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    38
      model=soc.modules.ghop.models.task_subscription.GHOPTaskSubscription,
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    39
      base_model=soc.models.base.ModelWithFieldAttributes, id_based=True):
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    40
    """Defines the name, key_name and model for this entity.
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    41
    """
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    42
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    43
    super(Logic, self).__init__(model, base_model=base_model,
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    44
                                id_based=id_based)
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    45
2952
c063bb466376 Added getOrCreateTaskSubscriptionForTask to TaskSubscription Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2819
diff changeset
    46
  def getOrCreateTaskSubscriptionForTask(self, task_entity):
c063bb466376 Added getOrCreateTaskSubscriptionForTask to TaskSubscription Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2819
diff changeset
    47
    """Gets or creates a TaskSubscription entity for the given GHOPTask.
c063bb466376 Added getOrCreateTaskSubscriptionForTask to TaskSubscription Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2819
diff changeset
    48
c063bb466376 Added getOrCreateTaskSubscriptionForTask to TaskSubscription Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2819
diff changeset
    49
    Args:
c063bb466376 Added getOrCreateTaskSubscriptionForTask to TaskSubscription Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2819
diff changeset
    50
      task_entity: GHOPTask entity
c063bb466376 Added getOrCreateTaskSubscriptionForTask to TaskSubscription Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2819
diff changeset
    51
c063bb466376 Added getOrCreateTaskSubscriptionForTask to TaskSubscription Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2819
diff changeset
    52
    Returns:
c063bb466376 Added getOrCreateTaskSubscriptionForTask to TaskSubscription Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2819
diff changeset
    53
      Existing TaskSubscription entity iff any exists, otherwise a new
c063bb466376 Added getOrCreateTaskSubscriptionForTask to TaskSubscription Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2819
diff changeset
    54
      TaskSubscription entity.
c063bb466376 Added getOrCreateTaskSubscriptionForTask to TaskSubscription Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2819
diff changeset
    55
    """
c063bb466376 Added getOrCreateTaskSubscriptionForTask to TaskSubscription Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2819
diff changeset
    56
c063bb466376 Added getOrCreateTaskSubscriptionForTask to TaskSubscription Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2819
diff changeset
    57
    fields = {'task': task_entity}
c063bb466376 Added getOrCreateTaskSubscriptionForTask to TaskSubscription Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2819
diff changeset
    58
c063bb466376 Added getOrCreateTaskSubscriptionForTask to TaskSubscription Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2819
diff changeset
    59
    task_subscription = self.getForFields(fields, unique=True)
c063bb466376 Added getOrCreateTaskSubscriptionForTask to TaskSubscription Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2819
diff changeset
    60
c063bb466376 Added getOrCreateTaskSubscriptionForTask to TaskSubscription Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2819
diff changeset
    61
    if not task_subscription:
c063bb466376 Added getOrCreateTaskSubscriptionForTask to TaskSubscription Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2819
diff changeset
    62
      task_subscription = self.updateOrCreateFromFields(fields)
c063bb466376 Added getOrCreateTaskSubscriptionForTask to TaskSubscription Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2819
diff changeset
    63
c063bb466376 Added getOrCreateTaskSubscriptionForTask to TaskSubscription Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2819
diff changeset
    64
    return task_subscription
c063bb466376 Added getOrCreateTaskSubscriptionForTask to TaskSubscription Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2819
diff changeset
    65
2819
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    66
03e03b0ef0c6 Added GHOPTaskSubscription Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    67
logic = Logic()