def post(self): """Handles the POST request when editing a GradingRecord. """ assert isSet(self.data.record) record_form = GradingRecordForm(self.data.POST) if not record_form.is_valid(): return self.get() decision = record_form.cleaned_data['grade_decision'] locked = record_form.cleaned_data['locked'] record = self.data.record record.grade_decision = decision record.locked = locked record.put() grading_record.updateProjectsForGradingRecords([record]) # pass along these params as POST to the new task task_params = {'record_key': str(record.key())} task_url = '/tasks/gsoc/grading_record/mail_result' mail_task = taskqueue.Task(params=task_params, url=task_url) mail_task.add('mail') self.redirect.id(record.grading_survey_group.key().id_or_name()) self.redirect.to('gsoc_grading_record_overview')
def post(self, data, check, mutator): """Handles the POST request when editing a GradingRecord.""" assert isSet(data.record) record_form = GradingRecordForm(data=data.POST) if not record_form.is_valid(): return self.get(data, check, mutator) decision = record_form.cleaned_data['grade_decision'] locked = record_form.cleaned_data['locked'] record = data.record record.grade_decision = decision record.locked = locked record.put() grading_record.updateProjectsForGradingRecords([record]) # pass along these params as POST to the new task task_params = {'record_key': str(record.key())} task_url = '/tasks/gsoc/grading_record/mail_result' mail_task = taskqueue.Task(params=task_params, url=task_url) mail_task.add('mail') data.redirect.id(record.grading_survey_group.key().id_or_name()) return data.redirect.to('gsoc_grading_record_overview')
def updateProjectsForSurveyGroup(self, request, *args, **kwargs): """Updates each StudentProject for which a GradingRecord is found. Expects the following to be present in the POST dict: group_key: Specifies the GradingSurveyGroup key name. cursor: Optional, specifies the cursor for the GadingRecord query. send_mail: Optional, if this string evaluates to True mail will be send for each GradingRecord that's processed. Args: request: Django Request object """ post_dict = request.POST group_key = post_dict.get('group_key') if not group_key: # invalid task data, log and return OK return error_handler.logErrorAndReturnOK( 'Invalid updateRecordForSurveyGroup data: %s' % post_dict) # get the GradingSurveyGroup for the given keyname survey_group = GSoCGradingSurveyGroup.get_by_id(int(group_key)) if not survey_group: # invalid GradingSurveyGroup specified, log and return OK return error_handler.logErrorAndReturnOK( 'Invalid GradingSurveyGroup specified: %s' % group_key) q = GSoCGradingRecord.all() q.filter('grading_survey_group', survey_group) if 'cursor' in post_dict: q.with_cursor(post_dict['cursor']) # get the first batch_size number of GradingRecords records = q.fetch(self.DEF_BATCH_SIZE) if not records: # we are done return http.HttpResponse() grading_record.updateProjectsForGradingRecords(records) # check if we need to send an email for each GradingRecord send_mail = post_dict.get('send_mail', '') if send_mail: # enqueue a task to send mail for each GradingRecord for record in records: # pass along these params as POST to the new task task_params = {'record_key': str(record.key())} task_url = '/tasks/gsoc/grading_record/mail_result' mail_task = taskqueue.Task(params=task_params, url=task_url) mail_task.add('mail') # pass along these params as POST to the new task task_params = {'group_key': group_key, 'cursor': q.cursor(), 'send_mail': send_mail} new_task = taskqueue.Task(params=task_params, url=request.path) new_task.add() # task completed, return OK return http.HttpResponse('OK')