app/soc/modules/ghop/models/task.py
author Madhusudan.C.S <madhusudancs@gmail.com>
Sat, 01 Aug 2009 19:27:20 +0530
changeset 2703 7117c43ccf1b
parent 2679 0ede2f3adbc1
child 2788 78d02dcd8eb0
permissions -rw-r--r--
Style fixes in the ghop task model module.
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
  """
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    45
  
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    46
  #: Each task_type tag is scoped under the program. 
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    47
  scope = db.ReferenceProperty(reference_class=soc.models.linkable.Linkable,
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    48
                               required=True,
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    49
                               collection_name='task_type_tags')
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    50
  
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    51
  @classmethod
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    52
  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
    53
    """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
    54
    """
2679
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    55
    return scope_path + '/' + tag_name
2397
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    56
2679
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    57
  @classmethod
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    58
  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
    59
    """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
    60
    """
2679
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    61
    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
    62
    return tags
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    63
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    64
  @classmethod
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    65
  def get_or_create(cls, program, tag_name):
2703
7117c43ccf1b Style fixes in the ghop task model module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2679
diff changeset
    66
    """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
    67
    """
2679
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    68
    tag_key_name = cls.__key_name(program.key().name(), tag_name)
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    69
    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
    70
    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
    71
      # the tag does not yet exist, so create it.
2679
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    72
      def create_tag_txn():
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    73
        new_tag = cls(key_name=tag_key_name, tag=tag_name, scope=program)
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    74
        new_tag.put()
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    75
        return new_tag
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    76
      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
    77
    return existing_tag
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    78
2703
7117c43ccf1b Style fixes in the ghop task model module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2679
diff changeset
    79
2679
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    80
class TaskTypeTag(TaskTag):
2703
7117c43ccf1b Style fixes in the ghop task model module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2679
diff changeset
    81
  """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
    82
  """
2679
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    83
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    84
  pass
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    85
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    86
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    87
class TaskDifficultyTag(TaskTag):
2703
7117c43ccf1b Style fixes in the ghop task model module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2679
diff changeset
    88
  """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
    89
  """
2679
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    90
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    91
  pass
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    92
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    93
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    94
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
    95
  """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
    96
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    97
  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
    98
  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
    99
  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
   100
  """
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   101
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   102
  #: 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
   103
  title = db.StringProperty(required=True,
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   104
                            verbose_name=ugettext('Title'))
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   105
  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
   106
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   107
  #: 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
   108
  description = db.TextProperty(required=True, 
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   109
                                verbose_name=ugettext('Description'))
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   110
  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
   111
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   112
  #: 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
   113
  #: 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
   114
  #: 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
   115
  difficulty = tag_property('difficulty')
2397
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   116
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   117
  #: 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
   118
  #: 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
   119
  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
   120
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   121
  #: 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
   122
  #: 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
   123
  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
   124
                                        verbose_name=('Time to Complete'))
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   125
  time_to_complete.help_text = ugettext(
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   126
      '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
   127
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   128
  #: 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
   129
  #: 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
   130
  #: 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
   131
  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
   132
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   133
  #: 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
   134
  #: is mandatory for claimed tasks
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   135
  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
   136
                              required=False,
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   137
                              collection_name='assigned_tasks')
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   138
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   139
  #: 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
   140
  #: 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
   141
  #: 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
   142
  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
   143
                                 required=False,
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   144
                                 collection_name='assigned_tasks')
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   145
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   146
  #: 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
   147
  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
   148
      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
   149
      required=True, collection_name='tasks')
2397
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   150
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   151
  #: 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
   152
  #: 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
   153
  #: The state can be one of the following:
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   154
  #: unapproved: If Task is created by a Mentor, this is the automatically
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   155
  #:   assigned state.
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   156
  #: unpublished: This Task is not published yet.
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   157
  #: open: This Task is open and ready to be claimed.
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   158
  #: reopened: This Task has been claimed but never finished and has been
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   159
  #:   reopened.
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   160
  #: claim_requested: A Student has requested to claim this task.
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   161
  #: claimed: This Task has been claimed and someone is working on it.
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   162
  #: action_needed: Work on this Task must be submitted for review within 
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   163
  #:   24 hours.
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   164
  #: closed: Work on this Task has been completed to the org's content.
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   165
  #: awaiting_registration: Student has completed work on this task, but
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   166
  #:   needs to complete Student registration before this task is closed.
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   167
  #: needs_work: This work on this Tasks needs a bit more brushing up. This
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   168
  #:   state is followed by a Mentor review.
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   169
  #: needs_review: Student has submitted work for this task and it should
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   170
  #:   be reviewed by a Mentor.
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   171
  status = db.StringProperty(
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   172
      required=True, verbose_name=ugettext('Status'),
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   173
      choices=['unapproved', 'unpublished', 'open', 'reopened', 
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   174
               'claim_requested', 'claimed', 'action_needed', 
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   175
               'closed', 'awaiting_registration', 'needs_work',
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   176
               'needs_review'],
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   177
      default='unapproved')
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   178
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   179
  #: A field which indicates if the Task was ever in the Reopened state.
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   180
  #: True indicates that its state was Reopened once, false indicated that it
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   181
  #: has never been in the Reopened state.
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   182
  was_reopened = db.BooleanProperty(default=False,
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   183
                                    verbose_name=ugettext('Has been reopened'))
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   184
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   185
  #: 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
   186
  #: 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
   187
  #: 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
   188
  deadline = db.DateTimeProperty(required=False,
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   189
                                 verbose_name=ugettext('Deadline'))
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   190
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   191
  #: Required field containing the Mentor/Org Admin who created this task
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   192
  created_by = db.ReferenceProperty(reference_class=soc.models.role.Role,
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   193
                                    required=True,
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   194
                                    collection_name='created_tasks',
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   195
                                    verbose_name=ugettext('Created by'))
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   196
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   197
  #: Date when the proposal was created
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   198
  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
   199
                                   verbose_name=ugettext('Created on'))
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   200
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   201
  #: 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
   202
  #: 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
   203
  #: 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
   204
  #: the task, it is empty.
2397
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   205
  modified_by = db.ReferenceProperty(reference_class=soc.models.role.Role,
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   206
                                   required=True,
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   207
                                   collection_name='edited_tasks',
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   208
                                   verbose_name=ugettext('Modified by'))
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
  #: 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
   211
  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
   212
                                    verbose_name=ugettext('Modified on'))
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   213
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   214
  #: 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
   215
  #: 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
   216
  #: {
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   217
  #:    timestamp1: {
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   218
  #:                   "user": User reference
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   219
  #:                   "student": Student reference
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   220
  #:                   ...
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   221
  #:                   "state": "Unapproved"
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   222
  #:                   ...
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   223
  #:                   "edited_by": Role reference
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   224
  #:                   
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   225
  #:               }
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   226
  #:    timestamp2: {
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   227
  #:                   "state": "Unpublished"
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   228
  #:               }
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
  #: 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
   231
  #: 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
   232
  #: timestamp given by the key.
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   233
  #: Reference properties will be stored by calling str() on their Key.
d943fa182fae Moved the GHOP module into the modules package.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   234
  history = db.TextProperty(required=True, default='')
2679
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   235
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   236
  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
   237
               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
   238
    """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
   239
    
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   240
    Args:
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   241
        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
   242
    """
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   243
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   244
    # 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
   245
    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
   246
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   247
    # 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
   248
    # keyword arguments
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   249
    Taggable.__init__(self, task_type=TaskTypeTag, 
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   250
                      difficulty=TaskDifficultyTag)
0ede2f3adbc1 Adds to Melange a tags framework based on taggable-mixin.
Madhusudan C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   251