mirror of
https://github.com/correl/codereview.git
synced 2025-01-14 19:12:04 +00:00
Cleaned up review comments a bit, added basic display code
This commit is contained in:
parent
4eaa6ee206
commit
5c17560ece
4 changed files with 46 additions and 27 deletions
|
@ -3,12 +3,9 @@ from django.contrib import admin
|
||||||
|
|
||||||
class CommentInline(admin.StackedInline):
|
class CommentInline(admin.StackedInline):
|
||||||
model = Comment
|
model = Comment
|
||||||
class ItemInline(admin.StackedInline):
|
|
||||||
model = Item
|
|
||||||
inlines = [CommentInline]
|
|
||||||
|
|
||||||
class ReviewAdmin(admin.ModelAdmin):
|
class ReviewAdmin(admin.ModelAdmin):
|
||||||
inlines = [
|
inlines = [
|
||||||
ItemInline
|
CommentInline,
|
||||||
]
|
]
|
||||||
admin.site.register(Review, ReviewAdmin)
|
admin.site.register(Review, ReviewAdmin)
|
||||||
|
|
|
@ -1,23 +1,45 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from codereview.dashboard.models import Repository
|
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):
|
class Review(models.Model):
|
||||||
author = models.ForeignKey(User)
|
author = models.ForeignKey(User)
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
description = models.TextField()
|
description = models.TextField()
|
||||||
|
repo = models.ForeignKey(Repository)
|
||||||
|
ref = models.CharField(max_length=40)
|
||||||
|
parent = models.CharField(max_length=40)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return 'Review #{0}'.format(self.pk)
|
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):
|
class Comment(models.Model):
|
||||||
item = models.ForeignKey(Item)
|
review = models.ForeignKey(Review)
|
||||||
author = models.ForeignKey(User)
|
author = models.ForeignKey(User)
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
blob = models.IntegerField()
|
path = models.TextField()
|
||||||
offset = models.IntegerField()
|
line_a = models.IntegerField()
|
||||||
|
line_b = models.IntegerField(null=True)
|
||||||
text = models.TextField()
|
text = models.TextField()
|
||||||
|
|
|
@ -5,7 +5,7 @@ from django.core.urlresolvers import reverse
|
||||||
from django.contrib.auth.decorators import permission_required
|
from django.contrib.auth.decorators import permission_required
|
||||||
from codereview.browser import vcs
|
from codereview.browser import vcs
|
||||||
from codereview.dashboard.models import Repository
|
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
|
from codereview.review.forms import NewCommitReviewForm
|
||||||
|
|
||||||
@permission_required('review.add_review')
|
@permission_required('review.add_review')
|
||||||
|
@ -18,12 +18,12 @@ def new(request):
|
||||||
repo = vcs.create(repository.type, repository.path)
|
repo = vcs.create(repository.type, repository.path)
|
||||||
commit = repo.commit(form.cleaned_data['ref'])
|
commit = repo.commit(form.cleaned_data['ref'])
|
||||||
description = commit.message.split('\n')[0].strip()
|
description = commit.message.split('\n')[0].strip()
|
||||||
review = Review.objects.create(author=request.user,
|
review = Review.objects.create(
|
||||||
description=description)
|
author=request.user,
|
||||||
item = Item.objects.create(
|
|
||||||
review=review,
|
|
||||||
repo=repository,
|
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]))
|
return HttpResponseRedirect(reverse(edit, args=[review.pk]))
|
||||||
@permission_required('review.change_review')
|
@permission_required('review.change_review')
|
||||||
def edit(request, review_id):
|
def edit(request, review_id):
|
||||||
|
@ -31,14 +31,10 @@ def edit(request, review_id):
|
||||||
review = Review.objects.get(pk=review_id)
|
review = Review.objects.get(pk=review_id)
|
||||||
except:
|
except:
|
||||||
raise Http404
|
raise Http404
|
||||||
# TODO: Support multiple items per review (?)
|
repo = vcs.create(review.repo.type, review.repo.path)
|
||||||
item = review.item_set.get()
|
diffs = repo.diff(review.ref, review.parent if review.parent else None)
|
||||||
repo = vcs.create(item.repo.type, item.repo.path)
|
|
||||||
commit = repo.commit(item.ref)
|
|
||||||
diffs = repo.diff(commit.id)
|
|
||||||
data = RequestContext(request, {
|
data = RequestContext(request, {
|
||||||
"review": review,
|
"review": review,
|
||||||
"commit": commit,
|
|
||||||
"diffs": diffs,
|
"diffs": diffs,
|
||||||
})
|
})
|
||||||
return render_to_response('review/edit.html', data)
|
return render_to_response('review/edit.html', data)
|
||||||
|
|
|
@ -19,16 +19,20 @@
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
{# TODO: Load in annotations somehow #}
|
{# 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">
|
<tr class="annotation">
|
||||||
<td colspan="3">
|
<td colspan="3">
|
||||||
<div class="annotation">
|
<div class="annotation">
|
||||||
<strong>Author @ Date:</strong>
|
<strong>{{ comment.author }} @ {{ comment.created }}:</strong>
|
||||||
<p>Comment</p>
|
<p>{{ comment.text }}</p>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|
Loading…
Reference in a new issue