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 convertUser(user_key): """Converts the specified user by creating a new user entity that inherits from the newly added NewUser model. Args: user_key: User key. """ user = User.get(user_key) entity_id = user.key().name() account_id = user.user_id or 'unset' if user.status == 'valid': status = user_model.Status.ACTIVE elif user.status == 'invalid': status = user_model.Status.BANNED else: operation.counters.Increment('Bad status') logging.warning('Invalid status %s for user %s', user.status, user.key().name()) return host_for = [] for sponsor_key in user.host_for: host_for.extend( map( ndb.Key.from_old_key, GSoCProgram.all(keys_only=True).filter( 'sponsor', sponsor_key).fetch(1000))) host_for.extend( map( ndb.Key.from_old_key, GCIProgram.all(keys_only=True).filter( 'sponsor', sponsor_key).fetch(1000))) account = user.account new_user = NewUser(id=entity_id, account_id=account_id, status=status, host_for=host_for, account=account) _createUserTxn(new_user)
def programs(self): """Memorizes and returns a list of all programs.""" if not self._isSet(self._programs): self._programs = list(GCIProgram.all()) return self._programs