app/soc/modules/ghop/logic/models/task.py
author Mario Ferraro <fadinlight@gmail.com>
Sun, 15 Nov 2009 22:12:20 +0100
changeset 3093 d1be59b6b627
parent 3092 beeb5d111318
permissions -rw-r--r--
GMaps related JS changed to use new google namespace. Google is going to change permanently in the future the way to load its services, so better stay safe. Also this commit shows uses of the new melange.js module. Fixes Issue 634.
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>',
3091
a48f4e860f7b Tasks may be deleted by pressing 'Delete' button on the edit view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3080
diff changeset
    22
    '"Daniel Hans" <daniel.m.hans@gmail.com>',
2823
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    23
    '"Lennard de Rijk" <ljvderijk@gmail.com>',
2401
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
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    26
2823
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    27
import datetime
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    28
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    29
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
    30
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    31
from django.utils import simplejson
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    32
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
    33
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    34
from soc.logic.models import base
3091
a48f4e860f7b Tasks may be deleted by pressing 'Delete' button on the edit view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3080
diff changeset
    35
from soc.logic import tags
a48f4e860f7b Tasks may be deleted by pressing 'Delete' button on the edit view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3080
diff changeset
    36
a48f4e860f7b Tasks may be deleted by pressing 'Delete' button on the edit view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3080
diff changeset
    37
from soc.modules.ghop.logic.models import comment as ghop_comment_logic
2401
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    38
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    39
import soc.models.linkable
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    40
2407
e23fce20ad3a Changed GHOP module imports to be consistent with rest of Melange code.
Madhusudan C.S. <madhusudancs@gmail.com>
parents: 2401
diff changeset
    41
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
    42
import soc.modules.ghop.models.task
2401
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    43
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    44
2823
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    45
STATE_TRANSITIONS = {
2831
a7ed56911653 STATE_TRANSITIONS dictionary values are changed to strings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2823
diff changeset
    46
    'Claimed': 'transitFromClaimed',
a7ed56911653 STATE_TRANSITIONS dictionary values are changed to strings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2823
diff changeset
    47
    'NeedsReview': 'transitFromNeedsReview',
a7ed56911653 STATE_TRANSITIONS dictionary values are changed to strings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2823
diff changeset
    48
    'ActionNeeded': 'transitFromActionNeeded',
a7ed56911653 STATE_TRANSITIONS dictionary values are changed to strings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2823
diff changeset
    49
    'NeedsWork': 'transitFromNeedsWork',
2823
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    50
    }
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    51
3091
a48f4e860f7b Tasks may be deleted by pressing 'Delete' button on the edit view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3080
diff changeset
    52
TAG_NAMES = ['arbit_tag', 'difficulty', 'task_type']
2823
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    53
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    54
class Logic(base.Logic):
2401
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    55
  """Logic methods for the GHOPTask model.
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    56
  """
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    57
2823
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    58
  DEF_ACTION_NEEDED_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 intial '
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    60
      '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
    61
      'ActionNeeded.)')
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    62
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    63
  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
    64
      '(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
    65
      '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
    66
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    67
  DEF_REOPENED_MSG = ugettext(
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    68
      '(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
    69
      '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
    70
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    71
2407
e23fce20ad3a Changed GHOP module imports to be consistent with rest of Melange code.
Madhusudan C.S. <madhusudancs@gmail.com>
parents: 2401
diff changeset
    72
  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
    73
               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
    74
               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
    75
    """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
    76
    """
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    77
3091
a48f4e860f7b Tasks may be deleted by pressing 'Delete' button on the edit view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3080
diff changeset
    78
    self.tags_service = tags.TagsService(TAG_NAMES)
a48f4e860f7b Tasks may be deleted by pressing 'Delete' button on the edit view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3080
diff changeset
    79
2401
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    80
    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
    81
                                scope_logic=scope_logic)
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
    82
