# HG changeset patch # User Lennard de Rijk # Date 1254420820 -7200 # Node ID a7cb53d213d7e566fe15df445a7a0330e2954d59 # Parent 9a62e3cad4a8e9b39a2641caaaffc8f019d24bc4 Added the Organization to GSoCOrganzation update. diff -r 9a62e3cad4a8 -r a7cb53d213d7 app/soc/tasks/updates/module_conversion.py --- a/app/soc/tasks/updates/module_conversion.py Wed Sep 30 21:39:09 2009 +0200 +++ b/app/soc/tasks/updates/module_conversion.py Thu Oct 01 20:13:40 2009 +0200 @@ -28,6 +28,7 @@ from django.http import HttpResponse from soc.logic.models.program import logic as program_logic +from soc.logic.models.organization import logic as org_logic from soc.tasks.helper import decorators from soc.tasks.helper import error_handler @@ -81,7 +82,8 @@ gsoc_properties[program_property] = getattr(entity, program_property) # create the new GSoCProgram entity and prepare it to be stored - gsoc_program_entity = GSoCProgram(key_name=entity.key().name(), **gsoc_properties) + gsoc_program_entity = GSoCProgram(key_name=entity.key().name(), + **gsoc_properties) gsoc_programs.append(gsoc_program_entity) # store all the new GSoCPrograms @@ -89,3 +91,48 @@ # task completed, return return + + +@decorators.iterative_task(org_logic) +def runOrgConversionUpdate(request, entities, context, *args, **kwargs): + """Appengine Task that converts Organizations into GSoCOrganizations. + + Args: + request: Django Request object + entities: list of Organization entities to convert + context: the context of this task + """ + + from soc.modules.gsoc.logic.models.program import logic as gsoc_program_logic + from soc.modules.gsoc.models.organization import GSoCOrganization + + # get all the properties that are part of each Organization + org_model = org_logic.getModel() + org_properties = org_model.properties().keys() + + # use this to store all the new GSoCOrganization + gsoc_orgs = [] + + for entity in entities: + gsoc_properties = {} + + for org_property in org_properties: + # copy over all the information from the Organization entity + gsoc_properties[org_property] = getattr(entity, org_property) + + # get the Program key belonging to the old Organization + program_key = entity.scope.key().id_or_name() + # get the new GSoCProgram and set it as scope for the GSoCOrganzation + gsoc_program = gsoc_program_logic.getFromKeyName(program_key) + gsoc_properties['scope'] = gsoc_program + + # create the new GSoCOrganization entity and prepare it to be stored + gsoc_org_entity = GSoCOrganization(key_name=entity.key().name(), + **gsoc_properties) + gsoc_orgs.append(gsoc_org_entity) + + # store all the new GSoCOrganizations + db.put(gsoc_orgs) + + # task completed, return + return