app/soc/modules/ghop/logic/models/task.py
author Lennard de Rijk <ljvderijk@gmail.com>
Sun, 08 Nov 2009 11:54:44 -0800
changeset 3080 30a33926ab91
parent 3059 14421976288a
child 3091 a48f4e860f7b
permissions -rw-r--r--
Fixed an error with the task_history not being loaded when it was empty.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2401
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
     2
#
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
     3
# Copyright 2009 the Melange authors.
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
     4
#
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
     8
#
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    10
#
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    16
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    17
"""GHOPTask (Model) query functions.
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    18
"""
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    19
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    20
__authors__ = [
2823
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    21
    '"Madhusudan.C.S" <madhusudancs@gmail.com>',
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    22
    '"Lennard de Rijk" <ljvderijk@gmail.com>',
2401
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    23
  ]
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    24
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    25
2823
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    26
import datetime
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    27
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    28
from google.appengine.ext import db
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    29
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    30
from django.utils import simplejson
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    31
from django.utils.translation import ugettext
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    32
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    33
from soc.logic.models import base
2401
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    34
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    35
import soc.models.linkable
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    36
2407
e23fce20ad3a Changed GHOP module imports to be consistent with rest of Melange code.
Madhusudan C.S. <madhusudancs@gmail.com>
parents: 2401
diff changeset
    37
import soc.modules.ghop.logic.models.organization
e23fce20ad3a Changed GHOP module imports to be consistent with rest of Melange code.
Madhusudan C.S. <madhusudancs@gmail.com>
parents: 2401
diff changeset
    38
import soc.modules.ghop.models.task
2401
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    39
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    40
2823
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    41
STATE_TRANSITIONS = {
2831
a7ed56911653 STATE_TRANSITIONS dictionary values are changed to strings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2823
diff changeset
    42
    'Claimed': 'transitFromClaimed',
a7ed56911653 STATE_TRANSITIONS dictionary values are changed to strings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2823
diff changeset
    43
    'NeedsReview': 'transitFromNeedsReview',
a7ed56911653 STATE_TRANSITIONS dictionary values are changed to strings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2823
diff changeset
    44
    'ActionNeeded': 'transitFromActionNeeded',
a7ed56911653 STATE_TRANSITIONS dictionary values are changed to strings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2823
diff changeset
    45
    'NeedsWork': 'transitFromNeedsWork',
2823
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    46
    }
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    47
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    48
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    49
class Logic(base.Logic):
2401
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    50
  """Logic methods for the GHOPTask model.
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    51
  """
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    52
2823
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    53
  DEF_ACTION_NEEDED_MSG = ugettext(
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    54
      '(The Melange Automated System has detected that the intial '
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    55
      'deadline has been passed and it has set the task status to '
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    56
      'ActionNeeded.)')
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    57
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    58
  DEF_NO_MORE_WORK_MSG = ugettext(
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    59
      '(The Melange Automated System has detected that the deadline '
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    60
      'has been passed and no more work can be submitted.)')
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    61
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    62
  DEF_REOPENED_MSG = ugettext(
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    63
      '(The Melange Automated System has detected that the final '
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    64
      'deadline has been passed and it has Reopened the task.)')
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    65
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    66
2407
e23fce20ad3a Changed GHOP module imports to be consistent with rest of Melange code.
Madhusudan C.S. <madhusudancs@gmail.com>
parents: 2401
diff changeset
    67
  def __init__(self, model=soc.modules.ghop.models.task.GHOPTask,
2401
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    68
               base_model=soc.models.linkable.Linkable, 
2407
e23fce20ad3a Changed GHOP module imports to be consistent with rest of Melange code.
Madhusudan C.S. <madhusudancs@gmail.com>
parents: 2401
diff changeset
    69
               scope_logic=soc.modules.ghop.logic.models.organization):
