app/soc/tasks/updates/module_conversion.py
changeset 3063 0b69dd9a5252
parent 3025 1ffc7cd7309c
equal deleted inserted replaced
3062:4b5a7e5746a0 3063:0b69dd9a5252
   106 
   106 
   107 @decorators.iterative_task(org_logic)
   107 @decorators.iterative_task(org_logic)
   108 def runOrgConversionUpdate(request, entities, context, *args, **kwargs):
   108 def runOrgConversionUpdate(request, entities, context, *args, **kwargs):
   109   """AppEngine Task that converts Organizations into GSoCOrganizations.
   109   """AppEngine Task that converts Organizations into GSoCOrganizations.
   110 
   110 
       
   111   Also updates the RankerRoots that are associated with the Organization.
       
   112 
   111   Args:
   113   Args:
   112     request: Django Request object
   114     request: Django Request object
   113     entities: list of Organization entities to convert
   115     entities: list of Organization entities to convert
   114     context: the context of this task
   116     context: the context of this task
   115   """
   117   """
       
   118 
       
   119   from soc.logic.models.ranker_root import logic as ranker_root_logic
   116 
   120 
   117   from soc.modules.gsoc.logic.models.program import logic as gsoc_program_logic
   121   from soc.modules.gsoc.logic.models.program import logic as gsoc_program_logic
   118   from soc.modules.gsoc.models.organization import GSoCOrganization
   122   from soc.modules.gsoc.models.organization import GSoCOrganization
   119 
   123 
   120   # get all the properties that are part of each Organization
   124   # get all the properties that are part of each Organization
   121   org_model = org_logic.getModel()
   125   org_model = org_logic.getModel()
   122   org_properties = org_model.properties().keys()
   126   org_properties = org_model.properties().keys()
   123 
   127 
   124   # use this to store all the new GSoCOrganization
   128   # use this to store all the new GSoCOrganization
   125   gsoc_orgs = []
   129   gsoc_orgs = []
       
   130   gsoc_rankers = []
   126 
   131 
   127   for entity in entities:
   132   for entity in entities:
   128     gsoc_properties = {}
   133     gsoc_properties = {}
   129 
   134 
   130     for org_property in org_properties:
   135     for org_property in org_properties:
   140     # create the new GSoCOrganization entity and prepare it to be stored
   145     # create the new GSoCOrganization entity and prepare it to be stored
   141     gsoc_org_entity = GSoCOrganization(key_name=entity.key().name(),
   146     gsoc_org_entity = GSoCOrganization(key_name=entity.key().name(),
   142                                        **gsoc_properties)
   147                                        **gsoc_properties)
   143     gsoc_orgs.append(gsoc_org_entity)
   148     gsoc_orgs.append(gsoc_org_entity)
   144 
   149 
       
   150     # retrieve the RankerRoots belonging to the Organization
       
   151     fields = {'scope': entity}
       
   152     rankers = ranker_root_logic.getForFields(fields)
       
   153 
       
   154     for ranker in rankers:
       
   155       ranker.scope = gsoc_org_entity
       
   156       # append the adjusted ranker
       
   157       gsoc_rankers.append(ranker)
       
   158 
   145   # store all the new GSoCOrganizations
   159   # store all the new GSoCOrganizations
   146   db.put(gsoc_orgs)
   160   db.put(gsoc_orgs)
       
   161   # store all the new rankers
       
   162   db.put(gsoc_rankers)
   147 
   163 
   148   # task completed, return
   164   # task completed, return
   149   return
   165   return
   150 
   166 
   151 
   167