diff --git a/media/default.css b/media/default.css index da05765..c3c3432 100644 --- a/media/default.css +++ b/media/default.css @@ -103,3 +103,9 @@ table.diff td { table.diff tr.annotation td { white-space: normal; } + +.comment-form textarea { + display: block; + width: 90%; + height: 3em; +} diff --git a/review/forms.py b/review/forms.py index ba96e66..d270587 100644 --- a/review/forms.py +++ b/review/forms.py @@ -5,3 +5,7 @@ class NewCommitReviewForm(forms.Form): author = forms.IntegerField(widget=forms.HiddenInput) repo = forms.IntegerField(widget=forms.HiddenInput) ref = forms.CharField(widget=forms.HiddenInput) +class CommentForm(forms.ModelForm): + class Meta: + model = Comment + fields = ('review', 'line_a', 'line_b', 'text') diff --git a/review/models.py b/review/models.py index f09468d..310bde2 100755 --- a/review/models.py +++ b/review/models.py @@ -40,6 +40,6 @@ class Comment(models.Model): author = models.ForeignKey(User) created = models.DateTimeField(auto_now_add=True) path = models.TextField() - line_a = models.IntegerField() + line_a = models.IntegerField(null=True) line_b = models.IntegerField(null=True) text = models.TextField() diff --git a/review/urls.py b/review/urls.py index 96f5e45..8baee1c 100644 --- a/review/urls.py +++ b/review/urls.py @@ -3,4 +3,5 @@ from django.conf.urls.defaults import * urlpatterns = patterns('', (r'^(?P\d+)/$', 'codereview.review.views.edit'), (r'^new/$', 'codereview.review.views.new'), + (r'^comment/new/$', 'codereview.review.views.add_comment'), ) diff --git a/review/views.py b/review/views.py index f34ddae..d14ee16 100755 --- a/review/views.py +++ b/review/views.py @@ -6,7 +6,7 @@ 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, Comment -from codereview.review.forms import NewCommitReviewForm +from codereview.review.forms import NewCommitReviewForm, CommentForm @permission_required('review.add_review') def new(request): @@ -38,3 +38,21 @@ def edit(request, review_id): "diffs": diffs, }) return render_to_response('review/edit.html', data) +@permission_required('review.add_comment') +def add_comment(request): + review_id = request.POST.get('review') + try: + review = Review.objects.get(pk=review_id) + path = int(request.POST.get('path')) + except: + raise Http404 + repo = vcs.create(review.repo.type, review.repo.path) + diffs = repo.diff(review.ref, review.parent if review.parent else None) + + form = CommentForm(request.POST) + comment = form.save(commit=False) + diff = diffs[path] + comment.author = request.user + comment.path = diff.b.path if diff.b else diff.a.path + comment.save() + return HttpResponseRedirect(reverse(edit, args=[review.pk])) diff --git a/templates/components/diff.html b/templates/components/diff.html index 0f5b37f..2e5edb4 100644 --- a/templates/components/diff.html +++ b/templates/components/diff.html @@ -12,7 +12,8 @@ {{ change.text }} {% else %} - + {% if change.type != '+' %}{{ change.line_a }}{% endif %} {% if change.type != '-' %}{{ change.line_b }}{% endif %} {{ change.text }} diff --git a/templates/review/edit.html b/templates/review/edit.html index c24cfcc..8d0a7cc 100644 --- a/templates/review/edit.html +++ b/templates/review/edit.html @@ -4,6 +4,34 @@ {% endblock %} {% block content %} +

#{{ review.pk }} - {{ review.description }}

{% for diff in diffs %}