Cleaned up review comments a bit, added basic display code

This commit is contained in:
Correl Roush 2010-12-13 00:33:04 -05:00
parent 4eaa6ee206
commit 5c17560ece
4 changed files with 46 additions and 27 deletions

View file

@ -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)

View file

@ -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()

View file

@ -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)

View file

@ -19,16 +19,20 @@
</tr>
{# 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 %}
<tr class="annotation">
<td colspan="3">
<div class="annotation">
<strong>Author @ Date:</strong>
<p>Comment</p>
<strong>{{ comment.author }} @ {{ comment.created }}:</strong>
<p>{{ comment.text }}</p>
</div>
</td>
</tr>
{% endif %}
{% endfor %}
{% endif %}
{% endif %}
{% endfor %}
</table>