def post(self, data, check, mutator): """Get handler for the code sample delete file.""" assert isSet(data.url_project) try: id_value = int(data.request.POST['id']) code_sample = GSoCCodeSample.get_by_id(id_value, data.url_project) if not code_sample: raise exception.BadRequest(message='Requested code sample not found') upload_of_work = code_sample.upload_of_work def txn(): code_sample.delete() if upload_of_work: # this is executed outside of transaction upload_of_work.delete() if data.url_project.countCodeSamples() <= 1: project = GSoCProject.get(data.url_project.key()) project.code_samples_submitted = False project.put() db.run_in_transaction(txn) url = links.LINKER.userId( data.url_profile.key(), data.url_project.key().id(), url_names.GSOC_PROJECT_UPDATE) return http.HttpResponseRedirect(url) except KeyError: raise exception.BadRequest(message='id argument missing in POST data') except ValueError: raise exception.BadRequest( message='id argument in POST data is not a number')
def get(self, data, check, mutator): """Get handler for the code sample download file.""" assert isSet(data.url_project) try: id_value = int(data.request.GET['id']) code_sample = GSoCCodeSample.get_by_id(id_value, data.url_project) if not code_sample or not code_sample.upload_of_work: raise exception.BadRequest( message='Requested project or code sample not found') else: return bs_helper.sendBlob(code_sample.upload_of_work) except KeyError: raise exception.BadRequest(message='id argument missing in GET data') except ValueError: raise exception.BadRequest( message='id argument in GET data is not a number')
def get(self, data, check, mutator): """Get handler for the code sample download file.""" assert isSet(data.url_project) try: id_value = int(data.request.GET['id']) code_sample = GSoCCodeSample.get_by_id(id_value, data.url_project) if not code_sample or not code_sample.upload_of_work: raise exception.BadRequest( message='Requested project or code sample not found') else: return bs_helper.sendBlob(code_sample.upload_of_work) except KeyError: raise exception.BadRequest( message='id argument missing in GET data') except ValueError: raise exception.BadRequest( message='id argument in GET data is not a number')
def post(self, data, check, mutator): """Get handler for the code sample delete file.""" assert isSet(data.url_project) try: id_value = int(data.request.POST['id']) code_sample = GSoCCodeSample.get_by_id(id_value, data.url_project) if not code_sample: raise exception.BadRequest( message='Requested code sample not found') upload_of_work = code_sample.upload_of_work def txn(): code_sample.delete() if upload_of_work: # this is executed outside of transaction upload_of_work.delete() if data.url_project.countCodeSamples() <= 1: project = GSoCProject.get(data.url_project.key()) project.code_samples_submitted = False project.put() db.run_in_transaction(txn) url = links.LINKER.userId(data.url_profile.key(), data.url_project.key().id(), url_names.GSOC_PROJECT_UPDATE) return http.HttpResponseRedirect(url) except KeyError: raise exception.BadRequest( message='id argument missing in POST data') except ValueError: raise exception.BadRequest( message='id argument in POST data is not a number')
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)