26 from google.appengine.ext import db |
26 from google.appengine.ext import db |
27 |
27 |
28 from django.http import HttpResponse |
28 from django.http import HttpResponse |
29 |
29 |
30 from soc.logic.models.mentor import logic as mentor_logic |
30 from soc.logic.models.mentor import logic as mentor_logic |
31 from soc.logic.models.program import logic as program_logic |
|
32 from soc.logic.models.org_admin import logic as org_admin_logic |
31 from soc.logic.models.org_admin import logic as org_admin_logic |
33 from soc.logic.models.organization import logic as org_logic |
32 from soc.logic.models.organization import logic as org_logic |
|
33 from soc.logic.models.program import logic as program_logic |
|
34 from soc.logic.models.student import logic as student_logic |
34 from soc.tasks.helper import decorators |
35 from soc.tasks.helper import decorators |
35 from soc.tasks.helper import error_handler |
36 from soc.tasks.helper import error_handler |
36 |
37 |
37 |
38 |
38 # batch size to use when going through the entities |
39 # batch size to use when going through the entities |
192 |
193 |
193 for entity in entities: |
194 for entity in entities: |
194 gsoc_properties = {} |
195 gsoc_properties = {} |
195 |
196 |
196 for role_property in role_properties: |
197 for role_property in role_properties: |
197 # copy over all the information from the Organization entity |
198 # copy over all the information from the Role entity |
198 gsoc_properties[role_property] = getattr(entity, role_property) |
199 gsoc_properties[role_property] = getattr(entity, role_property) |
199 |
200 |
200 # get the Program key belonging to the old Role |
201 # get the Program key belonging to the old Role |
201 program_key = entity.program.key().id_or_name() |
202 program_key = entity.program.key().id_or_name() |
202 # get the new GSoCProgram and set it for the Role |
203 # get the new GSoCProgram and set it for the Role |
218 db.put(gsoc_roles) |
219 db.put(gsoc_roles) |
219 |
220 |
220 # task completed, return |
221 # task completed, return |
221 return |
222 return |
222 |
223 |
|
224 |
|
225 @decorators.iterative_task(student_logic) |
|
226 def runStudentConversionUpdate(request, entities, context, *args, **kwargs): |
|
227 """AppEngine Task that converts Students into GSoCStudents. |
|
228 |
|
229 Args: |
|
230 request: Django Request object |
|
231 entities: list of Student entities to convert |
|
232 context: the context of this task |
|
233 """ |
|
234 |
|
235 from soc.modules.gsoc.logic.models.program import logic as gsoc_program_logic |
|
236 from soc.modules.gsoc.models.student import GSoCStudent |
|
237 |
|
238 # get all the properties that are part of each Student |
|
239 student_model = student_logic.getModel() |
|
240 student_properties = student_model.properties().keys() |
|
241 |
|
242 # use this to store all the new GSoCStudents |
|
243 gsoc_students = [] |
|
244 |
|
245 for entity in entities: |
|
246 gsoc_properties = {} |
|
247 |
|
248 for student_property in student_properties: |
|
249 # copy over all the information from the Student entity |
|
250 gsoc_properties[student_property] = getattr(entity, student_property) |
|
251 |
|
252 # get the Program key belonging to the old Student |
|
253 program_key = entity.scope.key().id_or_name() |
|
254 # get the new GSoCProgram and set it as scope for the GSoCStudent |
|
255 gsoc_program = gsoc_program_logic.getFromKeyName(program_key) |
|
256 gsoc_properties['scope'] = gsoc_program |
|
257 |
|
258 # create the new GSoCStudent entity and prepare it to be stored |
|
259 gsoc_student_entity = GSoCStudent(key_name=entity.key().name(), |
|
260 **gsoc_properties) |
|
261 gsoc_students.append(gsoc_student_entity) |
|
262 |
|
263 # store all the new GSoCStudents |
|
264 db.put(gsoc_students) |
|
265 |
|
266 # task completed, return |
|
267 return |