app/soc/modules/ghop/models/task.py
author Daniel Hans <Daniel.M.Hans@gmail.com>
Tue, 10 Nov 2009 13:59:15 +0100
changeset 3083 f384c0a42920
parent 3082 da8cc38cabe9
child 3084 cac43a6cb986
permissions -rw-r--r--
'scope' field moved from TaskTag to the parent class.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2397
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
     2
#
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
     3
# Copyright 2009 the Melange authors.
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
     4
#
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
     8
#
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    10
#
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    16
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    17
"""This module contains the GHOP Task Model.
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    18
"""
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    19
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    20
__authors__ = [
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    21
  '"Madhusudan.C.S" <madhusudancs@gmail.com>',
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    22
  '"Lennard de Rijk" <ljvderijk@gmail.com>',
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    23
]
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    24
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    25
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    26
from google.appengine.ext import db
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    27
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    28
from django.utils.translation import ugettext
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    29
2679
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    30
from taggable.taggable import Tag
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    31
from taggable.taggable import Taggable
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    32
from taggable.taggable import tag_property
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    33
2397
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    34
import soc.models.linkable
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    35
import soc.models.role
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    36
import soc.models.student
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    37
import soc.models.user
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    38
2407
e23fce20ad3a Changed GHOP module imports to be consistent with rest of Melange code.
Madhusudan C.S. <madhusudancs@gmail.com>
parents: 2399
diff changeset
    39
import soc.modules.ghop.models.program
2397
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    40
2703
7117c43ccf1b Style fixes in the ghop task model module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2679
diff changeset
    41
2679
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    42
class TaskTag(Tag):
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    43
  """Model for storing all Task tags.
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    44
  """
3082
da8cc38cabe9 TaskArbritraryTag now has auto_delete set to True by default.
Daniel Hans <daniel.m.hans@gmail.com>
parents: 2858
diff changeset
    45
3083
f384c0a42920 'scope' field moved from TaskTag to the parent class.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3082
diff changeset
    46
  #: Each task_type tag is scoped under the program.
2858
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    47
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    48
  order = db.IntegerProperty(required=True, default=0)
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    49
2679
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    50
  @classmethod
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    51
  def __key_name(cls, scope_path, tag_name):
2703
7117c43ccf1b Style fixes in the ghop task model module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2679
diff changeset
    52
    """Create the key_name from program key_name as scope_path and tag_name.
7117c43ccf1b Style fixes in the ghop task model module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2679
diff changeset
    53
    """
2679
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    54
    return scope_path + '/' + tag_name
2397
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    55
2679
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    56
  @classmethod
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    57
  def get_by_name(cls, tag_name):
2703
7117c43ccf1b Style fixes in the ghop task model module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2679
diff changeset
    58
    """Get the list of tag objects that has the given tag_name.
7117c43ccf1b Style fixes in the ghop task model module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2679
diff changeset
    59
    """
2679
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    60
    tags = db.Query(cls).filter('tag =', tag_name).fetch(1000)
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    61
    return tags
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    62
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    63
  @classmethod
