def listContent(self): """Returns the ListContentResponse object that is constructed from the data. """ q = GSoCGradingRecord.all() q.filter('grading_survey_group', self.data.survey_group) starter = lists.keyStarter prefetcher = GradingRecordsList.ListPrefetcher() response_builder = lists.RawQueryContentResponseBuilder( self.data.request, self._list_config, q, starter, prefetcher=prefetcher) return response_builder.build()
def listContent(self): """Returns the ListContentResponse object that is constructed from the data. """ q = GSoCGradingRecord.all() q.filter('grading_survey_group', self.data.survey_group) starter = lists.keyStarter prefetcher = lists.modelPrefetcher( GSoCGradingRecord, ['mentor_record', 'student_record'], parent=True) response_builder = lists.RawQueryContentResponseBuilder( self.request, self._list_config, q, starter, prefetcher=prefetcher) return response_builder.build()
def testCreateGradingRecord(self): """Test creating a GradingRecord. """ self.grading_record.delete() post_data = {'group_key': self.survey_group.key().id_or_name()} response = self.post(self.UPDATE_RECORDS_URL, post_data) self.assertEqual(response.status_code, httplib.OK) self.assertTasksInQueue(n=1, url=self.UPDATE_RECORDS_URL) record = GSoCGradingRecord.all().get() self.assertFalse(record is None) self.assertEqual(record.grade_decision, 'pass')
def listContent(self): """Returns the ListContentResponse object that is constructed from the data. """ q = GSoCGradingRecord.all() q.filter('grading_survey_group', self.data.survey_group) starter = lists.keyStarter prefetcher = GradingRecordsList.ListPrefetcher() response_builder = lists.RawQueryContentResponseBuilder( self.data.request, self._list_config, q, starter, prefetcher=prefetcher) return response_builder.build()
def testCreateGradingRecord(self): """Test creating a GradingRecord. """ self.grading_record.delete() post_data = { 'group_key': self.survey_group.key().id_or_name() } response = self.post(self.UPDATE_RECORDS_URL, post_data) self.assertEqual(response.status_code, httplib.OK) self.assertTasksInQueue(n=1, url=self.UPDATE_RECORDS_URL) record = GSoCGradingRecord.all().get() self.assertFalse(record is None) self.assertEqual(record.grade_decision, 'pass')
def updateOrCreateRecordsFor(survey_group, projects): """Updates or creates GradingRecords in batch. Args: survey_group: GradingSurveyGroup entity projects: list of GSoCProjects which to process Returns: The list of updated and new records. """ records = [] for project in projects: q = GSoCGradingRecord.all() q.filter('grading_survey_group', survey_group) q.ancestor(project) # try to retrieve an existing record record = q.get() # retrieve the fields that should be set record_fields = getFieldsForGradingRecord(project, survey_group, record) if not record and project.status in ['failed', 'invalid'] \ and not record_fields['mentor_record'] \ and not record_fields['student_record']: # Don't create a new GradingRecord for an already failed project which # has no records attached. Because it does not matter. continue if record: # update existing GradingRecord for key, value in record_fields.iteritems(): setattr(record, key, value) else: # create a new GradingRecord record = GSoCGradingRecord(parent=project, **record_fields) # prepare the new/updated record for storage records.append(record) db.put(records) return records
def updateOrCreateRecordsFor(survey_group, projects): """Updates or creates GradingRecords in batch. Args: survey_group: GradingSurveyGroup entity projects: list of GSoCProjects which to process Returns: The list of updated and new records. """ records = [] for project in projects: q = GSoCGradingRecord.all() q.filter('grading_survey_group', survey_group) q.ancestor(project) # try to retrieve an existing record record = q.get() # retrieve the fields that should be set record_fields = getFieldsForGradingRecord( project, survey_group, record) if not record and project.status in ['failed', 'invalid'] \ and not record_fields['mentor_record'] \ and not record_fields['student_record']: # Don't create a new GradingRecord for an already failed project which # has no records attached. Because it does not matter. continue if record: # update existing GradingRecord for key, value in record_fields.iteritems(): setattr(record, key, value) else: # create a new GradingRecord record = GSoCGradingRecord(parent=project, **record_fields) # prepare the new/updated record for storage records.append(record) db.put(records) return records
def convertGSoCProfileDBEntityGroup(profile_key): """Converts DB based part of entity group associated with the specified profile. Args: profile_key: db.Key of the profile to process """ # map that associate old keys with new ones which are created during # the conversion conversion_map = {} to_delete = [] do_put = True proposals = GSoCProposal.all().ancestor(profile_key).fetch(1000) for proposal in proposals: # update GSoCProposal.parent new_proposal = _convertParent(proposal) # update GSoCProposal.possible_mentors new_proposal.possible_mentors = _convertListProperty( GSoCProposal.possible_mentors, new_proposal) # update GSoCProposal.mentor new_proposal.mentor = _convertReferenceProperty( GSoCProposal.mentor, new_proposal) to_delete.append(proposal) if do_put: new_proposal.put() conversion_map[proposal.key()] = new_proposal.key() comments = GSoCComment.all().ancestor(proposal).fetch(1000) for comment in comments: # update GSoCComment.parent new_comment = _convertParent(comment, parent=new_proposal.key()) # update GSoCComment.author new_comment.author = _convertReferenceProperty( GSoCComment.author, new_comment) if do_put: new_comment.put() to_delete.append(comment) scores = GSoCScore.all().ancestor(proposal).fetch(1000) for score in scores: # update GSoCScore.parent new_score = _convertParent(score, parent=new_proposal.key()) # update GSoCScore.author new_score.author = _convertReferenceProperty(GSoCScore.author, new_score) if do_put: new_score.put() to_delete.append(score) projects = GSoCProject.all().ancestor(profile_key).fetch(1000) for project in projects: # update GSoCProject.parent new_project = _convertParent(project) # update GSoCProject.mentors new_project.mentors = _convertListProperty(GSoCProject.mentors, new_project) # update GSoCProject.proposal proposal_key = GSoCProject.proposal.get_value_for_datastore(project) if proposal_key: new_project.proposal = conversion_map.get( GSoCProject.proposal.get_value_for_datastore(project)) if do_put: new_project.put() conversion_map[project.key()] = new_project.key() to_delete.append(project) grading_records = GSoCGradingRecord.all().ancestor(project.key()) for grading_record in grading_records: # update GSoCGradingProjectSurveyRecord.project # this is another entity group, but XG transaction does the thing grading_project_survey_record_key = ( GSoCGradingRecord.mentor_record.get_value_for_datastore( grading_record)) if grading_project_survey_record_key: grading_project_survey_record = GSoCGradingProjectSurveyRecord.get( grading_project_survey_record_key) if grading_project_survey_record: grading_project_survey_record.project = new_project.key() if do_put: grading_project_survey_record.put() # update GSoCProjectSurveyRecord.project # this is another entity group, but XG transaction does the thing project_survey_record_key = ( GSoCGradingRecord.student_record.get_value_for_datastore( grading_record)) if project_survey_record_key: project_survey_record = GSoCProjectSurveyRecord.get( project_survey_record_key) if project_survey_record: project_survey_record.project = new_project.key() if do_put: project_survey_record.put() # update GSoCGradingRecord.parent new_grading_record = _convertParent( grading_record, parent=new_project.key()) if do_put: new_grading_record.put() code_samples = GSoCCodeSample.all().ancestor(project.key()) for code_sample in code_samples: # update GSoCCodeSample.parent new_code_sample = _convertParent(code_sample, parent=new_project.key()) if do_put: new_code_sample.put() to_delete.append(code_sample) db.delete(to_delete)
def convertGSoCProfileDBEntityGroup(profile_key): """Converts DB based part of entity group associated with the specified profile. Args: profile_key: db.Key of the profile to process """ # map that associate old keys with new ones which are created during # the conversion conversion_map = {} to_delete = [] do_put = True proposals = GSoCProposal.all().ancestor(profile_key).fetch(1000) for proposal in proposals: # update GSoCProposal.parent new_proposal = _convertParent(proposal) # update GSoCProposal.possible_mentors new_proposal.possible_mentors = _convertListProperty( GSoCProposal.possible_mentors, new_proposal) # update GSoCProposal.mentor new_proposal.mentor = _convertReferenceProperty( GSoCProposal.mentor, new_proposal) to_delete.append(proposal) if do_put: new_proposal.put() conversion_map[proposal.key()] = new_proposal.key() comments = GSoCComment.all().ancestor(proposal).fetch(1000) for comment in comments: # update GSoCComment.parent new_comment = _convertParent(comment, parent=new_proposal.key()) # update GSoCComment.author new_comment.author = _convertReferenceProperty( GSoCComment.author, new_comment) if do_put: new_comment.put() to_delete.append(comment) scores = GSoCScore.all().ancestor(proposal).fetch(1000) for score in scores: # update GSoCScore.parent new_score = _convertParent(score, parent=new_proposal.key()) # update GSoCScore.author new_score.author = _convertReferenceProperty( GSoCScore.author, new_score) if do_put: new_score.put() to_delete.append(score) projects = GSoCProject.all().ancestor(profile_key).fetch(1000) for project in projects: # update GSoCProject.parent new_project = _convertParent(project) # update GSoCProject.mentors new_project.mentors = _convertListProperty(GSoCProject.mentors, new_project) # update GSoCProject.proposal proposal_key = GSoCProject.proposal.get_value_for_datastore(project) if proposal_key: new_project.proposal = conversion_map.get( GSoCProject.proposal.get_value_for_datastore(project)) if do_put: new_project.put() conversion_map[project.key()] = new_project.key() to_delete.append(project) grading_records = GSoCGradingRecord.all().ancestor(project.key()) for grading_record in grading_records: # update GSoCGradingProjectSurveyRecord.project # this is another entity group, but XG transaction does the thing grading_project_survey_record_key = ( GSoCGradingRecord.mentor_record.get_value_for_datastore( grading_record)) if grading_project_survey_record_key: grading_project_survey_record = GSoCGradingProjectSurveyRecord.get( grading_project_survey_record_key) if grading_project_survey_record: grading_project_survey_record.project = new_project.key() if do_put: grading_project_survey_record.put() # update GSoCProjectSurveyRecord.project # this is another entity group, but XG transaction does the thing project_survey_record_key = ( GSoCGradingRecord.student_record.get_value_for_datastore( grading_record)) if project_survey_record_key: project_survey_record = GSoCProjectSurveyRecord.get( project_survey_record_key) if project_survey_record: project_survey_record.project = new_project.key() if do_put: project_survey_record.put() # update GSoCGradingRecord.parent new_grading_record = _convertParent(grading_record, parent=new_project.key()) if do_put: new_grading_record.put() code_samples = GSoCCodeSample.all().ancestor(project.key()) for code_sample in code_samples: # update GSoCCodeSample.parent new_code_sample = _convertParent(code_sample, parent=new_project.key()) if do_put: new_code_sample.put() to_delete.append(code_sample) db.delete(to_delete)
def updateProjectsForSurveyGroup(self, request, *args, **kwargs): """Updates each StudentProject for which a GradingRecord is found. Expects the following to be present in the POST dict: group_key: Specifies the GradingSurveyGroup key name. cursor: Optional, specifies the cursor for the GadingRecord query. send_mail: Optional, if this string evaluates to True mail will be send for each GradingRecord that's processed. Args: request: Django Request object """ post_dict = request.POST group_key = post_dict.get('group_key') if not group_key: # invalid task data, log and return OK return error_handler.logErrorAndReturnOK( 'Invalid updateRecordForSurveyGroup data: %s' % post_dict) # get the GradingSurveyGroup for the given keyname survey_group = GSoCGradingSurveyGroup.get_by_id(int(group_key)) if not survey_group: # invalid GradingSurveyGroup specified, log and return OK return error_handler.logErrorAndReturnOK( 'Invalid GradingSurveyGroup specified: %s' % group_key) q = GSoCGradingRecord.all() q.filter('grading_survey_group', survey_group) if 'cursor' in post_dict: q.with_cursor(post_dict['cursor']) # get the first batch_size number of GradingRecords records = q.fetch(self.DEF_BATCH_SIZE) if not records: # we are done return http.HttpResponse() grading_record.updateProjectsForGradingRecords(records) # check if we need to send an email for each GradingRecord send_mail = post_dict.get('send_mail', '') if send_mail: # enqueue a task to send mail for each GradingRecord for record in records: # pass along these params as POST to the new task task_params = {'record_key': str(record.key())} task_url = '/tasks/gsoc/grading_record/mail_result' mail_task = taskqueue.Task(params=task_params, url=task_url) mail_task.add('mail') # pass along these params as POST to the new task task_params = {'group_key': group_key, 'cursor': q.cursor(), 'send_mail': send_mail} new_task = taskqueue.Task(params=task_params, url=request.path) new_task.add() # task completed, return OK return http.HttpResponse('OK')