app/soc/tasks/updates/module_conversion.py
author Lennard de Rijk <ljvderijk@gmail.com>
Mon, 26 Oct 2009 15:38:13 -0700
changeset 3063 0b69dd9a5252
parent 3025 1ffc7cd7309c
permissions -rw-r--r--
Module Conversion also changes the RankerRoots associated with an Organization.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2973
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     2
#
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     3
# Copyright 2009 the Melange authors.
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     4
#
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     8
#
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    10
#
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    16
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    17
"""The module conversion updates are defined in this module.
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    18
"""
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    19
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    20
__authors__ = [
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    21
  '"Lennard de Rijk" <ljvderijk@gmail.com>',
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    22
  ]
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    23
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    24
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    25
from google.appengine.api.labs import taskqueue
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    26
from google.appengine.ext import db
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    27
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    28
from django.http import HttpResponse
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    29
3008
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
    30
from soc.logic.models import survey as survey_logic
3009
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
    31
from soc.logic.models import survey_record as survey_record_logic
3019
f106f825c4c9 Fixed module conversion imports.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3014
diff changeset
    32
from soc.logic.models.document import logic as document_logic
3021
baeb847b88e6 Added GradingSurveyGroup update to the Module Conversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3020
diff changeset
    33
from soc.logic.models.grading_survey_group import logic as \
baeb847b88e6 Added GradingSurveyGroup update to the Module Conversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3020
diff changeset
    34
    grading_survey_group_logic
2998
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
    35
from soc.logic.models.mentor import logic as mentor_logic
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
    36
from soc.logic.models.org_admin import logic as org_admin_logic
2997
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
    37
from soc.logic.models.organization import logic as org_logic
3000
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
    38
from soc.logic.models.program import logic as program_logic
3006
e74c4d37a61a Added Review module conversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3001
diff changeset
    39
from soc.logic.models.review import logic as review_logic
3000
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
    40
from soc.logic.models.student import logic as student_logic
3007
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
    41
from soc.logic.models.student_project import logic as student_project_logic
3014
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
    42
from soc.logic.models.student_proposal import logic as student_proposal_logic
3011
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
    43
from soc.logic.models.timeline import logic as timeline_logic
2996
9a62e3cad4a8 Use the iterative task iterator for the ProgramConversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2973
diff changeset
    44
from soc.tasks.helper import decorators
2973
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    45
from soc.tasks.helper import error_handler
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    46
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    47
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    48
# batch size to use when going through the entities
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    49
DEF_BATCH_SIZE = 10
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    50
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    51
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    52
def startUpdateWithUrl(request, task_url):
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    53
  """Spawns an update task for the given task URL.
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    54
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    55
  Args:
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    56
    request: Django Request object
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    57
    task_url: The URL used to run this update task
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    58
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    59
  Returns:
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    60
    True iff the new task is successfully added to the Task Queue API
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    61
  """
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    62
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    63
  new_task = taskqueue.Task(url=task_url)
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    64
  new_task.add()
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    65
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    66
  return True
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    67
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    68
2996
9a62e3cad4a8 Use the iterative task iterator for the ProgramConversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2973
diff changeset
    69
@decorators.iterative_task(program_logic)
9a62e3cad4a8 Use the iterative task iterator for the ProgramConversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2973
diff changeset
    70
def runProgramConversionUpdate(request, entities, context, *args, **kwargs):
2998
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
    71
  """AppEngine Task that converts Programs into GSoCPrograms.
2973
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    72
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    73
  Args:
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    74
    request: Django Request object
2996
9a62e3cad4a8 Use the iterative task iterator for the ProgramConversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2973
diff changeset
    75
    entities: list of Program entities to convert
9a62e3cad4a8 Use the iterative task iterator for the ProgramConversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2973
diff changeset
    76
    context: the context of this task
2973
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    77
  """
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    78
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    79
  from soc.modules.gsoc.models.program import GSoCProgram
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    80
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    81
  # get all the properties that are part of each Programs
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    82
  program_model = program_logic.getModel()
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    83
  program_properties = program_model.properties().keys()
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    84
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    85
  # use this to store all the new GSoCPrograms
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    86
  gsoc_programs = []
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    87
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    88
  for entity in entities:
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    89
    gsoc_properties = {}
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    90
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    91
    for program_property in program_properties:
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    92
      # copy over all the information from the program entity
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    93
      gsoc_properties[program_property] = getattr(entity, program_property)
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    94
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    95
    # create the new GSoCProgram entity and prepare it to be stored
2997
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
    96
    gsoc_program_entity = GSoCProgram(key_name=entity.key().name(),
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
    97
                                      **gsoc_properties)