2858
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    64
  def get_by_scope(cls, scope):
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    65
    """Get the list of tag objects that has the given scope.
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    66
    """
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    67
    tags = db.Query(cls).filter('scope =', scope).order('order').fetch(1000)
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    68
    return tags
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    69
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    70
  @classmethod
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    71
  def get_highest_order(cls, scope):
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    72
    """Get a tag with highest order.
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    73
    """
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    74
    tags = db.Query(cls).filter('scope =', scope).order('-order').fetch(1)
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    75
    if tags:
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    76
      return tags[0].order
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    77
    else:
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    78
      return -1
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    79
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    80
  @classmethod
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    81
  def get_by_scope_and_name(cls, scope, tag_name):
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    82
    """Get a tag by scope and name.
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    83
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    84
    There can be only one such tag.
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    85
    """
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    86
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    87
    tags = db.Query(cls).filter(
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    88
        'scope =', scope).filter('tag =', tag_name).fetch(1)
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    89
    if tags:
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    90
      return tags[0]
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    91
    else:
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    92
      return None
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    93
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    94
  @classmethod
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    95
  def update_order(cls, scope, tag_name, order):
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    96
    """Updates the order of the tag.
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    97
    """
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    98
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
    99
    tag = cls.get_by_scope_and_name(scope, tag_name)
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   100
    if tag:
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   101
      tag.order = order
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   102
      tag.put()
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   103
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   104
    return tag
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   105
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   106
  @classmethod
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   107
  def copy_tag(cls, scope, tag_name, new_tag_name):
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   108
    """Copy a tag with a given scope and tag_name to another tag with
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   109
    new tag_name.
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   110
    """
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   111
    tag = cls.get_by_scope_and_name(scope, tag_name)
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   112
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   113
    if tag:
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   114
      tag_key_name = cls.__key_name(scope.key().name(), new_tag_name)
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   115
      existing_tag = cls.get_by_key_name(tag_key_name)
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   116
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   117
      if existing_tag is None:
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   118
        new_tag = cls(key_name=tag_key_name, tag=new_tag_name, scope=scope, 
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   119
                      added=tag.added, tagged=tag.tagged,
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   120
                      tagged_count=tag.tagged_count)
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   121
        new_tag.put()
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   122
        tag.delete()
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   123
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   124
        return new_tag
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   125
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   126
      return existing_tag
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   127
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   128
    return None
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   129
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   130
  @classmethod
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   131
  def delete_tag(cls, scope, tag_name):
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   132
    """Copy a tag with a given scope and tag_name to another tag with
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   133
    new tag_name.
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   134
    """
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   135
    tag = cls.get_by_scope_and_name(scope, tag_name)
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   136
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   137
    if tag:
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   138
      tag.delete()
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   139
      return True
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   140
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   141
    return False
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   142
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   143
  @classmethod
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   144
  def get_or_create(cls, scope, tag_name, order=0):
2703
7117c43ccf1b Style fixes in the ghop task model module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2679
diff changeset
   145
    """Get the Tag object that has the tag value given by tag_value.
7117c43ccf1b Style fixes in the ghop task model module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2679
diff changeset
   146
    """
3083
f384c0a42920 'scope' field moved from TaskTag to the parent class.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3082
diff changeset
   147
f384c0a42920 'scope' field moved from TaskTag to the parent class.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3082
diff changeset
   148
    if not scope:
f384c0a42920 'scope' field moved from TaskTag to the parent class.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3082
diff changeset
   149
      return None
f384c0a42920 'scope' field moved from TaskTag to the parent class.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3082
diff changeset
   150
2858
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   151
    tag_key_name = cls.__key_name(scope.key().name(), tag_name)
2679
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   152
    existing_tag = cls.get_by_key_name(tag_key_name)
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   153
    if existing_tag is None:
2703
7117c43ccf1b Style fixes in the ghop task model module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2679
diff changeset
   154
      # the tag does not yet exist, so create it.
2858
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   155
      if not order:
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   156
        order = cls.get_highest_order(scope=scope) + 1
2679
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   157
      def create_tag_txn():
2858
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   158
        new_tag = cls(key_name=tag_key_name, tag=tag_name,
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   159
                      scope=scope, order=order)
2679
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   160
        new_tag.put()
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   161
        return new_tag
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   162
      existing_tag = db.run_in_transaction(create_tag_txn)
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   163
    return existing_tag
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   164
2703
7117c43ccf1b Style fixes in the ghop task model module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2679
diff changeset
   165
2679
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   166
class TaskTypeTag(TaskTag):
2703
7117c43ccf1b Style fixes in the ghop task model module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2679
diff changeset
   167
  """Model for storing of task type tags.
7117c43ccf1b Style fixes in the ghop task model module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2679
diff changeset
   168
  """
2679
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   169
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   170
  pass
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   171
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   172
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   173
class TaskDifficultyTag(TaskTag):
2703
7117c43ccf1b Style fixes in the ghop task model module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2679
diff changeset
   174
  """Model for storing of task difficulty level tags.
7117c43ccf1b Style fixes in the ghop task model module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2679
diff changeset
   175
  """
