Beispiel #1
0
    def _editRecordPost(self, request, params, context, template,
                        record_entity):
        """Handles the POST request for editing a GradingRecord.

    Args:
      request: a Django Request object
      params: the params for this view
      context: the context for the webpage
      template: the location of the template used for this view
      record_entity: a GradingRecord entity
    """

        from google.appengine.api.labs import taskqueue
        from soc.modules.gsoc.logic.models.student_project import logic as \
            student_project_logic

        survey_logic = params['logic']
        record_logic = survey_logic.getRecordLogic()

        post_dict = request.POST

        form = params['record_edit_form'](post_dict)

        if not form.is_valid():
            return self._constructResponse(request, record_entity, context,
                                           form, params)

        _, fields = forms_helper.collectCleanedFields(form)

        record_entity = record_logic.updateEntityProperties(
            record_entity, fields)

        if 'save_update' in post_dict:
            # also update the accompanying StudentProject
            student_project_logic.updateProjectsForGradingRecords(
                [record_entity])
        elif 'save_update_mail' in post_dict:
            # update the StudentProject and send an email about the result
            student_project_logic.updateProjectsForGradingRecords(
                [record_entity])

            # pass along these params as POST to the new task
            task_params = {'record_key': record_entity.key().id_or_name()}
            task_url = '/tasks/grading_survey_group/mail_result'

            mail_task = taskqueue.Task(params=task_params, url=task_url)
            mail_task.add('mail')

        # Redirect to the same page
        redirect = request.META['HTTP_REFERER']
        return http.HttpResponseRedirect(redirect)
  def _editRecordPost(self, request, params, context, template, record_entity):
    """Handles the POST request for editing a GradingRecord.

    Args:
      request: a Django Request object
      params: the params for this view
      context: the context for the webpage
      template: the location of the template used for this view
      record_entity: a GradingRecord entity
    """

    from google.appengine.api import taskqueue
    from soc.modules.gsoc.logic.models.student_project import logic as \
        student_project_logic

    survey_logic = params['logic']
    record_logic = survey_logic.getRecordLogic()

    post_dict = request.POST

    form = params['record_edit_form'](post_dict)

    if not form.is_valid():
      return self._constructResponse(request, record_entity, context, form,
                                     params)

    _, fields = forms_helper.collectCleanedFields(form)

    record_entity = record_logic.updateEntityProperties(record_entity, fields)

    if 'save_update' in post_dict:
      # also update the accompanying StudentProject
      student_project_logic.updateProjectsForGradingRecords([record_entity])
    elif 'save_update_mail' in post_dict:
      # update the StudentProject and send an email about the result
      student_project_logic.updateProjectsForGradingRecords([record_entity])

      # pass along these params as POST to the new task
      task_params = {'record_key': record_entity.key().id_or_name()}
      task_url = '/tasks/grading_survey_group/mail_result'

      mail_task = taskqueue.Task(params=task_params, url=task_url)
      mail_task.add('mail')

    # Redirect to the same page
    redirect = request.META['HTTP_REFERER']
    return http.HttpResponseRedirect(redirect)
