app/soc/modules/ghop/tasks/task_update.py
author Madhusudan.C.S <madhusudancs@gmail.com>
Thu, 27 Aug 2009 11:13:52 +0200
changeset 2817 c31428f08daa
child 2826 211783aa20d5
permissions -rw-r--r--
Added GAE tasks that are related to updating GHOP Tasks. Several TODO's have been added. Also note that some functionality that is being used here is under construction and is being integrated asap. That's the price to pay for cleaner integration commits I guess :). Reviewed by: Lennard de Rijk
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2817
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     2
#
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     3
# Copyright 2009 the Melange authors.
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     4
#
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     8
#
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    10
#
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    16
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    17
"""Appengine Tasks related to GHOP Task handling.
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    18
"""
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    19
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    20
__authors__ = [
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    21
    '"Madhusudan.C.S" <madhusudancs@gmail.com>'
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    22
  ]
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    23
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    24
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    25
import logging
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    26
import os
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    27
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    28
from google.appengine.api.labs import taskqueue
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    29
from google.appengine.ext import db
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    30
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    31
from django import http
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    32
from django.utils.translation import ugettext
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    33
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    34
from soc.tasks.helper import error_handler
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    35
from soc.views.helper import redirects
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    36
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    37
from soc.modules.ghop.logic.models import task as ghop_task_logic
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    38
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    39
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    40
DEF_TASK_UPDATE_SUBJECT_FMT = ugettext('[GHOP Task Update] %(title)s')
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    41
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    42
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    43
def getDjangoURLPatterns():
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    44
  """Returns the URL patterns for the tasks in this module.
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    45
  """
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    46
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    47
  patterns = [
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    48
      (r'^tasks/ghop/task/update$',
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    49
       'soc.modules.ghop.tasks.task_update.updateGHOPTask'),
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    50
      (r'^tasks/ghop/task/update/student_status$',
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    51
       'soc.modules.ghop.tasks.task_update.updateTasksPostStudentSignUp')]
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    52
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    53
  return patterns
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    54
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    55
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    56
def spawnUpdateTask(entity):
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    57
  """Spawns a task to update the state of the task. 
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    58
  """
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    59
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    60
  update_params = {
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    61
      'ghop_task_key': entity.key().name(),
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    62
      }
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    63
  update_url = '/tasks/ghop/task/update'
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    64
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    65
  new_task = taskqueue.Task(eta=entity.deadline, 
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    66
                            params=update_params,
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    67
                            url=update_url)
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    68
  new_task.add('ghop-update')
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    69
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    70
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    71
def updateGHOPTask(request, *args, **kwargs):
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    72
  """Method executed by Task Queue API to update a GHOP Task to
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    73
  relevant state.
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    74
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    75
  Expects the ghop_task_key entry to be present in the POST dict.
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    76
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    77
  Args:
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    78
    request: the standard Django HTTP request object 
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    79
  """
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    80
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    81
  post_dict = request.POST
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    82
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    83
  key_name = post_dict.get('ghop_task_key')
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    84
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    85
  if not key_name:
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    86
    # invalid task data, log and return OK
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    87
    return error_handler.logErrorAndReturnOK(
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    88
        'Invalid updateGHOPTask data: %s' % post_dict)
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    89
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    90
  entity = ghop_task_logic.logic.getFromKeyNameOr404(key_name)
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    91
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    92
  entity, comment_entity, ws_entity = ghop_task_logic.logic.updateTaskStatus(
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    93
      entity)
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    94
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    95
  if entity:
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    96
    # TODO(madhusudan): does this really mean an unsuccessful update?
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    97
    # return OK
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    98
    return http.HttpResponse()
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    99
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   100
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   101
def updateTasksPostStudentSignUp(request, *args, **kwargs):
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   102
  """Appengine task that updates the GHOP Tasks after the student signs up.
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   103
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   104
  Expects the following to be present in the POST dict:
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   105
    student_key: Specifies the student key name who registered
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   106
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   107
  Args:
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   108
    request: Django Request object
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   109
  """
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   110
  from soc.modules.ghop.logic.models import student as ghop_student_logic
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   111
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   112
  post_dict = request.POST
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   113
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   114
  student_key = post_dict.get('student_key')
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   115
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   116
  if not student_key:
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   117
    # invalid student data, log and return OK
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   118
    return error_handler.logErrorAndReturnOK(
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   119
        'Invalid Student data: %s' % post_dict)
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   120
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   121
  student_entity = ghop_student_logic.logic.getFromKeyNameOr404(student_key)
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   122
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   123
  # retrieve all tasks currently assigned to the user
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   124
  task_fields = {
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   125
      'user': student_entity.user,
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   126
      }
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   127
  task_entities = ghop_task_logic.logic.getForFields(task_fields)
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   128
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   129
  # TODO(madhusudan) move this to the Task Logic
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   130
  # Make sure the tasks store references to the student as well as
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   131
  # closing all tasks that are AwaitingRegistration.
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   132
  for task_entity in task_entities:
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   133
    task_entity.student = student_entity
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   134
    if task_entity.status == 'AwaitingRegistration':
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   135
      task_entities.remove(task_entity)
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   136
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   137
      properties = {'status': 'Closed'}
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   138
      changes = [ugettext('User-MelangeAutomatic'),
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   139
                 ugettext('Action-Student registered'),
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   140
                 ugettext('Status-%s' % (properties['status']))]
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   141
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   142
      comment_properties = {
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   143
          'parent': task_entity,
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   144
          'scope_path': task_entity.key().name(),
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   145
          'created_by': None,
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   146
          'changes': changes,
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   147
          'content': ugettext(
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   148
              '(The Melange Automated System has detected that the student '
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   149
              'has signed up for the program and hence has closed this task.'),
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   150
          }
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   151
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   152
      ghop_task_logic.logic.updateEntityPropertiesWithCWS(
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   153
          task_entity, properties, comment_properties)
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   154
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   155
  db.put(task_entities)
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   156
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   157
  # return OK
c31428f08daa Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   158
  return http.HttpResponse()