2679
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   176
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   177
  pass
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   178
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   179
2858
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   180
class TaskArbitraryTag(TaskTag):
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   181
  """Model for storing of arbitrary tags.
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   182
  """
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   183
3082
da8cc38cabe9 TaskArbritraryTag now has auto_delete set to True by default.
Daniel Hans <daniel.m.hans@gmail.com>
parents: 2858
diff changeset
   184
  def __init__(self, *args, **kwds):
da8cc38cabe9 TaskArbritraryTag now has auto_delete set to True by default.
Daniel Hans <daniel.m.hans@gmail.com>
parents: 2858
diff changeset
   185
    """Initialization function.
da8cc38cabe9 TaskArbritraryTag now has auto_delete set to True by default.
Daniel Hans <daniel.m.hans@gmail.com>
parents: 2858
diff changeset
   186
    """
da8cc38cabe9 TaskArbritraryTag now has auto_delete set to True by default.
Daniel Hans <daniel.m.hans@gmail.com>
parents: 2858
diff changeset
   187
da8cc38cabe9 TaskArbritraryTag now has auto_delete set to True by default.
Daniel Hans <daniel.m.hans@gmail.com>
parents: 2858
diff changeset
   188
    TaskTag.__init__(self, *args, **kwds)
da8cc38cabe9 TaskArbritraryTag now has auto_delete set to True by default.
Daniel Hans <daniel.m.hans@gmail.com>
parents: 2858
diff changeset
   189
    self.auto_delete = True
2858
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   190
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   191
2679
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   192
class GHOPTask(Taggable, soc.models.linkable.Linkable):
2397
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   193
  """Model for a task used in GHOP workflow.
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   194
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   195
  The scope property of Linkable will be set to the Organization to which
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   196
  this task belongs to. A link_id will be generated automatically and will
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   197
  have no specific meaning other than identification.
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   198
  """
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   199
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   200
  #: Required field indicating the "title" of the task
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   201
  title = db.StringProperty(required=True,
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   202
                            verbose_name=ugettext('Title'))
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   203
  title.help_text = ugettext('Title of the task')
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   204
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   205
  #: Required field containing the description of the task
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   206
  description = db.TextProperty(required=True, 
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   207
                                verbose_name=ugettext('Description'))
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   208
  description.help_text = ugettext('Complete description of the task')
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   209
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   210
  #: Field indicating the difficulty level of the Task. This is not
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   211
  #: mandatory so the it can be assigned at any later stage. 
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   212
  #: The options are configured by a Program Admin.
2679
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   213
  difficulty = tag_property('difficulty')
2397
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   214
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   215
  #: Required field which contains the type of the task. These types are
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   216
  #: configured by a Program Admin.
2679
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   217
  task_type = tag_property('task_type')
2397
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   218
2858
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   219
  #: Field which contains the arbitrary tags for the task. These tags can
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   220
  #: be assigned by Org Admins and mentors.
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   221
  arbit_tag = tag_property('arbit_tag')
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   222
2397
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   223
  #: A field which contains time allowed for completing the task (in hours)
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   224
  #: from the moment that this task has been assigned to a Student
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   225
  time_to_complete = db.IntegerProperty(required=True,
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   226
                                        verbose_name=('Time to Complete'))
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   227
  time_to_complete.help_text = ugettext(
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   228
      'Time allowed to complete the task, in hours, once it is claimed')
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   229
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   230
  #: List of Mentors assigned to this task. A Mentor who creates this
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   231
  #: task is assigned as the Mentor by default. An Org Admin will have
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   232
  #: to assign a Mentor upon task creation.
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   233
  mentors = db.ListProperty(item_type=db.Key, default=[])
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   234
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   235
  #: User profile to whom this task has been claimed by. This field
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   236
  #: is mandatory for claimed tasks
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   237
  user = db.ReferenceProperty(reference_class=soc.models.user.User,
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   238
                              required=False,
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   239
                              collection_name='assigned_tasks')
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   240
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   241
  #: Student profile to whom this task is currently assigned to. If the user
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   242
  #: has registered as a Student than this field will be filled in. This field
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   243
  #: is mandatory for all Tasks in the closed state.
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   244
  student = db.ReferenceProperty(reference_class=soc.models.student.Student,
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   245
                                 required=False,
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   246
                                 collection_name='assigned_tasks')
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   247
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   248
  #: Program in which this Task has been created