2401
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    70
    """Defines the name, key_name and model for this entity.
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    71
    """
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    72
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    73
    super(Logic, self).__init__(model, base_model=base_model,
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    74
                                scope_logic=scope_logic)
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    75
2823
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    76
  def updateEntityProperties(self, entity, entity_properties,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    77
                             silent=False, store=True):
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    78
    """See base.Logic.updateEntityProperties().
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    79
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    80
    Also ensures that the history property of the task is updated in the same
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    81
    datastore operation.
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    82
    """
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    83
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    84
    from soc.logic.models import base as base_logic
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    85
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    86
    # TODO: History needs a proper test drive and perhaps a refactoring
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    87
    history = {}
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    88
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    89
    # we construct initial snapshot of the task when it is published
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    90
    # for the first time.
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    91
    if entity_properties and 'status' in entity_properties:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    92
      if entity.status == 'Unpublished' or entity.status == 'Unapproved':
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    93
        if entity_properties['status'] == 'Open':
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    94
          history = {
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    95
              'title': entity.title,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    96
              'description': entity.description,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    97
              'difficulty': entity.difficulty[0].tag,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    98
              'task_type': [type.tag for type in entity.task_type],
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    99
              'time_to_complete': entity.time_to_complete,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   100
              'mentors': [m_key.name() for m_key in entity.mentors],
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   101
              'user': '',
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   102
              'student': '',
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   103
              'status': entity.status,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   104
              'deadline': '',
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   105
              'created_by': entity.created_by.key().name(),
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   106
              'created_on': str(entity.created_on),
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   107
              'modified_on': str(entity.modified_on),
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   108
              }
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   109
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   110
          if entity.modified_by:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   111
            history['modified_by'] = entity.modified_by.key().name()
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   112
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   113
          # initialize history
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   114
          task_history = {}
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   115
      # extract the existing json history from the entity to update it
3080
30a33926ab91 Fixed an error with the task_history not being loaded when it was empty.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3059
diff changeset
   116
    elif entity.history:
30a33926ab91 Fixed an error with the task_history not being loaded when it was empty.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3059
diff changeset
   117
      task_history = simplejson.loads(entity.history)
2823
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   118
    else:
3080
30a33926ab91 Fixed an error with the task_history not being loaded when it was empty.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3059
diff changeset
   119
      task_history = {}
2823
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   120
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   121
      # we construct history for only changed entity properties
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   122
      if entity_properties:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   123
        for property in entity_properties:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   124
          changed_val = getattr(entity, property)
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   125
          if changed_val != entity_properties[property]:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   126
            if property == 'deadline':
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   127
              history[property] = str(changed_val)
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   128
            else:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   129
              history[property] = changed_val
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   130
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   131
    if history:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   132
      # create a dictionary for the new history update with timestamp as key
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   133
      tstamp = str(datetime.datetime.now())
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   134
      new_history = {tstamp: history}
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   135
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   136
      # update existing history
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   137
      task_history.update(new_history)
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   138
      task_history_str = simplejson.dumps(task_history)
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   139
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   140
      # update the task's history property
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   141
      history_property = {
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   142
          'history': task_history_str
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   143
          }
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   144
      entity_properties.update(history_property)
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   145
2979
ba4aeaaad0a1 Fixed GHOP Task Logic's updateEntityProperties.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2831
diff changeset
   146
    # call the base logic method to store the updated Task entity
ba4aeaaad0a1 Fixed GHOP Task Logic's updateEntityProperties.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2831
diff changeset
   147
    return super(Logic, self).updateEntityProperties(
ba4aeaaad0a1 Fixed GHOP Task Logic's updateEntityProperties.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2831
diff changeset
   148
        entity, entity_properties, silent=silent, store=store)
2823
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   149
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   150
  def updateEntityPropertiesWithCWS(self, entity, entity_properties,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   151
                                    comment_properties=None, 
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   152
                                    ws_properties=None, silent=False):
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   153
    """Updates the GHOPTask entity properties and creates a comment
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   154
    entity.
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   155
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   156
    Args:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   157
      entity: a model entity
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   158
      entity_properties: keyword arguments that correspond to entity
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   159
          properties and their values
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   160
      comment_properties: keyword arguments that correspond to the
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   161
          GHOPTask's to be created comment entity
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   162
      silent: iff True does not call post store methods.
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   163
    """
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   164
3059
14421976288a The work_submission model's update now reflected in views and logic.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2979
diff changeset
   165
    from soc.modules.ghop.logic.models.comment import logic as \
14421976288a The work_submission model's update now reflected in views and logic.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2979
diff changeset
   166
        ghop_comment_logic
14421976288a The work_submission model's update now reflected in views and logic.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2979
diff changeset
   167
    from soc.modules.ghop.logic.models.work_submission import logic as \
2823
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   168
        ghop_work_submission_logic
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   169
    from soc.modules.ghop.models import comment as ghop_comment_model
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   170
    from soc.modules.ghop.models import work_submission as \
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   171
        ghop_work_submission_model
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   172
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   173
    if entity_properties:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   174
      entity = self.updateEntityProperties(entity, entity_properties, 
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   175
                                           silent=silent, store=False)
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   176
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   177
    comment_entity = ghop_comment_model.GHOPComment(**comment_properties)
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   178
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   179
    ws_entity = None
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   180
    if ws_properties:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   181
      ws_entity = ghop_work_submission_model.GHOPWorkSubmission(
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   182
          **ws_properties)
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   183
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   184
    def comment_create():
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   185
      """Method to be run in transaction that stores Task, Comment and
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   186
      WorkSubmission.
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   187
      """
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   188
      entity.put()
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   189
      if ws_entity:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   190
        ws_entity.put()
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   191
        comment_entity.content = comment_entity.content % (
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   192
            ws_entity.key().id_or_name())
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   193
        comment_entity.put()
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   194
        return entity, comment_entity, ws_entity
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   195
      else:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   196
        comment_entity.put()
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   197
        return entity, comment_entity, None
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   198
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   199
    entity, comment_entity, ws_entity = db.run_in_transaction(
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   200
        comment_create)
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   201
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   202
    if not silent:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   203
      # call the _onCreate methods for the Comment and WorkSubmission
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   204
      if comment_entity:
