def update_ranking_txn(): logging.info("updateScore txn starts for task %s" % task_key.id()) query = GCIScore.all().ancestor(student) score = query.get() # create a new GCIStore entity if one does not exist yet if not score: logging.info("score entity is being created") score = GCIScore(parent=student, program=program) # check if the task has been included in the score if task_key not in score.tasks: score.points += POINTS[task.difficulty_level] score.tasks.append(task_key) # TODO(dhans): optimize it; sometimes, put may not be needed logging.info("score put") score.put() logging.info("score put returned") query = GCIStudentInfo.all().ancestor(student) student_info = query.get() # set in student info that the student has completed a task if not student_info.task_closed: student_info.task_closed = True student_info.put()
def calculate_score_txn(): query = GCIScore.all().ancestor(student) score = query.get() # create a new GCIStore entity if one does not exist yet if not score: score = GCIScore(parent=student, program=program) score.points = points score.tasks = [task.key() for task in tasks] score.put() # set that the student closed a task in GCIStudentInfo query = GCIStudentInfo.all().ancestor(student) student_info = query.get() student_info.task_closed = True student_info.put()
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 update_ranking_txn(): logging.info("updateScore txn starts for task %s", task_key.id()) query = GCIScore.all().ancestor(student) score = query.get() # create a new GCIStore entity if one does not exist yet if not score: score = GCIScore(parent=student, program=program) # check if the task has been included in the score if task_key not in score.tasks: if not task.points_invalidated: score.points += POINTS[task.difficulty_level] score.tasks.append(task_key) score.put() query = GCIStudentInfo.all().ancestor(student) student_info = query.get() # set in student info that the student has completed a task if not student_info.task_closed: student_info.task_closed = True student_info.put()