2823
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    83
  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
    84
                             silent=False, store=True):
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    85
    """See base.Logic.updateEntityProperties().
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    86
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    87
    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
    88
    datastore operation.
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    89
    """
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    90
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    91
    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
    92
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    93
    # 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
    94
    history = {}
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    95
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    96
    # 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
    97
    # for the first time.
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
    98
    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
    99
      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
   100
        if entity_properties['status'] == 'Open':
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   101
          history = {
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   102
              'title': entity.title,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   103
              'description': entity.description,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   104
              'difficulty': entity.difficulty[0].tag,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   105
              '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
   106
              '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
   107
              '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
   108
              'user': '',
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   109
              'student': '',
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   110
              'status': entity.status,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   111
              'deadline': '',
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   112
              '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
   113
              '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
   114
              '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
   115
              }
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   116
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   117
          if entity.modified_by:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   118
            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
   119
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   120
          # initialize history
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   121
          task_history = {}
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   122
      # 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
   123
    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
   124
      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
   125
    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
   126
      task_history = {}
2823
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   127
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   128
      # 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
   129
      if entity_properties:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   130
        for property in entity_properties:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   131
          changed_val = getattr(entity, property)
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   132
          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
   133
            if property == 'deadline':
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   134
              history[property] = str(changed_val)
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   135
            else:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   136
              history[property] = changed_val
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   137
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   138
    if history:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   139
      # 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
   140
      tstamp = str(datetime.datetime.now())
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   141
      new_history = {tstamp: history}
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   142
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   143
      # update existing history
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   144
      task_history.update(new_history)
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   145
      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
   146
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   147
      # 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
   148
      history_property = {
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   149
          'history': task_history_str
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   150
          }
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   151
      entity_properties.update(history_property)
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   152
3092
beeb5d111318 Changes in tags are saved to the data store.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3091
diff changeset
   153
    entity = self.tags_service.setTagValuesForEntity(entity, entity_properties)
beeb5d111318 Changes in tags are saved to the data store.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3091
diff changeset
   154
2979
ba4aeaaad0a1 Fixed GHOP Task Logic's updateEntityProperties.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2831
diff changeset
   155
    # 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
   156
    return super(Logic, self).updateEntityProperties(
ba4aeaaad0a1 Fixed GHOP Task Logic's updateEntityProperties.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2831
diff changeset
   157
        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
   158
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   159
  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
   160
                                    comment_properties=None, 
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   161
                                    ws_properties=None, silent=False):
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   162
    """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
   163
    entity.
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   164
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   165
    Args:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   166
      entity: a model entity
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   167
      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
   168
          properties and their values
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   169
      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
   170
          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
   171
      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
   172
    """
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   173
3059
14421976288a The work_submission model's update now reflected in views and logic.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2979
diff changeset
   174
    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
   175
        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
   176
    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
   177
        ghop_work_submission_logic
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   178
    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
   179
    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
   180
        ghop_work_submission_model
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   181
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   182
    if entity_properties:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   183
      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
   184
                                           silent=silent, store=False)
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   185
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   186
    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
   187
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   188
    ws_entity = None
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   189
    if ws_properties:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   190
      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
   191
          **ws_properties)
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   192
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   193
    def comment_create():
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   194
      """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
   195
      WorkSubmission.
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   196
      """
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   197
      entity.put()
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   198
      if ws_entity:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   199
        ws_entity.put()
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   200
        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
   201
            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
   202
        comment_entity.put()
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   203
        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
   204
      else:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   205
        comment_entity.put()
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   206
        return entity, comment_entity, None
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   207
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   208
    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
   209
        comment_create)
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   210
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   211
    if not silent:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   212
      # 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
   213
      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
   214
        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
   215
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   216
      if ws_entity:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   217
        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
   218
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   219
    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
   220
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   221
  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
   222
    """See base.Logic.updateOrCreateFromFields().
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   223
    """
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   224
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   225
    # 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
   226
    if properties['status'] == 'Open':
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   227
      history = {
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   228
          'title': properties['title'],
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   229
          'description': properties['description'],
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   230
          'difficulty': properties['difficulty']['tags'],
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   231
          'task_type': properties['type_tags'],
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   232
          '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
   233
          '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
   234
          'user': '',
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   235
          'student': '',
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   236
          'status': properties['status'],
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   237
          'deadline': '',
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   238
          '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
   239
          '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
   240
          }
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   241
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   242
      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
   243
        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
   244
        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
   245
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   246
      # 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
   247
      # 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
   248
      # a JSON string.
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   249
      task_history_str = simplejson.dumps({
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   250
          str(datetime.datetime.now()): history,
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
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   253
      # 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
   254
      history_property = {
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   255
          'history': task_history_str
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   256
          }
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   257
      properties.update(history_property)
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
    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
   260
3092
beeb5d111318 Changes in tags are saved to the data store.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3091
diff changeset
   261
    self.tags_service.setTagValuesForEntity(entity, properties)
2823
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   262
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   263
    return entity
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
  def getFromKeyFieldsWithCWSOr404(self, fields):
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   266
    """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
   267
    specified by the fields argument.
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   268
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   269
    For args see base.getFromKeyFieldsOr404().
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   270
    """
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   271
3059
14421976288a The work_submission model's update now reflected in views and logic.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2979
diff changeset
   272
    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
   273
        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
   274
    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
   275
        ghop_work_submission_logic
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   276
 
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   277
    entity = self.getFromKeyFieldsOr404(fields)
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   278
3059
14421976288a The work_submission model's update now reflected in views and logic.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2979
diff changeset
   279
    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
   280
        ancestors=[entity], order=['created_on'])
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   281
3059
14421976288a The work_submission model's update now reflected in views and logic.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2979
diff changeset
   282
    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
   283
        ancestors=[entity], order=['submitted_on'])
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   284
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   285
    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
   286
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   287
  def updateTaskStatus(self, entity):
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   288
    """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
   289
    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
   290
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   291
    Args:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   292
      entity: The GHOPTask entity
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
    Returns:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   295
      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
   296
    """
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   297
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   298
    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
   299
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   300
    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
   301
      # 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
   302
      # task's current state
