def _runOrgSurveyRecordUpdate(entities): """AppEngine Task that updates SurveyRecord entities which refer to an organization. In particular, these are GradingProjectSurvey and ProjectSurvey records. Args: entities: list of SurveyRecord entities to update """ from soc.modules.gsoc.logic.models.organization import logic as org_logic cached_orgs = {} for entity in entities: org_key_name = entity.org.key().id_or_name() org_entity = cached_orgs.get(org_key_name) if not org_entity: org_entity = org_logic.getFromKeyName(org_key_name) cached_orgs[org_key_name] = org_entity entity.org = org_entity db.put(entities) # task completed, return return entities
def runStudentProposalUpdate(request, entities, context, *args, **kwargs): """AppEngine Task that updates StudentProposal entities. Args: request: Django Request object entities: list of StudentProposal entities to update context: the context of this task """ from soc.modules.gsoc.logic.models.mentor import logic as mentor_logic from soc.modules.gsoc.logic.models.organization import logic as org_logic from soc.modules.gsoc.logic.models.program import logic as program_logic from soc.modules.gsoc.logic.models.student import logic as student_logic for entity in entities: entity.scope = student_logic.getFromKeyName( entity.scope.key().id_or_name()) entity.org = org_logic.getFromKeyName(entity.org.key().id_or_name()) entity.program = program_logic.getFromKeyName( entity.program.key().id_or_name()) if entity.mentor: entity.mentor = mentor_logic.getFromKeyName( entity.mentor.key().id_or_name()) old_mentors = entity.possible_mentors new_mentors = [] for old_mentor in old_mentors: new_mentor = mentor_logic.getFromKeyName(old_mentor.id_or_name()) new_mentors.append(new_mentor.key()) entity.possible_mentors = new_mentors # store all StudentProposal db.put(entities) # task completed, return return
def runDocumentUpdate(request, entities, context, *args, **kwargs): """AppEngine Task that updates Document entities. Args: request: Django Request object entities: list of Document entities to update context: the context of this task """ from soc.modules.gsoc.logic.models.organization import logic as org_logic from soc.modules.gsoc.logic.models.program import logic as program_logic # get all the properties that are part of each Document document_model = document_logic.getModel() document_properties = document_model.properties().keys() # use this to store all the new Documents and Presences documents = [] presences = [] for entity in entities: if entity.prefix not in ['org', 'program']: # we do not want to convert this Document continue new_document_properties = {} for document_property in document_properties: # copy over all the information from the Document entity new_document_properties[document_property] = getattr(entity, document_property) if entity.prefix == 'org': new_document_prefix = 'gsoc_org' presence_entity = org_logic.getFromKeyName(entity.scope_path) elif entity.prefix == 'program': new_document_prefix = 'gsoc_program' presence_entity = program_logic.getFromKeyName(entity.scope_path) new_document_properties['prefix'] = new_document_prefix new_document_properties['scope'] = presence_entity new_document_properties['home_for'] = presence_entity if entity.home_for else None # create the new Document entity and prepare it to be stored new_document_entity = document_model( key_name=document_logic.getKeyNameFromFields(new_document_properties), **new_document_properties) documents.append(new_document_entity) if entity.home_for: # update the presence for which this document was the home page presence_entity.home = new_document_entity presences.append(presence_entity) # store all the new Documents and updated Presences db.put(documents) db.put(presences) # task completed, return return