mirror of
https://github.com/correl/codereview.git
synced 2025-01-13 11:01:55 +00:00
Enabled review creation on a changeset
Does not yet support commenting
This commit is contained in:
parent
3b17fca150
commit
3e77959aaa
11 changed files with 115 additions and 3 deletions
|
@ -4,6 +4,7 @@ from django.shortcuts import render_to_response
|
|||
from django.template import RequestContext
|
||||
from django.contrib.auth.decorators import permission_required
|
||||
from codereview.dashboard.models import Repository
|
||||
from codereview.review.forms import NewCommitReviewForm
|
||||
from codereview.browser import vcs
|
||||
|
||||
def _repo(request, name):
|
||||
|
@ -57,6 +58,11 @@ def commit(request, repository, ref):
|
|||
repo = vcs.create(repository.type, repository.path)
|
||||
commit = repo.commit(ref)
|
||||
diffs = repo.diff(ref)
|
||||
form = NewCommitReviewForm({
|
||||
'author': request.user.pk,
|
||||
'repo': repository.pk,
|
||||
'ref': ref
|
||||
})
|
||||
|
||||
data = RequestContext(request, {
|
||||
'repository': repository,
|
||||
|
@ -64,6 +70,7 @@ def commit(request, repository, ref):
|
|||
'ref': ref,
|
||||
'commit': commit,
|
||||
'diffs': diffs,
|
||||
'form': form,
|
||||
})
|
||||
return render_to_response('browser/view.html', data)
|
||||
@permission_required('dashboard.browse')
|
||||
|
|
|
@ -93,3 +93,6 @@ table.diff .del .text {
|
|||
table.diff td {
|
||||
font-family: monospace;
|
||||
}
|
||||
table.diff tr.annotation td {
|
||||
white-space: normal;
|
||||
}
|
||||
|
|
14
review/admin.py
Normal file
14
review/admin.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
from codereview.review.models import *
|
||||
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
|
||||
]
|
||||
admin.site.register(Review, ReviewAdmin)
|
7
review/forms.py
Normal file
7
review/forms.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
from django import forms
|
||||
from codereview.review.models import *
|
||||
|
||||
class NewCommitReviewForm(forms.Form):
|
||||
author = forms.IntegerField(widget=forms.HiddenInput)
|
||||
repo = forms.IntegerField(widget=forms.HiddenInput)
|
||||
ref = forms.CharField(widget=forms.HiddenInput)
|
|
@ -1,14 +1,17 @@
|
|||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
from codereview.dashboard.models import Repository
|
||||
|
||||
class Review(models.Model):
|
||||
author = models.ForeignKey(User)
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
description = models.TextField()
|
||||
|
||||
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):
|
||||
|
|
6
review/urls.py
Normal file
6
review/urls.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.conf.urls.defaults import *
|
||||
|
||||
urlpatterns = patterns('',
|
||||
(r'^new/$', 'codereview.review.views.new'),
|
||||
(r'^edit/(?P<review_id>\d+)/$', 'codereview.review.views.edit'),
|
||||
)
|
|
@ -1 +1,44 @@
|
|||
# Create your views here.
|
||||
from django.http import Http404, HttpResponseRedirect
|
||||
from django.shortcuts import render_to_response
|
||||
from django.template import RequestContext
|
||||
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.forms import NewCommitReviewForm
|
||||
|
||||
@permission_required('review.add_review')
|
||||
def new(request):
|
||||
if not request.POST:
|
||||
raise Http404
|
||||
form = NewCommitReviewForm(request.POST)
|
||||
if form.is_valid():
|
||||
repository = Repository.objects.get(pk=form.cleaned_data['repo'])
|
||||
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=commit.message)
|
||||
item = Item.objects.create(
|
||||
review=review,
|
||||
repo=repository,
|
||||
ref=commit.id)
|
||||
return HttpResponseRedirect(reverse(edit, args=[review.pk]))
|
||||
@permission_required('review.change_review')
|
||||
def edit(request, review_id):
|
||||
try:
|
||||
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)
|
||||
data = RequestContext(request, {
|
||||
"review": review,
|
||||
"commit": commit,
|
||||
"diffs": diffs,
|
||||
})
|
||||
return render_to_response('review/edit.html', data)
|
||||
|
|
|
@ -30,6 +30,11 @@
|
|||
</dd>
|
||||
</dl>
|
||||
|
||||
<form name="review" method="post" action="{% url codereview.review.views.new%}">
|
||||
{{ form }}
|
||||
{% csrf_token %}
|
||||
<input type="submit" value="Create New Review" />
|
||||
</form>
|
||||
<div class="diff-container">
|
||||
<div class="diff-html">
|
||||
{% for diff in diffs %}
|
||||
|
|
|
@ -17,8 +17,18 @@
|
|||
<td class="number">{% if change.type != '-' %}{{ change.line_b }}{% endif %}</td>
|
||||
<td class="text">{{ change.text }}</td>
|
||||
</tr>
|
||||
{% block annotations %}
|
||||
{% endblock %}
|
||||
|
||||
{# TODO: Load in annotations somehow #}
|
||||
{% if change.annotation %}
|
||||
<tr class="annotation">
|
||||
<td colspan="3">
|
||||
<div class="annotation">
|
||||
<strong>Author @ Date:</strong>
|
||||
<p>Comment</p>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
|
13
templates/review/edit.html
Normal file
13
templates/review/edit.html
Normal file
|
@ -0,0 +1,13 @@
|
|||
{% extends "layouts/default.html" %}
|
||||
|
||||
{% block annotations %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2>#{{ review.pk }} - <span id="review-description">{{ review.description }}</span></h2>
|
||||
|
||||
{% for diff in diffs %}
|
||||
{% include "components/diff.html" %}
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
|
1
urls.py
1
urls.py
|
@ -11,6 +11,7 @@ urlpatterns = patterns('',
|
|||
(r'^browser/', include('codereview.browser.urls')),
|
||||
|
||||
(r'^dashboard/', include('codereview.dashboard.urls')),
|
||||
(r'^review/', include('codereview.review.urls')),
|
||||
|
||||
# Uncomment the admin/doc line below and add 'django.contrib.admindocs'
|
||||
# to INSTALLED_APPS to enable admin documentation:
|
||||
|
|
Loading…
Reference in a new issue