2973
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    98
    gsoc_programs.append(gsoc_program_entity)
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    99
2999
d933a6da5eef Only store all the entities once in the ModuleConversion, after the for loop.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2998
diff changeset
   100
  # store all the new GSoCPrograms
d933a6da5eef Only store all the entities once in the ModuleConversion, after the for loop.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2998
diff changeset
   101
  db.put(gsoc_programs)
2973
ba3f2522e8df Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   102
2996
9a62e3cad4a8 Use the iterative task iterator for the ProgramConversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2973
diff changeset
   103
  # task completed, return
9a62e3cad4a8 Use the iterative task iterator for the ProgramConversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2973
diff changeset
   104
  return
2997
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   105
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   106
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   107
@decorators.iterative_task(org_logic)
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   108
def runOrgConversionUpdate(request, entities, context, *args, **kwargs):
2998
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   109
  """AppEngine Task that converts Organizations into GSoCOrganizations.
2997
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   110
3063
0b69dd9a5252 Module Conversion also changes the RankerRoots associated with an Organization.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3025
diff changeset
   111
  Also updates the RankerRoots that are associated with the Organization.
0b69dd9a5252 Module Conversion also changes the RankerRoots associated with an Organization.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3025
diff changeset
   112
2997
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   113
  Args:
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   114
    request: Django Request object
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   115
    entities: list of Organization entities to convert
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   116
    context: the context of this task
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   117
  """
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   118
3063
0b69dd9a5252 Module Conversion also changes the RankerRoots associated with an Organization.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3025
diff changeset
   119
  from soc.logic.models.ranker_root import logic as ranker_root_logic
0b69dd9a5252 Module Conversion also changes the RankerRoots associated with an Organization.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3025
diff changeset
   120
2997
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   121
  from soc.modules.gsoc.logic.models.program import logic as gsoc_program_logic
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   122
  from soc.modules.gsoc.models.organization import GSoCOrganization
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   123
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   124
  # get all the properties that are part of each Organization
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   125
  org_model = org_logic.getModel()
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   126
  org_properties = org_model.properties().keys()
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   127
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   128
  # use this to store all the new GSoCOrganization
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   129
  gsoc_orgs = []
3063
0b69dd9a5252 Module Conversion also changes the RankerRoots associated with an Organization.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3025
diff changeset
   130
  gsoc_rankers = []
2997
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   131
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   132
  for entity in entities:
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   133
    gsoc_properties = {}
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   134
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   135
    for org_property in org_properties:
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   136
      # copy over all the information from the Organization entity
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   137
      gsoc_properties[org_property] = getattr(entity, org_property)
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   138
3001
1698cca3d912 Only set new properties outside the "properties" loop for the ModuleConversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3000
diff changeset
   139
    # get the Program key belonging to the old Organization
1698cca3d912 Only set new properties outside the "properties" loop for the ModuleConversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3000
diff changeset
   140
    program_key = entity.scope.key().id_or_name()
1698cca3d912 Only set new properties outside the "properties" loop for the ModuleConversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3000
diff changeset
   141
    # get the new GSoCProgram and set it as scope for the GSoCOrganzation
1698cca3d912 Only set new properties outside the "properties" loop for the ModuleConversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3000
diff changeset
   142
    gsoc_program = gsoc_program_logic.getFromKeyName(program_key)
1698cca3d912 Only set new properties outside the "properties" loop for the ModuleConversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3000
diff changeset
   143
    gsoc_properties['scope'] = gsoc_program
2997
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   144
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   145
    # create the new GSoCOrganization entity and prepare it to be stored
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   146
    gsoc_org_entity = GSoCOrganization(key_name=entity.key().name(),
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   147
                                       **gsoc_properties)
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   148
    gsoc_orgs.append(gsoc_org_entity)
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   149
3063
0b69dd9a5252 Module Conversion also changes the RankerRoots associated with an Organization.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3025
diff changeset
   150
    # retrieve the RankerRoots belonging to the Organization
0b69dd9a5252 Module Conversion also changes the RankerRoots associated with an Organization.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3025
diff changeset
   151
    fields = {'scope': entity}
0b69dd9a5252 Module Conversion also changes the RankerRoots associated with an Organization.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3025
diff changeset
   152
    rankers = ranker_root_logic.getForFields(fields)
0b69dd9a5252 Module Conversion also changes the RankerRoots associated with an Organization.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3025
diff changeset
   153
0b69dd9a5252 Module Conversion also changes the RankerRoots associated with an Organization.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3025
diff changeset
   154
    for ranker in rankers:
0b69dd9a5252 Module Conversion also changes the RankerRoots associated with an Organization.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3025
diff changeset
   155
      ranker.scope = gsoc_org_entity