3059
14421976288a The work_submission model's update now reflected in views and logic.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2979
diff changeset
   205
        ghop_comment_logic._onCreate(comment_entity)
2823
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   206
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   207
      if ws_entity:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   208
        ghop_work_submission_logic._onCreate(ws_entity)
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   209
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   210
    return entity, comment_entity, ws_entity
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   211
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   212
  def updateOrCreateFromFields(self, properties, silent=False):
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   213
    """See base.Logic.updateOrCreateFromFields().
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   214
    """
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   215
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   216
    # TODO: History needs to be tested and perhaps refactored
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   217
    if properties['status'] == 'Open':
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   218
      history = {
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   219
          'title': properties['title'],
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   220
          'description': properties['description'],
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   221
          'difficulty': properties['difficulty']['tags'],
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   222
          'task_type': properties['type_tags'],
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   223
          'time_to_complete': properties['time_to_complete'],
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   224
          'mentors': [m_key.name() for m_key in properties['mentors']],
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   225
          'user': '',
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   226
          'student': '',
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   227
          'status': properties['status'],
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   228
          'deadline': '',
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   229
          'created_on': str(properties['created_on']),
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   230
          'modified_on': str(properties['modified_on']),
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   231
          }
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   232
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   233
      if 'created_by' in properties and properties['created_by']:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   234
        history['created_by'] = properties['created_by'].key().name()
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   235
        history['modified_by'] = properties['modified_by'].key().name()
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   236
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   237
      # Constructs new history from the _constructNewHistory method, assigns
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   238
      # it as a value to the dictionary key with current timestamp and dumps
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   239
      # a JSON string.
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   240
      task_history_str = simplejson.dumps({
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   241
          str(datetime.datetime.now()): history,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   242
          })
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   243
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   244
      # update the task's history property
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   245
      history_property = {
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   246
          'history': task_history_str
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   247
          }
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   248
      properties.update(history_property)
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   249
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   250
    entity = super(Logic, self).updateOrCreateFromFields(properties, silent)
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   251
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   252
    if entity:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   253
      if properties.get('task_type'):
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   254
        setattr(entity, 'task_type', properties['task_type'])
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   255
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   256
      if properties.get('difficulty'):
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   257
        setattr(entity, 'difficulty', properties['difficulty'])
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   258
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   259
    return entity
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   260
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   261
  def getFromKeyFieldsWithCWSOr404(self, fields):
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   262
    """Returns the Task, all Comments and all WorkSubmissions for the Task
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   263
    specified by the fields argument.
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   264
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   265
    For args see base.getFromKeyFieldsOr404().
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   266
    """
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   267
3059
14421976288a The work_submission model's update now reflected in views and logic.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2979
diff changeset
   268
    from soc.modules.ghop.logic.models.comment import logic as \
14421976288a The work_submission model's update now reflected in views and logic.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2979
diff changeset
   269
        ghop_comment_logic
14421976288a The work_submission model's update now reflected in views and logic.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2979
diff changeset
   270
    from soc.modules.ghop.logic.models.work_submission import logic as \
2823
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   271
        ghop_work_submission_logic
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   272
 
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   273
    entity = self.getFromKeyFieldsOr404(fields)
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   274
3059
14421976288a The work_submission model's update now reflected in views and logic.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2979
diff changeset
   275
    comment_entities = ghop_comment_logic.getForFields(
2823
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   276
        ancestors=[entity], order=['created_on'])
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   277
3059
14421976288a The work_submission model's update now reflected in views and logic.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2979
diff changeset
   278
    ws_entities = ghop_work_submission_logic.getForFields(
2823
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   279
        ancestors=[entity], order=['submitted_on'])
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   280
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   281
    return entity, comment_entities, ws_entities
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   282
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   283
  def updateTaskStatus(self, entity):
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   284
    """Method used to transit a task from a state to another state
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   285
    depending on the context. Whenever the deadline has passed.
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   286
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   287
    Args:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   288
      entity: The GHOPTask entity
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   289
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   290
    Returns:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   291
      Task entity and a Comment entity if the occurring transit created one.
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   292
    """
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   293
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   294
    from soc.modules.ghop.tasks import task_update
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   295
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   296
    if entity.deadline and datetime.datetime.now() > entity.deadline:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   297
      # calls a specific method to make a transition depending on the
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   298
      # task's current state