def updateProjectsForSurveyGroup(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.
    record_key: Optional, specifies the key of the last processed
                GradingRecord.
    send_mail: Optional, if this string evaluates to True mail will be send
               for each GradingRecord that's processed.

  Args:
    request: Django Request object
  """

    from soc.logic.models.grading_record import logic as grading_record_logic
    from soc.logic.models.grading_survey_group import logic as survey_group_logic
    from soc.logic.models.student_project import logic as student_project_logic

    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_entity = survey_group_logic.getFromKeyName(group_key)

    if not survey_group_entity:
        # invalid GradingSurveyGroup specified, log and return OK
        return error_handler.logErrorAndReturnOK(
            'Invalid GradingSurveyGroup specified: %s' % group_key)

    # check and retrieve the record_key that has been done last
    if 'record_key' in post_dict and post_dict['record_key'].isdigit():
        record_start_key = int(post_dict['record_key'])
    else:
        record_start_key = None

    # get all valid StudentProjects from starting key
    fields = {'grading_survey_group': survey_group_entity}

    if record_start_key:
        # retrieve the last record that was done
        record_start = grading_record_logic.getFromID(record_start_key)

        if not record_start:
            # invalid starting record key specified, log and return OK
            return error_handler.logErrorAndReturnOK(
                'Invalid GradingRecord Key specified: %s' % (record_start_key))

        fields['__key__ >'] = record_start.key()

    # get the first batch_size number of GradingRecords
    record_entities = grading_record_logic.getForFields(fields,
                                                        limit=DEF_BATCH_SIZE)

    student_project_logic.updateProjectsForGradingRecords(record_entities)

    # 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_entity in record_entities:
            # pass along these params as POST to the new task
            task_params = {'record_key': record_entity.key().id_or_name()}
            task_url = '/tasks/grading_survey_group/mail_result'

            mail_task = taskqueue.Task(params=task_params, url=task_url)
            mail_task.add('mail')

    if len(record_entities) == DEF_BATCH_SIZE:
        # spawn new task starting from the last
        new_record_start = record_entities[DEF_BATCH_SIZE -
                                           1].key().id_or_name()

        # pass along these params as POST to the new task
        task_params = {
            'group_key': group_key,
            'record_key': new_record_start,
            'send_mail': send_mail
        }
        task_url = '/tasks/grading_survey_group/update_projects'

        new_task = taskqueue.Task(params=task_params, url=task_url)
        new_task.add()

    # task completed, return OK
    return http.HttpResponse('OK')
def updateProjectsForSurveyGroup(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.
    record_key: Optional, specifies the key of the last processed
                GradingRecord.
    send_mail: Optional, if this string evaluates to True mail will be send
               for each GradingRecord that's processed.

  Args:
    request: Django Request object
  """

  from soc.modules.gsoc.logic.models.grading_record import logic as \
      grading_record_logic
  from soc.modules.gsoc.logic.models.grading_survey_group import logic as \
      survey_group_logic
  from soc.modules.gsoc.logic.models.student_project import logic as \
      student_project_logic

  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_entity = survey_group_logic.getFromKeyName(group_key)

  if not survey_group_entity:
    # invalid GradingSurveyGroup specified, log and return OK
    return error_handler.logErrorAndReturnOK(
        'Invalid GradingSurveyGroup specified: %s' % group_key)

  # check and retrieve the record_key that has been done last
  if 'record_key' in post_dict and post_dict['record_key'].isdigit():
    record_start_key = int(post_dict['record_key'])
  else:
    record_start_key = None

  # get all valid StudentProjects from starting key
  fields = {'grading_survey_group': survey_group_entity}

  if record_start_key:
    # retrieve the last record that was done
    record_start = grading_record_logic.getFromID(record_start_key)

    if not record_start:
      # invalid starting record key specified, log and return OK
      return error_handler.logErrorAndReturnOK(
          'Invalid GradingRecord Key specified: %s' %(record_start_key))

    fields['__key__ >'] = record_start.key()

  # get the first batch_size number of GradingRecords
  record_entities = grading_record_logic.getForFields(fields,
                                                      limit=DEF_BATCH_SIZE)

  student_project_logic.updateProjectsForGradingRecords(record_entities)

  # 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_entity in record_entities:
      # pass along these params as POST to the new task
      task_params = {'record_key': record_entity.key().id_or_name()}
      task_url = '/tasks/grading_survey_group/mail_result'

      mail_task = taskqueue.Task(params=task_params, url=task_url)
      mail_task.add('mail')

  if len(record_entities) == DEF_BATCH_SIZE:
    # spawn new task starting from the last
    new_record_start = record_entities[DEF_BATCH_SIZE-1].key().id_or_name()

    # pass along these params as POST to the new task
    task_params = {'group_key': group_key,
                   'record_key': new_record_start,
                   'send_mail': send_mail}
    task_url = '/tasks/grading_survey_group/update_projects'

    new_task = taskqueue.Task(params=task_params, url=task_url)
    new_task.add()

  # task completed, return OK
  return http.HttpResponse('OK')