0b69dd9a5252 Module Conversion also changes the RankerRoots associated with an Organization.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3025
diff changeset
   156
      # append the adjusted ranker
0b69dd9a5252 Module Conversion also changes the RankerRoots associated with an Organization.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3025
diff changeset
   157
      gsoc_rankers.append(ranker)
0b69dd9a5252 Module Conversion also changes the RankerRoots associated with an Organization.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3025
diff changeset
   158
2999
d933a6da5eef Only store all the entities once in the ModuleConversion, after the for loop.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2998
diff changeset
   159
  # store all the new GSoCOrganizations
d933a6da5eef Only store all the entities once in the ModuleConversion, after the for loop.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2998
diff changeset
   160
  db.put(gsoc_orgs)
3063
0b69dd9a5252 Module Conversion also changes the RankerRoots associated with an Organization.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3025
diff changeset
   161
  # store all the new rankers
0b69dd9a5252 Module Conversion also changes the RankerRoots associated with an Organization.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3025
diff changeset
   162
  db.put(gsoc_rankers)
2997
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   163
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   164
  # task completed, return
a7cb53d213d7 Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2996
diff changeset
   165
  return
2998
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   166
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   167
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   168
@decorators.iterative_task(org_admin_logic)
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   169
def runOrgAdminConversionUpdate(request, entities, context, *args, **kwargs):
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   170
  """AppEngine Task that converts OrgAdmins into GSoCOrgAdmins.
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   171
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   172
  Args:
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   173
    request: Django Request object
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   174
    entities: list of OrgAdmin entities to convert
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   175
    context: the context of this task
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   176
  """
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   177
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   178
  from soc.modules.gsoc.models.org_admin import GSoCOrgAdmin
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   179
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   180
  return _runOrgRoleConversionUpdate(entities, org_admin_logic, GSoCOrgAdmin)
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   181
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   182
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   183
@decorators.iterative_task(mentor_logic)
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   184
def runMentorConversionUpdate(request, entities, context, *args, **kwargs):
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   185
  """AppEngine Task that converts Mentors into GSoCMentors.
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   186
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   187
  Args:
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   188
    request: Django Request object
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   189
    entities: list of Mentor entities to convert
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   190
    context: the context of this task
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   191
  """
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   192
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   193
  from soc.modules.gsoc.models.mentor import GSoCMentor
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   194
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   195
  return _runOrgRoleConversionUpdate(entities, mentor_logic, GSoCMentor)
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   196
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   197
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   198
def _runOrgRoleConversionUpdate(entities, from_role_logic, to_role_model):
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   199
  """AppEngine Task that converts a normal Organization Role into a
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   200
  GSoCOrganization Role.
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   201
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   202
  Args:
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   203
    entities: Role entities to convert
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   204
    from_role_logic: the Role Logic instance where to convert from
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   205
    to_role_model: the role Model class where to convert to
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   206
  """
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   207
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   208
  from soc.modules.gsoc.logic.models.organization import logic as \
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   209
      gsoc_org_logic
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   210
  from soc.modules.gsoc.logic.models.program import logic as gsoc_program_logic
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   211
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   212
  # get all the properties that are part of each Organization's Role
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   213
  role_model = from_role_logic.getModel()
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   214
  role_properties = role_model.properties().keys()
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   215
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   216
  # use this to store all the new Roles
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   217
  gsoc_roles = []
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   218
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   219
  for entity in entities:
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   220
    gsoc_properties = {}
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   221
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   222
    for role_property in role_properties:
3000
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   223
      # copy over all the information from the Role entity
2998
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   224
      gsoc_properties[role_property] = getattr(entity, role_property)
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   225
3001
1698cca3d912 Only set new properties outside the "properties" loop for the ModuleConversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3000
diff changeset
   226
    # get the Program key belonging to the old Role
1698cca3d912 Only set new properties outside the "properties" loop for the ModuleConversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3000
diff changeset
   227
    program_key = entity.program.key().id_or_name()
1698cca3d912 Only set new properties outside the "properties" loop for the ModuleConversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3000
diff changeset
   228
    # get the new GSoCProgram and set it for the Role
1698cca3d912 Only set new properties outside the "properties" loop for the ModuleConversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3000
diff changeset
   229
    gsoc_program = gsoc_program_logic.getFromKeyName(program_key)
1698cca3d912 Only set new properties outside the "properties" loop for the ModuleConversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3000
diff changeset
   230
    gsoc_properties['program'] = gsoc_program
2998
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   231
3001
1698cca3d912 Only set new properties outside the "properties" loop for the ModuleConversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3000
diff changeset
   232
    # get the Organization key belonging to the old Role