2831
a7ed56911653 STATE_TRANSITIONS dictionary values are changed to strings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2823
diff changeset
   299
      transit_func = getattr(self, STATE_TRANSITIONS[entity.status])
2823
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   300
      update_dict = transit_func(entity)
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   301
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   302
      comment_properties = {
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   303
          'parent': entity,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   304
          'scope_path': entity.key().name(),
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   305
          'created_by': None,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   306
          'content': update_dict['content'],
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   307
          'changes': update_dict['changes'],
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   308
          }
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   309
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   310
      entity, comment_entity, _ = self.updateEntityPropertiesWithCWS(
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   311
          entity, update_dict['properties'], comment_properties)
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   312
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   313
      if entity.deadline:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   314
        # only if there is a deadline set we should schedule another task
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   315
        task_update.spawnUpdateTask(entity)
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   316
    else:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   317
      comment_entity=None
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   318
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   319
    return entity, comment_entity
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   320
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   321
  def transitFromClaimed(self, entity):
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   322
    """Makes a state transition of a GHOP Task from Claimed state
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   323
    to a relevant state.
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   324
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   325
    Args:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   326
      entity: The GHOPTask entity
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   327
    """
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   328
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   329
    # deadline is extended by 24 hours.
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   330
    deadline = entity.deadline + datetime.timedelta(
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   331
        hours=24)
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   332
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   333
    properties = {
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   334
        'status': 'ActionNeeded',
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   335
        'deadline': deadline,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   336
        }
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   337
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   338
    changes = [ugettext('User-MelangeAutomatic'),
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   339
               ugettext('Action-Warned for action'),
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   340
               ugettext('Status-%s' % (properties['status']))]
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   341
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   342
    content = self.DEF_ACTION_NEEDED_MSG
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   343
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   344
    update_dict = {
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   345
        'properties': properties,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   346
        'changes': changes,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   347
        'content': content,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   348
        }
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   349
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   350
    return update_dict
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   351
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   352
  def transitFromNeedsReview(self, entity):
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   353
    """Makes a state transition of a GHOP Task from NeedsReview state
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   354
    to a relevant state.
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   355
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   356
    Args:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   357
      entity: The GHOPTask entity
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   358
    """
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   359
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   360
    properties = {
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   361
        'deadline': None,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   362
        }
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   363
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   364
    changes = [ugettext('User-MelangeAutomatic'),
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   365
               ugettext('Action-Deadline passed'),
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   366
               ugettext('Status-%s' % (entity.status))]
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   367
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   368
    content = self.DEF_NO_MORE_WORK_MSG
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   369
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   370
    update_dict = {
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   371
        'properties': properties,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   372
        'changes': changes,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   373
        'content': content,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   374
        }
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   375
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   376
    return update_dict
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   377
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   378
  def transitFromActionNeeded(self, entity):
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   379
    """Makes a state transition of a GHOP Task from ActionNeeded state
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   380
    to a relevant state.
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   381
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   382
    Args:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   383
      entity: The GHOPTask entity
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   384
    """
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   385
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   386
    properties = {
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   387
        'user': None,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   388
        'student': None,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   389
        'status': 'Reopened',
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   390
        'deadline': None,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   391
        }
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   392
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   393
    changes = [ugettext('User-MelangeAutomatic'),
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   394
               ugettext('Action-Forcibly reopened'),
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   395
               ugettext('Status-Reopened')]
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   396
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   397
    content = self.DEF_REOPENED_MSG
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   398
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   399
    update_dict = {
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   400
        'properties': properties,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   401
        'changes': changes,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   402
        'content': content,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   403
        }
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   404
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   405
    return update_dict
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   406
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   407
  def transitFromNeedsWork(self, entity):
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   408
    """Makes a state transition of a GHOP Task from NeedsWork state
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   409
    to a relevant state.
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   410
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   411
    Args:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   412
      entity: The GHOPTask entity
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   413
    """
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   414
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   415
    properties = {
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   416
        'user': None,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   417
        'student': None,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   418
        'status': 'Reopened',
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   419
        'deadline': None,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   420
        }
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   421
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   422
    changes = [ugettext('User-MelangeAutomatic'),
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   423
               ugettext('Action-Forcibly reopened'),
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   424
               ugettext('Status-Reopened')]
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   425
    
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   426
    update_dict = {
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   427
        'properties': properties,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   428
        'changes': changes,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   429
        'content': None,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   430
        }
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   431
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   432
    return update_dict
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   433
2401
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   434
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   435
logic = Logic()