def recalculateGCIRanking(request, entities, context, *args, **kwargs): """Recalculates student ranking for a program with the specified key_name. """ program = gci_program_logic.getFromKeyName(kwargs['key_name']) if not program: return responses.terminateTask() # prefetch all task difficulties all_d = gci_task_model.TaskDifficultyTag.all().fetch(100) for entity in entities: # check if the entity refers to the program in scope if entity.scope.key() != program.key(): continue # get all the tasks that the student has completed filter = { 'student': entity, 'status': 'Closed', } tasks = gci_task_logic.getForFields(filter=filter) # calculate ranking with all the tasks gci_student_ranking_logic.calculateRankingForStudent( entity, tasks, all_d) # this task should not be repeated after the program is over timeline = program.timeline if timeline_helper.isAfterEvent(timeline, 'program_end'): raise responses.DoNotRepeatException()
def recalculateGCIRanking(request, entities, context, *args, **kwargs): """Recalculates student ranking for a program with the specified key_name. """ program = gci_program_logic.getFromKeyName(kwargs['key_name']) if not program: return responses.terminateTask() # prefetch all task difficulties all_d = gci_task_model.TaskDifficultyTag.all().fetch(100) for entity in entities: # check if the entity refers to the program in scope if entity.scope.key() != program.key(): continue # get all the tasks that the student has completed filter = { 'student': entity, 'status': 'Closed', } tasks = gci_task_logic.getForFields(filter=filter) # calculate ranking with all the tasks gci_student_ranking_logic.calculateRankingForStudent(entity, tasks, all_d) # this task should not be repeated after the program is over timeline = program.timeline if timeline_helper.isAfterEvent(timeline, 'program_end'): raise responses.DoNotRepeatException()
def _getCommonProperties(): """Returns properties that are common for all statistic entities. """ program = program_logic.getFromKeyName(program_keyname) properties = { 'access_for_other_programs': 'invisible', 'scope': program, 'scope_path': program_keyname, } return properties
def clearGCIRanking(request, entities, context, *args, **kwargs): """Clears student ranking for a program with the specified key_name. """ program = gci_program_logic.getFromKeyName(kwargs['key_name']) if not program: return responses.terminateTask() for entity in entities: # check if the entity refers to the program in scope if entity.scope.key() != program.key(): continue entity.points = 0 entity.tasks = [] entity.put()
def sendParentalFormMail(request, *args, **kwargs): """Method executed by Task Queue API to send remainder email to existing students for sending parental consent forms. Optionally accepts the start_key entry to be present in the POST dict. Args: request: the standard Django HTTP request object """ post_dict = request.POST program_key = post_dict.get('program_key') if not program_key: return error_handler.logErrorAndReturnOK( 'The program key is not specified: %s' % post_dict) program = gci_program_logic.getFromKeyName(program_key) if not program: return error_handler.logErrorAndReturnOK( 'Invalid program key specified: %s' % program_key) fields = { 'scope': program, 'parental_form_mail': False, } start_key = post_dict.get('start_key', None) if start_key: # retrieve the last student entity that was converted start = gci_student_logic.getFromKeyName(start_key) if not start: # invalid starting student key specified, log and return OK return error_handler.logErrorAndReturnOK( 'Invalid Student Key specified: %s' %(start_key)) fields['__key__ >'] = start.key() # get the first batch_size number of StudentProjects entities = gci_student_logic.getForFields(fields, limit=DEF_BATCH_SIZE) for entity in entities: gci_notifications.sendParentalConsentFormRequired( entity.user, entity.scope) gci_student_logic.updateEntityProperties( entity, {'parental_form_mail': True}) if len(entities) == DEF_BATCH_SIZE: # spawn new task starting from the last new_start = entities[DEF_BATCH_SIZE-1].key().id_or_name() # pass along these params as POST to the new task task_params = { 'start_key': new_start, 'program_key': program_key, } new_task = taskqueue.Task(params=task_params, url=DEF_SPAWN_TASK_URL) new_task.add('mail') # return OK return HttpResponse('OK')