1698cca3d912 Only set new properties outside the "properties" loop for the ModuleConversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3000
diff changeset
   233
    org_key = entity.scope.key().id_or_name()
1698cca3d912 Only set new properties outside the "properties" loop for the ModuleConversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3000
diff changeset
   234
    # get the new GSoCOrganization and set it as scope for the Role
1698cca3d912 Only set new properties outside the "properties" loop for the ModuleConversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3000
diff changeset
   235
    gsoc_org = gsoc_org_logic.getFromKeyName(org_key)
1698cca3d912 Only set new properties outside the "properties" loop for the ModuleConversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3000
diff changeset
   236
    gsoc_properties['scope'] = gsoc_org
2998
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   237
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   238
    # create the new GSoC Role entity and prepare it to be stored
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   239
    gsoc_role_entity = to_role_model(key_name=entity.key().name(),
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   240
                                        **gsoc_properties)
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   241
    gsoc_roles.append(gsoc_role_entity)
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   242
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   243
  # store all the new GSoC Roles
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   244
  db.put(gsoc_roles)
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   245
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   246
  # task completed, return
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   247
  return
9c34768346da Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2997
diff changeset
   248
3000
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   249
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   250
@decorators.iterative_task(student_logic)
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   251
def runStudentConversionUpdate(request, entities, context, *args, **kwargs):
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   252
  """AppEngine Task that converts Students into GSoCStudents.
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   253
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   254
  Args:
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   255
    request: Django Request object
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   256
    entities: list of Student entities to convert
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   257
    context: the context of this task
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   258
  """
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   259
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   260
  from soc.modules.gsoc.logic.models.program import logic as gsoc_program_logic
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   261
  from soc.modules.gsoc.models.student import GSoCStudent
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   262
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   263
  # get all the properties that are part of each Student
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   264
  student_model = student_logic.getModel()
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   265
  student_properties = student_model.properties().keys()
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   266
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   267
  # use this to store all the new GSoCStudents
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   268
  gsoc_students = []
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   269
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   270
  for entity in entities:
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   271
    gsoc_properties = {}
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   272
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   273
    for student_property in student_properties:
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   274
      # copy over all the information from the Student entity
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   275
      gsoc_properties[student_property] = getattr(entity, student_property)
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   276
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   277
    # get the Program key belonging to the old Student
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   278
    program_key = entity.scope.key().id_or_name()
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   279
    # get the new GSoCProgram and set it as scope for the GSoCStudent
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   280
    gsoc_program = gsoc_program_logic.getFromKeyName(program_key)
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   281
    gsoc_properties['scope'] = gsoc_program
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   282
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   283
    # create the new GSoCStudent entity and prepare it to be stored
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   284
    gsoc_student_entity = GSoCStudent(key_name=entity.key().name(),
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   285
                                      **gsoc_properties)
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   286
    gsoc_students.append(gsoc_student_entity)
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   287
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   288
  # store all the new GSoCStudents
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   289
  db.put(gsoc_students)
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   290
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   291
  # task completed, return
733d07eac729 Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2999
diff changeset
   292
  return
3006
e74c4d37a61a Added Review module conversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3001
diff changeset
   293
e74c4d37a61a Added Review module conversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3001
diff changeset
   294
3014
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   295
@decorators.iterative_task(student_proposal_logic)
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   296
def runStudentProposalUpdate(request, entities, context, *args, **kwargs):
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   297
  """AppEngine Task that updates StudentProposal entities.
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   298
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   299
  Args:
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   300
    request: Django Request object
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   301
    entities: list of StudentProposal entities to update
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   302
    context: the context of this task
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   303
  """
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   304
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   305
  from soc.modules.gsoc.logic.models.mentor import logic as mentor_logic
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   306
  from soc.modules.gsoc.logic.models.organization import logic as org_logic
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   307
  from soc.modules.gsoc.logic.models.program import logic as program_logic
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   308
  from soc.modules.gsoc.logic.models.student import logic as student_logic
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   309
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   310
  for entity in entities:
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   311
    entity.scope = student_logic.getFromKeyName(
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   312
        entity.scope.key().id_or_name())
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   313
    entity.org = org_logic.getFromKeyName(entity.org.key().id_or_name())
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   314
    entity.program = program_logic.getFromKeyName(
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   315
        entity.program.key().id_or_name())
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   316
3020
b2c97cbba7df Fixed bug in StudentProposal update when a StudentProposal had no Mentor.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3019
diff changeset
   317
    if entity.mentor:
