author | Lennard de Rijk <ljvderijk@gmail.com> |
Thu, 01 Oct 2009 20:48:11 +0200 | |
changeset 3001 | 1698cca3d912 |
parent 3000 | 733d07eac729 |
child 3006 | e74c4d37a61a |
permissions | -rw-r--r-- |
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 |
|
2998
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
30 |
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
|
31 |
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
|
32 |
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
|
33 |
from soc.logic.models.program import logic as program_logic |
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
34 |
from soc.logic.models.student import logic as student_logic |
2996
9a62e3cad4a8
Use the iterative task iterator for the ProgramConversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2973
diff
changeset
|
35 |
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
|
36 |
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
|
37 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
38 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
39 |
# 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
|
40 |
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
|
41 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
42 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
43 |
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
|
44 |
"""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
|
45 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
46 |
Args: |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
47 |
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
|
48 |
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
|
49 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
50 |
Returns: |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
51 |
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
|
52 |
""" |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
53 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
54 |
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
|
55 |
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
|
56 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
57 |
return True |
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 |
|
2996
9a62e3cad4a8
Use the iterative task iterator for the ProgramConversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2973
diff
changeset
|
60 |
@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
|
61 |
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
|
62 |
"""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
|
63 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
64 |
Args: |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
65 |
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
|
66 |
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
|
67 |
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
|
68 |
""" |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
69 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
70 |
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
|
71 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
72 |
# 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
|
73 |
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
|
74 |
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
|
75 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
76 |
# 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
|
77 |
gsoc_programs = [] |
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 |
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
|
80 |
gsoc_properties = {} |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
81 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
82 |
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
|
83 |
# 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
|
84 |
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
|
85 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
86 |
# 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
|
87 |
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
|
88 |
**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
|
89 |
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
|
90 |
|
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
|
91 |
# 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
|
92 |
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
|
93 |
|
2996
9a62e3cad4a8
Use the iterative task iterator for the ProgramConversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2973
diff
changeset
|
94 |
# task completed, return |
9a62e3cad4a8
Use the iterative task iterator for the ProgramConversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2973
diff
changeset
|
95 |
return |
2997
a7cb53d213d7
Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2996
diff
changeset
|
96 |
|
a7cb53d213d7
Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2996
diff
changeset
|
97 |
|
a7cb53d213d7
Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2996
diff
changeset
|
98 |
@decorators.iterative_task(org_logic) |
a7cb53d213d7
Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2996
diff
changeset
|
99 |
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
|
100 |
"""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
|
101 |
|
a7cb53d213d7
Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2996
diff
changeset
|
102 |
Args: |
a7cb53d213d7
Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2996
diff
changeset
|
103 |
request: Django Request object |
a7cb53d213d7
Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2996
diff
changeset
|
104 |
entities: list of Organization entities to convert |
a7cb53d213d7
Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2996
diff
changeset
|
105 |
context: the context of this task |
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 |
|
a7cb53d213d7
Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2996
diff
changeset
|
108 |
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
|
109 |
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
|
110 |
|
a7cb53d213d7
Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2996
diff
changeset
|
111 |
# 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
|
112 |
org_model = org_logic.getModel() |
a7cb53d213d7
Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2996
diff
changeset
|
113 |
org_properties = org_model.properties().keys() |
a7cb53d213d7
Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2996
diff
changeset
|
114 |
|
a7cb53d213d7
Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2996
diff
changeset
|
115 |
# 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
|
116 |
gsoc_orgs = [] |
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 |
for entity in entities: |
a7cb53d213d7
Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2996
diff
changeset
|
119 |
gsoc_properties = {} |
a7cb53d213d7
Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2996
diff
changeset
|
120 |
|
a7cb53d213d7
Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2996
diff
changeset
|
121 |
for org_property in org_properties: |
a7cb53d213d7
Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2996
diff
changeset
|
122 |
# 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
|
123 |
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
|
124 |
|
3001
1698cca3d912
Only set new properties outside the "properties" loop for the ModuleConversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3000
diff
changeset
|
125 |
# 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
|
126 |
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
|
127 |
# 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
|
128 |
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
|
129 |
gsoc_properties['scope'] = gsoc_program |
2997
a7cb53d213d7
Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2996
diff
changeset
|
130 |
|
a7cb53d213d7
Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2996
diff
changeset
|
131 |
# 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
|
132 |
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
|
133 |
**gsoc_properties) |
a7cb53d213d7
Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2996
diff
changeset
|
134 |
gsoc_orgs.append(gsoc_org_entity) |
a7cb53d213d7
Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2996
diff
changeset
|
135 |
|
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
|
136 |
# 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
|
137 |
db.put(gsoc_orgs) |
2997
a7cb53d213d7
Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2996
diff
changeset
|
138 |
|
a7cb53d213d7
Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2996
diff
changeset
|
139 |
# task completed, return |
a7cb53d213d7
Added the Organization to GSoCOrganzation update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2996
diff
changeset
|
140 |
return |
2998
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
141 |
|
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
142 |
|
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
143 |
@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
|
144 |
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
|
145 |
"""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
|
146 |
|
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
147 |
Args: |
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
148 |
request: Django Request object |
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
149 |
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
|
150 |
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
|
151 |
""" |
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
152 |
|
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
153 |
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
|
154 |
|
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
155 |
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
|
156 |
|
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
157 |
|
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
158 |
@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
|
159 |
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
|
160 |
"""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
|
161 |
|
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
162 |
Args: |
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
163 |
request: Django Request object |
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
164 |
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
|
165 |
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
|
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 |
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
|
169 |
|
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
170 |
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
|
171 |
|
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
172 |
|
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
173 |
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
|
174 |
"""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
|
175 |
GSoCOrganization Role. |
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 |
Args: |
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
178 |
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
|
179 |
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
|
180 |
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
|
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 |
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
|
184 |
gsoc_org_logic |
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
185 |
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
|
186 |
|
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
187 |
# 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
|
188 |
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
|
189 |
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
|
190 |
|
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
191 |
# 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
|
192 |
gsoc_roles = [] |
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
193 |
|
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
194 |
for entity in entities: |
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
195 |
gsoc_properties = {} |
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 |
for role_property in role_properties: |
3000
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
198 |
# 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
|
199 |
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
|
200 |
|
3001
1698cca3d912
Only set new properties outside the "properties" loop for the ModuleConversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3000
diff
changeset
|
201 |
# 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
|
202 |
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
|
203 |
# 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
|
204 |
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
|
205 |
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
|
206 |
|
3001
1698cca3d912
Only set new properties outside the "properties" loop for the ModuleConversion.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3000
diff
changeset
|
207 |
# 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
|
208 |
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
|
209 |
# 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
|
210 |
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
|
211 |
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
|
212 |
|
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
213 |
# 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
|
214 |
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
|
215 |
**gsoc_properties) |
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
216 |
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
|
217 |
|
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
218 |
# 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
|
219 |
db.put(gsoc_roles) |
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
220 |
|
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
221 |
# task completed, return |
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
222 |
return |
9c34768346da
Add OrgAdmin and Mentor to GSoCOrgadmin and GSoCMentor updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2997
diff
changeset
|
223 |
|
3000
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
224 |
|
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
225 |
@decorators.iterative_task(student_logic) |
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
226 |
def runStudentConversionUpdate(request, entities, context, *args, **kwargs): |
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
227 |
"""AppEngine Task that converts Students into GSoCStudents. |
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
228 |
|
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
229 |
Args: |
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
230 |
request: Django Request object |
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
231 |
entities: list of Student entities to convert |
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
232 |
context: the context of this task |
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
233 |
""" |
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
234 |
|
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
235 |
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
|
236 |
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
|
237 |
|
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
238 |
# 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
|
239 |
student_model = student_logic.getModel() |
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
240 |
student_properties = student_model.properties().keys() |
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
241 |
|
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
242 |
# 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
|
243 |
gsoc_students = [] |
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
244 |
|
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
245 |
for entity in entities: |
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
246 |
gsoc_properties = {} |
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
247 |
|
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
248 |
for student_property in student_properties: |
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
249 |
# 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
|
250 |
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
|
251 |
|
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
252 |
# 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
|
253 |
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
|
254 |
# 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
|
255 |
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
|
256 |
gsoc_properties['scope'] = gsoc_program |
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
257 |
|
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
258 |
# 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
|
259 |
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
|
260 |
**gsoc_properties) |
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
261 |
gsoc_students.append(gsoc_student_entity) |
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 |
# store all the new GSoCStudents |
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
264 |
db.put(gsoc_students) |
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
265 |
|
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
266 |
# task completed, return |
733d07eac729
Add the Student to GSoCStudent conversion,
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2999
diff
changeset
|
267 |
return |