def clear(*args, **kwargs): """Removes all entities from the datastore. """ # there no explicit ranker model anywhere, so make one for # our own convenience to delete all rankers class ranker(db.Model): """ranker model used with ranklist module. """ pass # TODO(dbentley): If there are more than 1000 instances of any model, # this method will not clear all instances. Instead, it should continually # call .all(), delete all those, and loop until .all() is empty. entities = itertools.chain(*[ Notification.all(), GSoCMentor.all(), GHOPMentor.all(), GSoCStudent.all(), GHOPStudent.all(), Survey.all(), SurveyContent.all(), SurveyRecord.all(), GSoCOrgAdmin.all(), GHOPOrgAdmin.all(), ranker.all(), RankerRoot.all(), StudentProposal.all(), GSoCOrganization.all(), GHOPOrganization.all(), OrgApplication.all(), GSoCTimeline.all(), GHOPTimeline.all(), GSoCProgram.all(), GHOPProgram.all(), Host.all(), Sponsor.all(), User.all(), Site.all(), Document.all(), ]) try: for entity in entities: entity.delete() except db.Timeout: return http.HttpResponseRedirect('#') # pylint: disable-msg=E1101 memcache.flush_all() return http.HttpResponse('Done')
def clear(*args, **kwargs): """Removes all entities from the datastore. """ # there no explicit ranker model anywhere, so make one for # our own convenience to delete all rankers class ranker(db.Model): """ranker model used with ranklist module. """ pass # TODO(dbentley): If there are more than 1000 instances of any model, # this method will not clear all instances. Instead, it should continually # call .all(), delete all those, and loop until .all() is empty. entities = itertools.chain(*[ Notification.all(), GSoCMentor.all(), GCIMentor.all(), GSoCStudent.all(), GCIStudent.all(), Survey.all(), SurveyContent.all(), SurveyRecord.all(), GSoCOrgAdmin.all(), GCIOrgAdmin.all(), ranker.all(), RankerRoot.all(), StudentProposal.all(), GSoCOrganization.all(), GCIOrganization.all(), GSoCTimeline.all(), GCITimeline.all(), GSoCProgram.all(), GCIProgram.all(), Host.all(), Sponsor.all(), User.all(), Site.all(), Document.all(), ]) try: for entity in entities: entity.delete() except db.Timeout: return http.HttpResponseRedirect('#') # pylint: disable=E1101 memcache.flush_all() return http.HttpResponse('Done')
def clear(*args, **kwargs): """Removes all entities from the datastore. """ # TODO(dbentley): If there are more than 1000 instances of any model, # this method will not clear all instances. Instead, it should continually # call .all(), delete all those, and loop until .all() is empty. entities = itertools.chain(*[ Survey.all(), SurveyRecord.all(), GCIOrganization.all(), GSoCTimeline.all(), GCITimeline.all(), GSoCProgram.all(), GSoCProject.all(), GSoCProposal.all(), GCIProgram.all(), GCIScore.all(), GSoCStudentInfo.all(), GCIStudentInfo.all(), GCITask.all(), Sponsor.all(), Site.all(), Document.all(), # The below models are all subclasses of ndb.Model and therefore must # use .query() to return all instances instead of .all(). soc_org_model.SOCOrganization.query(), profile_model.Profile.query(), soc_profile.SOCStudentData.query(), user.User.query(), address.Address.query(), contact.Contact.query() ]) try: for entity in entities: if isinstance(entity, ndb.Model): entity.key.delete() else: entity.delete() except db.Timeout: return http.HttpResponseRedirect('#') memcache.flush_all() return http.HttpResponse('Done')
def clear(*args, **kwargs): """Removes all entities from the datastore. """ # TODO(dbentley): If there are more than 1000 instances of any model, # this method will not clear all instances. Instead, it should continually # call .all(), delete all those, and loop until .all() is empty. entities = itertools.chain(*[ Notification.all(), GCIStudent.all(), Survey.all(), SurveyRecord.all(), StudentProposal.all(), GSoCOrganization.all(), GCIOrganization.all(), GSoCTimeline.all(), GCITimeline.all(), GSoCProgram.all(), GSoCProfile.all(), GCIProfile.all(), GSoCProposal.all(), GCIProgram.all(), GCIScore.all(), GSoCStudentInfo.all(), GCIStudentInfo.all(), GCITask.all(), Host.all(), Sponsor.all(), User.all(), Site.all(), Document.all(), ]) try: for entity in entities: entity.delete() except db.Timeout: return http.HttpResponseRedirect('#') # pylint: disable=E1101 memcache.flush_all() return http.HttpResponse('Done')
def seed_survey_answer(request, i): """Returns the properties of a student's survey answers. """ ensureUser() survey = Survey.get_by_key_name('program/google/gsoc2009/survey_%d' % i) user = User.get_by_key_name('user_%d' % i) #student = GSoCStudent.get_by_key_name('google/gsoc2009/student_%d' % i) if not user: raise Error('Run seed_many for at least %d users first.' % i) if not survey: raise Error('Run seed_many for at least %d surveys first.' % i) all_properties = [] scope_path = 'google/gsoc2009/' checkbox = 'PickMultipleQ Checkbox 2 for survey_%d' % i # pylint: disable=E1103 for i in range(5): #student = GSoCStudent.get_by_key_name('google/gsoc2009/student_%d' % i) user = User.get_by_key_name('user_%d' % i) properties = { 'scope_path': scope_path, 'user': user, 'project': None, '_survey': survey, '_fields': { 'ShortQ': 'Test', 'SelectionQ': u'SelectionQ Option 2', 'LongQ': 'Long answer... \n' * 10, 'PickMultipleQ': checkbox, } } all_properties.append(properties) return all_properties
def seed_survey_answer(request, i): """Returns the properties of a student's survey answers. """ ensureUser() survey = Survey.get_by_key_name('program/google/gsoc2009/survey_%d' % i) user = User.get_by_key_name('user_%d' % i) #student = GSoCStudent.get_by_key_name('google/gsoc2009/student_%d' % i) if not user: raise Error('Run seed_many for at least %d users first.' % i) if not survey: raise Error('Run seed_many for at least %d surveys first.' % i) all_properties = [] scope_path = 'google/gsoc2009/' checkbox = 'PickMultipleQ Checkbox 2 for survey_%d' % i # pylint: disable=E1103 for i in range(5): #student = GSoCStudent.get_by_key_name('google/gsoc2009/student_%d' % i) user = User.get_by_key_name('user_%d' % i) properties = { 'scope_path': scope_path, 'user': user, 'project': None, '_survey': survey, '_fields': {'ShortQ':'Test', 'SelectionQ': u'SelectionQ Option 2', 'LongQ': 'Long answer... \n' * 10, 'PickMultipleQ': checkbox, } } all_properties.append(properties) return all_properties