b2c97cbba7df Fixed bug in StudentProposal update when a StudentProposal had no Mentor.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3019
diff changeset
   318
      entity.mentor = mentor_logic.getFromKeyName(
b2c97cbba7df Fixed bug in StudentProposal update when a StudentProposal had no Mentor.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3019
diff changeset
   319
          entity.mentor.key().id_or_name())
b2c97cbba7df Fixed bug in StudentProposal update when a StudentProposal had no Mentor.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3019
diff changeset
   320
3014
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   321
    old_mentors = entity.possible_mentors
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   322
    new_mentors = []
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   323
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   324
    for old_mentor in old_mentors:
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   325
      new_mentors.append(
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   326
        mentor_logic.getFromKeyName(old_mentor.id_or_name()))
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   327
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   328
    entity.possible_mentors = new_mentors
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   329
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   330
  # store all StudentProposal
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   331
  db.put(entities)
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   332
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   333
  # task completed, return
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   334
  return
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   335
75c2410d3f85 Add StudentProposal conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3011
diff changeset
   336
3006
e74c4d37a61a Added Review module conversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3001
diff changeset
   337
@decorators.iterative_task(review_logic)
e74c4d37a61a Added Review module conversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3001
diff changeset
   338
def runReviewUpdate(request, entities, context, *args, **kwargs):
3007
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   339
  """AppEngine Task that updates Review entities.
3006
e74c4d37a61a Added Review module conversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3001
diff changeset
   340
e74c4d37a61a Added Review module conversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3001
diff changeset
   341
  Args:
e74c4d37a61a Added Review module conversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3001
diff changeset
   342
    request: Django Request object
e74c4d37a61a Added Review module conversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3001
diff changeset
   343
    entities: list of Review entities to update
e74c4d37a61a Added Review module conversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3001
diff changeset
   344
    context: the context of this task
e74c4d37a61a Added Review module conversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3001
diff changeset
   345
  """
e74c4d37a61a Added Review module conversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3001
diff changeset
   346
e74c4d37a61a Added Review module conversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3001
diff changeset
   347
  for entity in entities:
e74c4d37a61a Added Review module conversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3001
diff changeset
   348
    entity.reviewer = None
e74c4d37a61a Added Review module conversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3001
diff changeset
   349
e74c4d37a61a Added Review module conversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3001
diff changeset
   350
  # store all Reviews
e74c4d37a61a Added Review module conversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3001
diff changeset
   351
  db.put(entities)
e74c4d37a61a Added Review module conversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3001
diff changeset
   352
e74c4d37a61a Added Review module conversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3001
diff changeset
   353
  # task completed, return
3007
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   354
  return
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   355
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   356
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   357
@decorators.iterative_task(student_project_logic)
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   358
def runStudentProjectUpdate(request, entities, context, *args, **kwargs):
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   359
  """AppEngine Task that updates StudentProject entities.
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   360
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   361
  Args:
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   362
    request: Django Request object
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   363
    entities: list of StudentProject entities to update
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   364
    context: the context of this task
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   365
  """
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   366
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   367
  from soc.modules.gsoc.logic.models.mentor import logic as mentor_logic
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   368
  from soc.modules.gsoc.logic.models.organization import logic as org_logic
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   369
  from soc.modules.gsoc.logic.models.program import logic as program_logic
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   370
  from soc.modules.gsoc.logic.models.student import logic as student_logic
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   371
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   372
  for entity in entities:
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   373
    entity.scope = org_logic.getFromKeyName(entity.scope.key().id_or_name())
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   374
    entity.mentor = mentor_logic.getFromKeyName(
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   375
        entity.mentor.key().id_or_name())
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   376
    entity.student = student_logic.getFromKeyName(
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   377
        entity.student.key().id_or_name())
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   378
    entity.program = program_logic.getFromKeyName(
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   379
        entity.program.key().id_or_name())
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   380
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   381
    old_mentors = entity.additional_mentors
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   382
    new_mentors = []
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   383
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   384
    for old_mentor in old_mentors:
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   385
      new_mentors.append(
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   386
        mentor_logic.getFromKeyName(old_mentor.id_or_name()))
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   387
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   388
    entity.additional_mentors = new_mentors
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   389
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   390
  # store all StudentProjects
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   391
  db.put(entities)
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   392
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   393
  # task completed, return
d23d1dee5261 Added StudentProject update to the Module Conversion updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3006
diff changeset
   394
  return
