Re: [PATCH 40/46] patch: Single out the commit message

2014-11-10 Thread Jeremy Kerr

Hi Damien,


All 'Comments' are stored the same way in the db, but I believe it's
worth making the distinction between introducing what the patch does and
eventual review comments.

Signed-off-by: Damien Lespiau 
---
  apps/patchwork/models.py   | 11 ++-
  templates/patchwork/patch.html | 18 +-
  2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/apps/patchwork/models.py b/apps/patchwork/models.py
index 4bed9b8..b9c7794 100644
--- a/apps/patchwork/models.py
+++ b/apps/patchwork/models.py
@@ -188,7 +188,16 @@ class Patch(models.Model):
  return self.name

  def comments(self):
-return Comment.objects.filter(patch = self)
+comments = Comment.objects.filter(patch = self)
+# len() will trigger a queryset evaluation. That's what we want as
+# we need the full list of comments. That the list is then sliced into
+# (commit message, list of followup comments) won't hit the db twice.
+n_comments = len(comments)
+if n_comments > 2:
+return (comments[0], comments[1:])
+if n_comments == 1:
+return (comments[0], ())
+return (None, ())


This doesn't guarantee that you'll pick the correct comment for the 
commit message - you need to find the comment that has the same 
message-id as the patch.


Also, could we have this as a separate function? I'd like to 
Patch.comments() for the complete set as a single list. Your template 
might be a bit cleaner if have separate functions for 
commit-message-comments and follow-up-comments too.


Cheers,


Jeremy

___
Patchwork mailing list
Patchwork@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/patchwork


[PATCH 40/46] patch: Single out the commit message

2014-11-08 Thread Damien Lespiau
All 'Comments' are stored the same way in the db, but I believe it's
worth making the distinction between introducing what the patch does and
eventual review comments.

Signed-off-by: Damien Lespiau 
---
 apps/patchwork/models.py   | 11 ++-
 templates/patchwork/patch.html | 18 +-
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/apps/patchwork/models.py b/apps/patchwork/models.py
index 4bed9b8..b9c7794 100644
--- a/apps/patchwork/models.py
+++ b/apps/patchwork/models.py
@@ -188,7 +188,16 @@ class Patch(models.Model):
 return self.name
 
 def comments(self):
-return Comment.objects.filter(patch = self)
+comments = Comment.objects.filter(patch = self)
+# len() will trigger a queryset evaluation. That's what we want as
+# we need the full list of comments. That the list is then sliced into
+# (commit message, list of followup comments) won't hit the db twice.
+n_comments = len(comments)
+if n_comments > 2:
+return (comments[0], comments[1:])
+if n_comments == 1:
+return (comments[0], ())
+return (None, ())
 
 def save(self):
 try:
diff --git a/templates/patchwork/patch.html b/templates/patchwork/patch.html
index 6540060..618f08e 100644
--- a/templates/patchwork/patch.html
+++ b/templates/patchwork/patch.html
@@ -177,8 +177,22 @@ function toggle_headers(link_id, headers_id)
  >{{ patch.pull_url }}
 {% endif %}
 
+{% for item in patch.comments %}
+
+{% if forloop.first %}
+{% if item %}
+Commit Message
+
+{{ item.submitter|personify }} - {{item.date}}
+
+{{ item|commentsyntax }}
+
+
+{% endif %}
+{% elif item %}
 Comments
-{% for comment in patch.comments %}
+
+{% for comment in item %}
 
 {{ comment.submitter|personify }} - {{comment.date}}
 
@@ -186,6 +200,8 @@ function toggle_headers(link_id, headers_id)
 
 
 {% endfor %}
+{% endif %}
+{% endfor %}
 
 {% if patch.content %}
 Patch
-- 
1.8.3.1

___
Patchwork mailing list
Patchwork@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/patchwork