def taskFromKwargs(self, comments=False, work_submissions=True): """Sets the GCITask entity in RequestData object. The entity that is set will always be in a valid state and for the program that is set in the RequestData. Args: comments: If true the comments on this task are added to RequestData work_submissions: If true the work submissions on this task are added to RequestData """ id = long(self.data.kwargs['id']) task = GCITask.get_by_id(id) if not task or (task.program.key() != self.data.program.key()) or \ task.status == 'invalid': error_msg = access_checker.DEF_ID_BASED_ENTITY_NOT_EXISTS % { 'model': 'GCITask', 'id': id, } raise NotFound(error_msg) self.data.task = task if comments: self.data.comments = task.comments() if work_submissions: self.data.work_submissions = task.workSubmissions()
def publish_task_txn(profile_key): """Publishes or unpublishes a task in a transaction. profile_key: profile key of the user who takes this action. """ task = GCITask.get_by_id(int(task_key)) profile = profile_key.get() if not task: logging.warning("Task with task_id '%s' does not exist", task_key) return org_key = ndb.Key.from_old_key( GCITask.org.get_value_for_datastore(task)) if not org_key in profile.admin_for: logging.warning('Not an org admin') return if publish: if task.status in task_model.UNAVAILABLE: task.status = task_model.OPEN task.put() else: logging.warning( 'Trying to publish task with %s status.', task.status) else: if task.status == task_model.OPEN: task.status = task_model.UNPUBLISHED task.put() else: logging.warning( 'Trying to unpublish task with %s status.', task.status)
def updateGCITask(self, request, id, *args, **kwargs): """Method executed by Task Queue API to update a GCI Task to relevant state. Args: request: the standard Django HTTP request object """ id = int(id) task = GCITask.get_by_id(id) if not task: # invalid task data, log and return OK return error_handler.logErrorAndReturnOK("No GCITask found for id: %s" % id) task_logic.updateTaskStatus(task) return http.HttpResponse()
def updateGCITask(self, request, id, *args, **kwargs): """Method executed by Task Queue API to update a GCI Task to relevant state. Args: request: the standard Django HTTP request object """ id = int(id) task = GCITask.get_by_id(id) if not task: # invalid task data, log and return OK return error_handler.logErrorAndReturnOK( 'No GCITask found for id: %s' % id) task_logic.updateTaskStatus(task) return http.HttpResponse()
def updateRankingWithTask(self, request, *args, **kwargs): """Updates student ranking based on the task passed as post argument. Args in POST dict: id: The (numeric) id of the task to update the ranking for """ post_dict = request.POST id = int(post_dict.get('id')) task = GCITask.get_by_id(id) if not task: logging.warning('Ranking update queued for non-existing task: %s' %id) responses.terminateTask() ranking_logic.updateScore(task) logging.info("ranking_update updateRankingWithTask ends") return responses.terminateTask()
def updateRankingWithTask(self, request, *args, **kwargs): """Updates student ranking based on the task passed as post argument. Args in POST dict: id: The (numeric) id of the task to update the ranking for """ post_dict = request.POST id = int(post_dict.get('id')) task = GCITask.get_by_id(id) if not task: logging.warning('Ranking update queued for non-existing task: %s', id) responses.terminateTask() score_logic.updateScore(task) logging.info("ranking_update updateRankingWithTask ends") return responses.terminateTask()