<commit_before>#!/usr/bin/env python2.5
#
# Copyright 2009 the Melange authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Appengine Tasks related to GCI Task handling.
"""

__authors__ = [
    '"Madhusudan.C.S" <<EMAIL>>',
    '"<NAME>" <<EMAIL>>',
  ]


import datetime

from google.appengine.api.labs import taskqueue
from google.appengine.ext import db

from django import http
from django.utils.translation import ugettext

from soc.logic import system
from soc.tasks import responses as task_reponses
from soc.tasks.helper import error_handler
from soc.views.helper import redirects

from soc.modules.gci.logic.models import task as gci_task_logic
from soc.modules.gci.tasks import ranking_update


DEF_TASK_UPDATE_SUBJECT_FMT = ugettext(
    '[%(program_name)s Task Update] %(title)s')


def getDjangoURLPatterns():
  """Returns the URL patterns for the tasks in this module.
  """

  patterns = [
      (r'^tasks/gci/task/update$',
       'soc.modules.gci.tasks.task_update.updateGCITask'),
      (r'^tasks/gci/task/mail/create$',
       'soc.modules.gci.tasks.task_update.createNotificationMail'),
      (r'^tasks/gci/task/update/student_status$',
       'soc.modules.gci.tasks.task_update.updateTasksPostStudentSignUp')]

  return patterns


def spawnUpdateTask(entity):
  """Spawns a task to update the state of the task. 
  """

  update_params = {
      'gci_task_key': entity.key().name(),
      }
  update_url = '/tasks/gci/task/update'

  new_task = taskqueue.Task(eta=entity.deadline,
                            params=update_params,
                            url=update_url)
  new_task.add('gci-update')


def updateGCITask(request, *args, **kwargs):
  """Method executed by Task Queue API to update a GCI Task to
  relevant state.

  Expects the gci_task_key entry to be present in the POST dict.

  Args:
    request: the standard Django HTTP request object 
  """

  post_dict = request.POST

  key_name = post_dict.get('gci_task_key')

  if not key_name:
    # invalid task data, log and return OK
    return error_handler.logErrorAndReturnOK(
        'Invalid updateGCITask data: %s' % post_dict)

  entity = gci_task_logic.logic.getFromKeyNameOr404(key_name)

  entity, comment_entity = gci_task_logic.logic.updateTaskStatus(entity)

  if entity:
    # TODO(madhusudan): does this really mean an unsuccessful update?
    # return OK
    return http.HttpResponse()<commit_msg>Do not keep retrying if entity cannot be found<commit_after>#!/usr/bin/env python2.5
#
# Copyright 2009 the Melange authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Appengine Tasks related to GCI Task handling.
"""

__authors__ = [
    '"Madhusudan.C.S" <<EMAIL>>',
    '"<NAME>" <<EMAIL>>',
  ]


import datetime

from google.appengine.api.labs import taskqueue
from google.appengine.ext import db

from django import http
from django.utils.translation import ugettext

from soc.logic import system
from soc.tasks import responses as task_reponses
from soc.tasks.helper import error_handler
from soc.views.helper import redirects

from soc.modules.gci.logic.models import task as gci_task_logic
from soc.modules.gci.tasks import ranking_update


DEF_TASK_UPDATE_SUBJECT_FMT = ugettext(
    '[%(program_name)s Task Update] %(title)s')


def getDjangoURLPatterns():
  """Returns the URL patterns for the tasks in this module.
  """

  patterns = [
      (r'^tasks/gci/task/update$',
       'soc.modules.gci.tasks.task_update.updateGCITask'),
      (r'^tasks/gci/task/mail/create$',
       'soc.modules.gci.tasks.task_update.createNotificationMail'),
      (r'^tasks/gci/task/update/student_status$',
       'soc.modules.gci.tasks.task_update.updateTasksPostStudentSignUp')]

  return patterns


def spawnUpdateTask(entity):
  """Spawns a task to update the state of the task. 
  """

  update_params = {
      'gci_task_key': entity.key().name(),
      }
  update_url = '/tasks/gci/task/update'

  new_task = taskqueue.Task(eta=entity.deadline,
                            params=update_params,
                            url=update_url)
  new_task.add('gci-update')


def updateGCITask(request, *args, **kwargs):
  """Method executed by Task Queue API to update a GCI Task to
  relevant state.

  Expects the gci_task_key entry to be present in the POST dict.

  Args:
    request: the standard Django HTTP request object 
  """

  post_dict = request.POST

  key_name = post_dict.get('gci_task_key')

  if not key_name:
    # invalid task data, log and return OK
    return error_handler.logErrorAndReturnOK(
        'Invalid updateGCITask data: %s' % post_dict)

  entity = gci_task_logic.logic.getFromKeyName(key_name)

  if not entity:
    # invalid task data, log and return OK
    return error_handler.logErrorAndReturnOK(
        'Invalid updateGCITask gci_task_key: %s' % post_dict)

  entity, comment_entity = gci_task_logic.logic.updateTaskStatus(entity)

  if entity:
    # TODO(madhusudan): does this really mean an unsuccessful update?
    # return OK
    return http.HttpResponse()
{'fraction_non_alphanumeric': 0.09665613042754949, 'fraction_numerical': 0.003826318416236899, 'mean_word_length': 3.6677018633540373, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3419640', 'n_tokens_mistral': 1908, 'n_tokens_neox': 1832, 'n_words': 563}