3008
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   395
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   396
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   397
@decorators.iterative_task(survey_logic.logic)
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   398
def runSurveyUpdate(request, entities, context, *args, **kwargs):
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   399
  """AppEngine Task that updates Survey entities.
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   400
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   401
  Args:
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   402
    request: Django Request object
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   403
    entities: list of Survey entities to update
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   404
    context: the context of this task
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   405
  """
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   406
  return _runSurveyUpdate(entities)
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   407
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   408
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   409
@decorators.iterative_task(survey_logic.project_logic)
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   410
def runProjectSurveyUpdate(request, entities, context, *args, **kwargs):
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   411
  """AppEngine Task that updates ProjectSurvey entities.
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   412
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   413
  Args:
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   414
    request: Django Request object
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   415
    entities: list of ProjectSurvey entities to update
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   416
    context: the context of this task
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   417
  """
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   418
  return _runSurveyUpdate(entities)
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   419
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   420
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   421
@decorators.iterative_task(survey_logic.grading_logic)
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   422
def runGradingProjectSurveyUpdate(request, entities, context, *args, **kwargs):
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   423
  """AppEngine Task that updates GradingProjectSurvey entities.
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   424
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   425
  Args:
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   426
    request: Django Request object
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   427
    entities: list of GradingProjectSurvey entities to update
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   428
    context: the context of this task
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   429
  """
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   430
  return _runSurveyUpdate(entities)
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   431
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   432
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   433
def _runSurveyUpdate(entities):
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   434
  """AppEngine Task that updates Survey entities.
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   435
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   436
  Args:
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   437
    entities: list of Survey entities to update
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   438
  """
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   439
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   440
  from soc.modules.gsoc.logic.models.program import logic as program_logic
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   441
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   442
  for entity in entities:
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   443
    entity.scope = program_logic.getFromKeyName(
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   444
        entity.scope.key().id_or_name())
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   445
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   446
  # store all Surveys
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   447
  db.put(entities)
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   448
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   449
  # task completed, return
525c65b0a320 Added update for Surveys, ProjectSurveys and ProjectGradingSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3007
diff changeset
   450
  return
3009
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   451
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   452
3019
f106f825c4c9 Fixed module conversion imports.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3014
diff changeset
   453
@decorators.iterative_task(survey_record_logic.project_logic)
3009
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   454
def runProjectSurveyRecordUpdate(request, entities, context, *args, **kwargs):
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   455
  """AppEngine Task that updates ProjectSurveyRecord entities.
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   456
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   457
  Args:
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   458
    request: Django Request object
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   459
    entities: list of ProjectSurveyRecord entities to update
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   460
    context: the context of this task
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   461
  """
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   462
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   463
  return _runSurveyRecordUpdate(entities)
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   464
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   465
3019
f106f825c4c9 Fixed module conversion imports.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3014
diff changeset
   466
@decorators.iterative_task(survey_record_logic.grading_logic)
3023
3e9a292448a8 Renamed runGradingProjectSurveyRecordsUpdate to match style of module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3022
diff changeset
   467
def runGradingProjectSurveyRecordUpdate(request, entities, context, *args, **kwargs):
3009
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   468
  """AppEngine Task that updates GradingProjectSurveyRecord entities.
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   469
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   470
  Args:
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   471
    request: Django Request object
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   472
    entities: list of GradingProjectSurveyRecord entities to update
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   473
    context: the context of this task
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   474
  """
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   475
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   476
  return _runSurveyRecordUpdate(entities)
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   477
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   478
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   479
def _runSurveyRecordUpdate(entities):
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   480
  """AppEngine Task taht updates SurveyRecord entities.
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   481
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   482
  Args:
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   483
    entities: list of SurveyRecord entities to update 
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   484
  """
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   485
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   486
  from soc.modules.gsoc.logic.models.organization import logic as org_logic
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   487
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   488
  for entity in entities:
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   489
    entity.org = org_logic.getFromKeyName(entity.org.key().id_or_name())
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   490
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   491
  db.put(entities)
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   492
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   493
  # task completed, return
99f2d9b1ff7d Added update for SurveyRecords
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3008
diff changeset
   494
  return
3010
a0dd39fa090b Add update for Documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3009
diff changeset
   495
a0dd39fa090b Add update for Documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3009
diff changeset
   496
3021
baeb847b88e6 Added GradingSurveyGroup update to the Module Conversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3020
diff changeset
   497
@decorators.iterative_task(grading_survey_group_logic)
baeb847b88e6 Added GradingSurveyGroup update to the Module Conversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3020
diff changeset
   498
