Ejemplo n.º 1
0
def update_ranker(request, *args, **kwargs):
  """Update the ranker for the specified proposal.

  POST Args:
    student_proposal_key: the key of the student proposal for which the ranker 
    should be updated
    value: the value of the new score given to the proposal; type str(int) or ''
  """

  # Copy for modification below
  params = request.POST

  if 'student_proposal_key' not in params:
    return error_handler.logErrorAndReturnOK(
        'missing student_proposal_key in params: "%s"' % params)

  student_proposal = student_proposal_logic.getFromKeyName(
      params['student_proposal_key'])
  if not student_proposal:
    return error_handler.logErrorAndReturnOK(
        'invalid student_proposal_key in params: "%s"' % params)

  value = params.get('value', '')
  value = [int(value)] if value else None
  # update the ranker
  ranker = student_proposal_logic.getRankerFor(student_proposal)
  ranker.SetScore(student_proposal.key().id_or_name(), value)

  # return OK
  return http.HttpResponse()
Ejemplo n.º 2
0
def create_review_for(request, *args, **kwargs):
  """Create a review  for the specified proposal.

  POST Args:
    student_proposal_key: the key name of the student proposal for which 
    the review should be created
    user_key: the key name of the user who is reviewing the proposal
    comment: the comment left by the reviewer; type str
    score: the score given by the reviewer; type str(int)
    is_public: is this review available to public; type str(bool)
  """

  # Copy for modification below
  params = request.POST

  if 'student_proposal_key' not in params:
    return error_handler.logErrorAndReturnOK(
        'missing student_proposal_key in params: "%s"' % params)
  student_proposal = student_proposal_logic.getFromKeyName(
      params['student_proposal_key'])
  if not student_proposal:
    return error_handler.logErrorAndReturnOK(
        'invalid student_proposal_key in params: "%s"' % params)
  if 'user_key' not in params:
    return error_handler.logErrorAndReturnOK(
        'missing user_key in params: "%s"' % params)
  user = user_logic.logic.getFromKeyName(params['user_key'])
  if not user:
    return error_handler.logErrorAndReturnOK(
        'invalid user_key in params: "%s"' % params)
  comment = params.get('comment', '')
  score = int(params.get('score', 0))
  is_public = True if params.get('is_public')=='True' else False
  student_proposal_logic.createReviewFor(student_proposal_view, 
      student_proposal, user, comment, score, is_public)

  # return OK
  return http.HttpResponse()