Esempio n. 1
0
def _GetComments(request):
    """Helper that returns comments for a patch.

  Args:
    request: Django Request object.

  Returns:
    A 2-tuple of (old, new) where old/new are dictionaries that holds comments
      for that file, mapping from line number to a Comment entity.
  """
    old_dict = {}
    new_dict = {}
    # XXX GQL doesn't support OR yet...  Otherwise we'd be using
    # .gql('WHERE patch = :1 AND (draft = FALSE OR author = :2) ORDER BY data',
    #      patch, request.user)
    for comment in models.Comment.gql('WHERE patch = :1 ORDER BY date',
                                      request.patch):
        if comment.draft and comment.author != request.user:
            continue  # Only show your own drafts
        comment.complete(request.patch)
        if comment.left:
            dct = old_dict
        else:
            dct = new_dict
        dct.setdefault(comment.lineno, []).append(comment)
        library.prefetch_names([comment.author])
    return old_dict, new_dict
Esempio n. 2
0
def _GetComments(request):
  """Helper that returns comments for a patch.

  Args:
    request: Django Request object.

  Returns:
    A 2-tuple of (old, new) where old/new are dictionaries that holds comments
      for that file, mapping from line number to a Comment entity.
  """
  old_dict = {}
  new_dict = {}
  # XXX GQL doesn't support OR yet...  Otherwise we'd be using
  # .gql('WHERE patch = :1 AND (draft = FALSE OR author = :2) ORDER BY data',
  #      patch, request.user)
  for comment in models.Comment.gql('WHERE patch = :1 ORDER BY date',
                                    request.patch):
    if comment.draft and comment.author != request.user:
      continue  # Only show your own drafts
    comment.complete(request.patch)
    if comment.left:
      dct = old_dict
    else:
      dct = new_dict
    dct.setdefault(comment.lineno, []).append(comment)
    library.prefetch_names([comment.author])
  return old_dict, new_dict
Esempio n. 3
0
def _RenderDiff2TableRows(request,
                          old_lines,
                          old_patch,
                          new_lines,
                          new_patch,
                          colwidth,
                          debug=False):
    """Internal version of RenderDiff2TableRows().

  Args:
    The same as for RenderDiff2TableRows.

  Yields:
    Tuples (tag, row) where tag is an indication of the row type.
  """
    old_dict = {}
    new_dict = {}
    for patch, dct in [(old_patch, old_dict), (new_patch, new_dict)]:
        # XXX GQL doesn't support OR yet...  Otherwise we'd be using that.
        for comment in models.Comment.gql(
                'WHERE patch = :1 AND left = FALSE ORDER BY date', patch):
            if comment.draft and comment.author != request.user:
                continue  # Only show your own drafts
            comment.complete(patch)
            lst = dct.setdefault(comment.lineno, [])
            lst.append(comment)
            library.prefetch_names([comment.author])
    return _TableRowGenerator(old_patch, old_dict,
                              len(old_lines) + 1, 'new', new_patch, new_dict,
                              len(new_lines) + 1, 'new',
                              _GenerateTriples(old_lines, new_lines), colwidth,
                              debug)
Esempio n. 4
0
def _RenderDiff2TableRows(request, old_lines, old_patch, new_lines, new_patch,
                         colwidth, debug=False):
  """Internal version of RenderDiff2TableRows().

  Args:
    The same as for RenderDiff2TableRows.

  Yields:
    Tuples (tag, row) where tag is an indication of the row type.
  """
  old_dict = {}
  new_dict = {}
  for patch, dct in [(old_patch, old_dict), (new_patch, new_dict)]:
    # XXX GQL doesn't support OR yet...  Otherwise we'd be using that.
    for comment in models.Comment.gql(
        'WHERE patch = :1 AND left = FALSE ORDER BY date', patch):
      if comment.draft and comment.author != request.user:
        continue  # Only show your own drafts
      comment.complete(patch)
      lst = dct.setdefault(comment.lineno, [])
      lst.append(comment)
      library.prefetch_names([comment.author])
  return _TableRowGenerator(old_patch, old_dict, len(old_lines)+1, 'new',
                            new_patch, new_dict, len(new_lines)+1, 'new',
                            _GenerateTriples(old_lines, new_lines),
                            colwidth, debug)