2399
65a83ae32703 Changed imports in models to comply with recent GHOP code move.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2397
diff changeset
   249
  program = db.ReferenceProperty(
2407
e23fce20ad3a Changed GHOP module imports to be consistent with rest of Melange code.
Madhusudan C.S. <madhusudancs@gmail.com>
parents: 2399
diff changeset
   250
      reference_class=soc.modules.ghop.models.program.GHOPProgram,
2399
65a83ae32703 Changed imports in models to comply with recent GHOP code move.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2397
diff changeset
   251
      required=True, collection_name='tasks')
2397
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   252
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   253
  #: Required property which holds the state, the Task is currently in.
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   254
  #: This is a hidden field not shown on forms. Handled by logic internally.
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   255
  #: The state can be one of the following:
2788
78d02dcd8eb0 Changed all status to start with Uppercase letters, made 3 properties required.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2703
diff changeset
   256
  #: Unapproved: If Task is created by a Mentor, this is the automatically
2397
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   257
  #:   assigned state.
2788
78d02dcd8eb0 Changed all status to start with Uppercase letters, made 3 properties required.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2703
diff changeset
   258
  #: Unpublished: This Task is not published yet.
78d02dcd8eb0 Changed all status to start with Uppercase letters, made 3 properties required.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2703
diff changeset
   259
  #: Open: This Task is open and ready to be claimed.
78d02dcd8eb0 Changed all status to start with Uppercase letters, made 3 properties required.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2703
diff changeset
   260
  #: Reopened: This Task has been claimed but never finished and has been
2397
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   261
  #:   reopened.
2788
78d02dcd8eb0 Changed all status to start with Uppercase letters, made 3 properties required.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2703
diff changeset
   262
  #: ClaimRequested: A Student has requested to claim this task.
78d02dcd8eb0 Changed all status to start with Uppercase letters, made 3 properties required.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2703
diff changeset
   263
  #: Claimed: This Task has been claimed and someone is working on it.
78d02dcd8eb0 Changed all status to start with Uppercase letters, made 3 properties required.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2703
diff changeset
   264
  #: ActionNeeded: Work on this Task must be submitted for review within 
2397
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   265
  #:   24 hours.
2788
78d02dcd8eb0 Changed all status to start with Uppercase letters, made 3 properties required.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2703
diff changeset
   266
  #: Closed: Work on this Task has been completed to the org's content.
78d02dcd8eb0 Changed all status to start with Uppercase letters, made 3 properties required.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2703
diff changeset
   267
  #: AwaitingRegistration: Student has completed work on this task, but
2397
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   268
  #:   needs to complete Student registration before this task is closed.
2788
78d02dcd8eb0 Changed all status to start with Uppercase letters, made 3 properties required.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2703
diff changeset
   269
  #: NeedsWork: This work on this Tasks needs a bit more brushing up. This
2397
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   270
  #:   state is followed by a Mentor review.
2788
78d02dcd8eb0 Changed all status to start with Uppercase letters, made 3 properties required.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2703
diff changeset
   271
  #: NeedsReview: Student has submitted work for this task and it should
2397
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   272
  #:   be reviewed by a Mentor.
2788
78d02dcd8eb0 Changed all status to start with Uppercase letters, made 3 properties required.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2703
diff changeset
   273
  #: Invalid: The Task is deleted either by an Org Admin/Mentor
2397
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   274
  status = db.StringProperty(
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   275
      required=True, verbose_name=ugettext('Status'),
2788
78d02dcd8eb0 Changed all status to start with Uppercase letters, made 3 properties required.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2703
diff changeset
   276
      choices=['Unapproved', 'Unpublished', 'Open', 'Reopened', 
78d02dcd8eb0 Changed all status to start with Uppercase letters, made 3 properties required.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2703
diff changeset
   277
               'ClaimRequested', 'Claimed', 'ActionNeeded', 
78d02dcd8eb0 Changed all status to start with Uppercase letters, made 3 properties required.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2703
diff changeset
   278
               'Closed', 'AwaitingRegistration', 'NeedsWork',
78d02dcd8eb0 Changed all status to start with Uppercase letters, made 3 properties required.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2703
diff changeset
   279
               'NeedsReview', 'Invalid'],
78d02dcd8eb0 Changed all status to start with Uppercase letters, made 3 properties required.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2703
diff changeset
   280
      default='Unapproved')
