diff --git a/review/admin.py b/review/admin.py index e5e5647..5e61325 100644 --- a/review/admin.py +++ b/review/admin.py @@ -3,12 +3,9 @@ from django.contrib import admin class CommentInline(admin.StackedInline): model = Comment -class ItemInline(admin.StackedInline): - model = Item - inlines = [CommentInline] class ReviewAdmin(admin.ModelAdmin): inlines = [ - ItemInline + CommentInline, ] admin.site.register(Review, ReviewAdmin) diff --git a/review/models.py b/review/models.py index 6df8a9a..f09468d 100755 --- a/review/models.py +++ b/review/models.py @@ -1,23 +1,45 @@ from django.db import models from django.contrib.auth.models import User from codereview.dashboard.models import Repository +from codereview.browser import vcs + +""" +Requirements: + +i. + Must be able to review a changeset as a collection of blobs at a certain + revision, with diff information. Comments apply to any line of a unified diff + containing all context. + + * Single revision plus parent revision + * At least one valid (modified) path + * Line based on diff with full context. + +ii. + Must be able to review a blob or collection of blobs at a certain revision + without diff information. Comments apply to any line of raw blob text. + + * Single revision + * At least one valid path + * Line based on raw path text +""" class Review(models.Model): author = models.ForeignKey(User) created = models.DateTimeField(auto_now_add=True) description = models.TextField() + repo = models.ForeignKey(Repository) + ref = models.CharField(max_length=40) + parent = models.CharField(max_length=40) def __unicode__(self): return 'Review #{0}'.format(self.pk) -class Item(models.Model): - review = models.ForeignKey(Review) - repo = models.ForeignKey(Repository) - ref = models.CharField(max_length=40) - path = models.TextField() + class Comment(models.Model): - item = models.ForeignKey(Item) + review = models.ForeignKey(Review) author = models.ForeignKey(User) created = models.DateTimeField(auto_now_add=True) - blob = models.IntegerField() - offset = models.IntegerField() + path = models.TextField() + line_a = models.IntegerField() + line_b = models.IntegerField(null=True) text = models.TextField() diff --git a/review/views.py b/review/views.py index c91eee8..f34ddae 100755 --- a/review/views.py +++ b/review/views.py @@ -5,7 +5,7 @@ from django.core.urlresolvers import reverse from django.contrib.auth.decorators import permission_required from codereview.browser import vcs from codereview.dashboard.models import Repository -from codereview.review.models import Review, Item, Comment +from codereview.review.models import Review, Comment from codereview.review.forms import NewCommitReviewForm @permission_required('review.add_review') @@ -18,12 +18,12 @@ def new(request): repo = vcs.create(repository.type, repository.path) commit = repo.commit(form.cleaned_data['ref']) description = commit.message.split('\n')[0].strip() - review = Review.objects.create(author=request.user, - description=description) - item = Item.objects.create( - review=review, + review = Review.objects.create( + author=request.user, repo=repository, - ref=commit.id) + ref=commit.id, + parent=commit.parents[0] if commit.parents else None, + description=description) return HttpResponseRedirect(reverse(edit, args=[review.pk])) @permission_required('review.change_review') def edit(request, review_id): @@ -31,14 +31,10 @@ def edit(request, review_id): review = Review.objects.get(pk=review_id) except: raise Http404 - # TODO: Support multiple items per review (?) - item = review.item_set.get() - repo = vcs.create(item.repo.type, item.repo.path) - commit = repo.commit(item.ref) - diffs = repo.diff(commit.id) + repo = vcs.create(review.repo.type, review.repo.path) + diffs = repo.diff(review.ref, review.parent if review.parent else None) data = RequestContext(request, { "review": review, - "commit": commit, "diffs": diffs, }) return render_to_response('review/edit.html', data) diff --git a/templates/components/diff.html b/templates/components/diff.html index 49d62f3..0f5b37f 100644 --- a/templates/components/diff.html +++ b/templates/components/diff.html @@ -19,16 +19,20 @@ {# TODO: Load in annotations somehow #} - {% if change.annotation %} + {% if review %} + {% for comment in review.comment_set.all %} + {% if change.type != '+' and change.line_a == comment.line_a or change_type != '-' and change.line_b == comment.line_b %}
Comment
+ {{ comment.author }} @ {{ comment.created }}: +{{ comment.text }}