Beispiel #1
0
def createComment(request, set_id, file_id):
  if request.method == 'POST':
    try:
      user = User.objects.get(pk=request.user.id)
    except User.DoesNotExist:
      # TODO
      print "User not found"

    form = CommentForm(request.POST)
    if form.is_valid():
      cd = form.cleaned_data

      # This method handles comment creation and modification
      if int(request.POST['comment_id']) > 0:
        comment = DiffComment.objects.get(pk=request.POST['comment_id'])
        comment.comment = cd['message']
      else:
        comment = DiffComment(
          comment=cd['message'],
          line_number=cd['line_number'],
          user_id=user,
          file_id=FileDiff.objects.get(pk=file_id))
      comment.save()

  return HttpResponseRedirect(reverse('reviews.views.diff',
                              args=(set_id,file_id)))
Beispiel #2
0
def analyze(fileID):
  try:
    filediff = FileDiff.objects.get(pk=fileID)
  except:
    return

  length_limit = 80

  if filediff.deleted:
    return

  stylebot = User.objects.get(username='******')

  for index, line in enumerate(filediff.get_new_file().file_data.split('\n')):
    if len(line) > length_limit:
      comment = DiffComment(
                  user_id=stylebot,
                  file_id=filediff,
                  comment="Exceeds %d characters" % length_limit,
                  line_number=index+1)
      comment.save()