2831
a7ed56911653 STATE_TRANSITIONS dictionary values are changed to strings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2823
diff changeset
   303
      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
   304
      update_dict = transit_func(entity)
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   305
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   306
      comment_properties = {
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   307
          'parent': entity,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   308
          'scope_path': entity.key().name(),
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   309
          'created_by': None,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   310
          'content': update_dict['content'],
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   311
          'changes': update_dict['changes'],
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
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   314
      entity, comment_entity, _ = self.updateEntityPropertiesWithCWS(
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   315
          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
   316
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   317
      if entity.deadline:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   318
        # 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
   319
        task_update.spawnUpdateTask(entity)
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   320
    else:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   321
      comment_entity=None
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   322
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   323
    return entity, comment_entity
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
  def transitFromClaimed(self, entity):
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   326
    """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
   327
    to a relevant state.
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
    Args:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   330
      entity: The GHOPTask entity
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   331
    """
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
    # 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
   334
    deadline = entity.deadline + datetime.timedelta(
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   335
        hours=24)
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
    properties = {
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   338
        'status': 'ActionNeeded',
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   339
        'deadline': deadline,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   340
        }
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
    changes = [ugettext('User-MelangeAutomatic'),
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   343
               ugettext('Action-Warned for action'),
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   344
               ugettext('Status-%s' % (properties['status']))]
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   345
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   346
    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
   347
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   348
    update_dict = {
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   349
        'properties': properties,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   350
        'changes': changes,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   351
        'content': content,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   352
        }
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   353
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   354
    return update_dict
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
  def transitFromNeedsReview(self, entity):
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   357
    """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
   358
    to a relevant state.
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
    Args:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   361
      entity: The GHOPTask entity
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
    properties = {
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   365
        'deadline': None,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   366
        }
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
    changes = [ugettext('User-MelangeAutomatic'),
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   369
               ugettext('Action-Deadline passed'),
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   370
               ugettext('Status-%s' % (entity.status))]
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   371
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   372
    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
   373
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   374
    update_dict = {
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   375
        'properties': properties,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   376
        'changes': changes,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   377
        'content': content,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   378
        }
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   379
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   380
    return update_dict
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
  def transitFromActionNeeded(self, entity):
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   383
    """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
   384
    to a relevant state.
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
    Args:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   387
      entity: The GHOPTask entity
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   388
    """
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   389
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   390
    properties = {
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   391
        'user': None,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   392
        'student': None,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   393
        'status': 'Reopened',
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   394
        'deadline': None,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   395
        }
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
    changes = [ugettext('User-MelangeAutomatic'),
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   398
               ugettext('Action-Forcibly reopened'),
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   399
               ugettext('Status-Reopened')]
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   400
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   401
    content = self.DEF_REOPENED_MSG
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   402
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   403
    update_dict = {
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   404
        'properties': properties,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   405
        'changes': changes,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   406
        'content': content,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   407
        }
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   408
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   409
    return update_dict
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
  def transitFromNeedsWork(self, entity):
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   412
    """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
   413
    to a relevant state.
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
    Args:
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   416
      entity: The GHOPTask entity
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   417
    """
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   418
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   419
    properties = {
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   420
        'user': None,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   421
        'student': None,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   422
        'status': 'Reopened',
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   423
        'deadline': None,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   424
        }
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
    changes = [ugettext('User-MelangeAutomatic'),
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   427
               ugettext('Action-Forcibly reopened'),
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   428
               ugettext('Status-Reopened')]
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   429
    
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   430
    update_dict = {
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   431
        'properties': properties,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   432
        'changes': changes,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   433
        'content': None,
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   434
        }
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   435
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   436
    return update_dict
21c222535654 Added several methods to the Task Logic module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2407
diff changeset
   437
3091
a48f4e860f7b Tasks may be deleted by pressing 'Delete' button on the edit view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3080
diff changeset
   438
  def delete(self, entity):
a48f4e860f7b Tasks may be deleted by pressing 'Delete' button on the edit view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3080
diff changeset
   439
    """Delete existing entity from datastore.
a48f4e860f7b Tasks may be deleted by pressing 'Delete' button on the edit view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3080
diff changeset
   440
    """
a48f4e860f7b Tasks may be deleted by pressing 'Delete' button on the edit view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3080
diff changeset
   441
    
a48f4e860f7b Tasks may be deleted by pressing 'Delete' button on the edit view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3080
diff changeset
   442
    def task_delete_txn(entity):
a48f4e860f7b Tasks may be deleted by pressing 'Delete' button on the edit view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3080
diff changeset
   443
      """Performs all necessary operations in a single transaction when a task
a48f4e860f7b Tasks may be deleted by pressing 'Delete' button on the edit view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3080
diff changeset
   444
      is deleted.
a48f4e860f7b Tasks may be deleted by pressing 'Delete' button on the edit view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3080
diff changeset
   445
      """
a48f4e860f7b Tasks may be deleted by pressing 'Delete' button on the edit view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3080
diff changeset
   446
a48f4e860f7b Tasks may be deleted by pressing 'Delete' button on the edit view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3080
diff changeset
   447
      to_delete = []    
a48f4e860f7b Tasks may be deleted by pressing 'Delete' button on the edit view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3080
diff changeset
   448
      to_delete += ghop_comment_logic.logic.getForFields(ancestors=[entity])
a48f4e860f7b Tasks may be deleted by pressing 'Delete' button on the edit view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3080
diff changeset
   449
      to_delete += [entity]
a48f4e860f7b Tasks may be deleted by pressing 'Delete' button on the edit view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3080
diff changeset
   450
    
a48f4e860f7b Tasks may be deleted by pressing 'Delete' button on the edit view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3080
diff changeset
   451
      db.delete(to_delete)
a48f4e860f7b Tasks may be deleted by pressing 'Delete' button on the edit view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3080
diff changeset
   452
  
a48f4e860f7b Tasks may be deleted by pressing 'Delete' button on the edit view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3080
diff changeset
   453
    self.tags_service.removeAllTagsForEntity(entity)
a48f4e860f7b Tasks may be deleted by pressing 'Delete' button on the edit view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3080
diff changeset
   454
    db.run_in_transaction(task_delete_txn, entity)
a48f4e860f7b Tasks may be deleted by pressing 'Delete' button on the edit view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3080
diff changeset
   455
2401
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   456
bf70c5a0ef66 Added logic for every GHOP specific model.
Madhusudan C.S. <madhusudancs@gmail.com>
parents:
diff changeset
   457
logic = Logic()