def runGradingSurveyGroupUpdate(request, entities, context, *args, **kwargs):
baeb847b88e6 Added GradingSurveyGroup update to the Module Conversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3020
diff changeset
   499
  """AppEngine Task that updates GradingSurveyGroup entities.
baeb847b88e6 Added GradingSurveyGroup update to the Module Conversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3020
diff changeset
   500
baeb847b88e6 Added GradingSurveyGroup update to the Module Conversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3020
diff changeset
   501
  Args:
baeb847b88e6 Added GradingSurveyGroup update to the Module Conversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3020
diff changeset
   502
    request: Django Request object
baeb847b88e6 Added GradingSurveyGroup update to the Module Conversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3020
diff changeset
   503
    entities: list of Document entities to update
baeb847b88e6 Added GradingSurveyGroup update to the Module Conversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3020
diff changeset
   504
    context: the context of this task
baeb847b88e6 Added GradingSurveyGroup update to the Module Conversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3020
diff changeset
   505
  """
baeb847b88e6 Added GradingSurveyGroup update to the Module Conversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3020
diff changeset
   506
baeb847b88e6 Added GradingSurveyGroup update to the Module Conversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3020
diff changeset
   507
  from soc.modules.gsoc.logic.models.program import logic as program_logic
baeb847b88e6 Added GradingSurveyGroup update to the Module Conversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3020
diff changeset
   508
baeb847b88e6 Added GradingSurveyGroup update to the Module Conversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3020
diff changeset
   509
  for entity in entities:
baeb847b88e6 Added GradingSurveyGroup update to the Module Conversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3020
diff changeset
   510
    entity.scope = program_logic.getFromKeyName(
baeb847b88e6 Added GradingSurveyGroup update to the Module Conversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3020
diff changeset
   511
        entity.scope.key().id_or_name())
baeb847b88e6 Added GradingSurveyGroup update to the Module Conversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3020
diff changeset
   512
baeb847b88e6 Added GradingSurveyGroup update to the Module Conversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3020
diff changeset
   513
  db.put(entities)
baeb847b88e6 Added GradingSurveyGroup update to the Module Conversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3020
diff changeset
   514
baeb847b88e6 Added GradingSurveyGroup update to the Module Conversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3020
diff changeset
   515
  # task completed, return
baeb847b88e6 Added GradingSurveyGroup update to the Module Conversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3020
diff changeset
   516
  return
baeb847b88e6 Added GradingSurveyGroup update to the Module Conversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3020
diff changeset
   517
baeb847b88e6 Added GradingSurveyGroup update to the Module Conversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3020
diff changeset
   518
3010
a0dd39fa090b Add update for Documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3009
diff changeset
   519
@decorators.iterative_task(document_logic)
a0dd39fa090b Add update for Documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3009
diff changeset
   520
def runDocumentUpdate(request, entities, context, *args, **kwargs):
a0dd39fa090b Add update for Documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3009
diff changeset
   521
  """AppEngine Task that updates Document entities.
a0dd39fa090b Add update for Documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3009
diff changeset
   522
a0dd39fa090b Add update for Documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3009
diff changeset
   523
  Args:
a0dd39fa090b Add update for Documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3009
diff changeset
   524
    request: Django Request object
a0dd39fa090b Add update for Documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3009
diff changeset
   525
    entities: list of Document entities to update
a0dd39fa090b Add update for Documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3009
diff changeset
   526
    context: the context of this task
a0dd39fa090b Add update for Documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3009
diff changeset
   527
  """
a0dd39fa090b Add update for Documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3009
diff changeset
   528
3024
e21d0f9bcecd Use scope_path for updating Documents since scope was never properly set.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3023
diff changeset
   529
  import logging
3010
a0dd39fa090b Add update for Documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3009
diff changeset
   530
  from soc.modules.gsoc.logic.models.organization import logic as org_logic
a0dd39fa090b Add update for Documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3009
diff changeset
   531
  from soc.modules.gsoc.logic.models.program import logic as program_logic
a0dd39fa090b Add update for Documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3009
diff changeset
   532
a0dd39fa090b Add update for Documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3009
diff changeset
   533
  for entity in entities:
a0dd39fa090b Add update for Documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3009
diff changeset
   534
    if entity.prefix == 'org':
3024
e21d0f9bcecd Use scope_path for updating Documents since scope was never properly set.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3023
diff changeset
   535
      org_entity = org_logic.getFromKeyName(entity.scope_path)
3010
a0dd39fa090b Add update for Documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3009
diff changeset
   536
      entity.scope = org_entity
a0dd39fa090b Add update for Documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3009
diff changeset
   537
      entity.home_for = org_entity if entity.home_for else None
a0dd39fa090b Add update for Documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3009
diff changeset
   538
a0dd39fa090b Add update for Documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3009
diff changeset
   539
    if entity.prefix == 'program':
3024
e21d0f9bcecd Use scope_path for updating Documents since scope was never properly set.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3023
diff changeset
   540
      program_entity = program_logic.getFromKeyName(entity.scope_path)