2397
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   281
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   282
  #: This field is set to the next deadline that will have consequences for
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   283
  #: this Task. For instance this will store a DateTime property which will
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   284
  #: tell when this Task should be completed.
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   285
  deadline = db.DateTimeProperty(required=False,
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   286
                                 verbose_name=ugettext('Deadline'))
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   287
2788
78d02dcd8eb0 Changed all status to start with Uppercase letters, made 3 properties required.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2703
diff changeset
   288
  #: Required field containing the Mentor/Org Admin who created this task.
78d02dcd8eb0 Changed all status to start with Uppercase letters, made 3 properties required.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2703
diff changeset
   289
  #: If site developer has created the task, it is empty.
2397
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   290
  created_by = db.ReferenceProperty(reference_class=soc.models.role.Role,
2788
78d02dcd8eb0 Changed all status to start with Uppercase letters, made 3 properties required.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2703
diff changeset
   291
                                    required=False,
2397
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   292
                                    collection_name='created_tasks',
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   293
                                    verbose_name=ugettext('Created by'))
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   294
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   295
  #: Date when the proposal was created
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   296
  created_on = db.DateTimeProperty(required=True, auto_now_add=True,
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   297
                                   verbose_name=ugettext('Created on'))
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   298
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   299
  #: Required field containing the Mentor/Org Admin who last edited this
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   300
  #: task. It changes only when Mentor/Org Admin changes title, description,
2679
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   301
  #: difficulty, task_type, time_to_complete. If site developer has modified
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   302
  #: the task, it is empty.
2397
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   303
  modified_by = db.ReferenceProperty(reference_class=soc.models.role.Role,
2788
78d02dcd8eb0 Changed all status to start with Uppercase letters, made 3 properties required.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2703
diff changeset
   304
                                   required=False,
2397
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   305
                                   collection_name='edited_tasks',
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   306
                                   verbose_name=ugettext('Modified by'))
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   307
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   308
  #: Date when the proposal was last modified, should be set manually on edit
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   309
  modified_on = db.DateTimeProperty(required=True, auto_now_add=True,
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   310
                                    verbose_name=ugettext('Modified on'))
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   311
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   312
  #: A field which holds the entire history of this task in JSON. The
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   313
  #: structure of this JSON string is as follows:
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   314
  #: {
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   315
  #:    timestamp1: {
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   316
  #:                   "user": User reference
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   317
  #:                   "student": Student reference
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   318
  #:                   ...
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   319
  #:                   "state": "Unapproved"
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   320
  #:                   ...
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   321
  #:                   "edited_by": Role reference
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   322
  #:                   
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   323
  #:               }
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   324
  #:    timestamp2: {
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   325
  #:                   "state": "Unpublished"
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   326
  #:               }
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   327
  #: }
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   328
  #: First dictionary item holds the values for all the properties in this
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   329
  #: model. The subsequent items hold the properties that changed at the
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   330
  #: timestamp given by the key.
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   331
  #: Reference properties will be stored by calling str() on their Key.
2788
78d02dcd8eb0 Changed all status to start with Uppercase letters, made 3 properties required.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2703
diff changeset
   332
  history = db.TextProperty(required=False, default='')
2679
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   333
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   334
  def __init__(self, parent=None, key_name=None, 
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   335
               app=None, **entity_values):
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   336
    """Constructor for GHOPTask Model.
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   337
    
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   338
    Args:
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   339
        See Google App Engine APIs.
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   340
    """
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   341
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   342
    # explicitly call the AppEngine datastore Model constructor
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   343
    db.Model.__init__(self, parent, key_name, app, **entity_values)
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   344
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   345
    # call the Taggable constructor to initialize the tags specified as
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   346
    # keyword arguments
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   347
    Taggable.__init__(self, task_type=TaskTypeTag, 
2858
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   348
                      difficulty=TaskDifficultyTag,
9b59d89e6707 Added additional methods for TaskTag model and add arbit_tag type to GHOPTask.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2788
diff changeset
   349
                      arbit_tag=TaskArbitraryTag)