3010
a0dd39fa090b Add update for Documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3009
diff changeset
   541
      entity.scope = program_entity
a0dd39fa090b Add update for Documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3009
diff changeset
   542
      entity.home_for = program_entity if entity.home_for else None
a0dd39fa090b Add update for Documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3009
diff changeset
   543
a0dd39fa090b Add update for Documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3009
diff changeset
   544
  # store all Documents
a0dd39fa090b Add update for Documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3009
diff changeset
   545
  db.put(entities)
a0dd39fa090b Add update for Documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3009
diff changeset
   546
a0dd39fa090b Add update for Documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3009
diff changeset
   547
  # task completed, return
a0dd39fa090b Add update for Documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3009
diff changeset
   548
  return
3011
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   549
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   550
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   551
@decorators.iterative_task(timeline_logic)
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   552
def runTimelineConversionUpdate(request, entities, context, *args, **kwargs):
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   553
  """AppEngine Task that converts Timelines into GSoCTimelines.
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   554
3025
1ffc7cd7309c Fixed the TimelineConversionUpdate to also update the GSoCProgram.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3024
diff changeset
   555
  It also updates all GSoCPrograms with a reference to the new GSoCTimeline.
1ffc7cd7309c Fixed the TimelineConversionUpdate to also update the GSoCProgram.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3024
diff changeset
   556
3011
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   557
  Args:
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   558
    request: Django Request object
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   559
    entities: list of Timeline entities to convert
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   560
    context: the context of this task
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   561
  """
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   562
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   563
  from soc.modules.gsoc.models.timeline import GSoCTimeline
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   564
  from soc.modules.gsoc.logic.models.program import logic as program_logic
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   565
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   566
  # get all the properties that are part of each Timeline
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   567
  timeline_model = timeline_logic.getModel()
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   568
  timeline_properties = timeline_model.properties().keys()
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   569
3025
1ffc7cd7309c Fixed the TimelineConversionUpdate to also update the GSoCProgram.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3024
diff changeset
   570
  # use this to store all the new GSoCTimelines and GSoCPrograms
1ffc7cd7309c Fixed the TimelineConversionUpdate to also update the GSoCProgram.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3024
diff changeset
   571
  gsoc_timelines = []
1ffc7cd7309c Fixed the TimelineConversionUpdate to also update the GSoCProgram.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3024
diff changeset
   572
  gsoc_programs = []
3011
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   573
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   574
  for entity in entities:
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   575
    gsoc_properties = {}
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   576
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   577
    for timeline_property in timeline_properties:
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   578
      # copy over all the information from the timeline entity
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   579
      gsoc_properties[timeline_property] = getattr(entity, timeline_property)
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   580
3025
1ffc7cd7309c Fixed the TimelineConversionUpdate to also update the GSoCProgram.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3024
diff changeset
   581
    gsoc_program = program_logic.getFromKeyName(entity.key().id_or_name())
3011
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   582
    gsoc_properties['scope'] = gsoc_program
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   583
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   584
    # create the new GSoCTimeline entity and prepare it to be stored
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   585
    gsoc_timeline_entity = GSoCTimeline(key_name=entity.key().name(),
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   586
                                        **gsoc_properties)
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   587
    gsoc_timelines.append(gsoc_timeline_entity)
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   588
3025
1ffc7cd7309c Fixed the TimelineConversionUpdate to also update the GSoCProgram.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3024
diff changeset
   589
    # set the timeline for the GSoCProgram entity and prepare it for storage
1ffc7cd7309c Fixed the TimelineConversionUpdate to also update the GSoCProgram.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3024
diff changeset
   590
    gsoc_program.timeline = gsoc_timeline_entity
1ffc7cd7309c Fixed the TimelineConversionUpdate to also update the GSoCProgram.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3024
diff changeset
   591
    gsoc_programs.append(gsoc_program)
1ffc7cd7309c Fixed the TimelineConversionUpdate to also update the GSoCProgram.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3024
diff changeset
   592
1ffc7cd7309c Fixed the TimelineConversionUpdate to also update the GSoCProgram.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3024
diff changeset
   593
  # store all the new GSoCTimelines and GSoCPrograms
3011
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   594
  db.put(gsoc_timelines)
3025
1ffc7cd7309c Fixed the TimelineConversionUpdate to also update the GSoCProgram.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3024
diff changeset
   595
  db.put(gsoc_programs)
3011
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   596
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   597
  # task completed, return
1834d422d1dc Add Timeline conversion update
Sverre Rabbelier <srabbelier@gmail.com>
parents: 3010
diff changeset
   598
  return