changeset 2296:e5c0f201ca0b codereview

Add changeset status change into emails
author Marcin Kuzminski <marcin@python-works.com>
date Thu, 17 May 2012 12:54:44 +0200
parents 8447d35b674e
children d3f1b71099ab
files rhodecode/controllers/changeset.py rhodecode/model/comment.py rhodecode/model/db.py rhodecode/model/notification.py rhodecode/templates/email_templates/changeset_comment.html
diffstat 5 files changed, 25 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/controllers/changeset.py	Thu May 17 00:47:45 2012 +0200
+++ b/rhodecode/controllers/changeset.py	Thu May 17 12:54:44 2012 +0200
@@ -368,18 +368,22 @@
 
     @jsonify
     def comment(self, repo_name, revision):
+        status = request.POST.get('changeset_status')
+        change_status = request.POST.get('change_changeset_status')
+
         comm = ChangesetCommentsModel().create(
             text=request.POST.get('text'),
             repo_id=c.rhodecode_db_repo.repo_id,
             user_id=c.rhodecode_user.user_id,
             revision=revision,
             f_path=request.POST.get('f_path'),
-            line_no=request.POST.get('line')
+            line_no=request.POST.get('line'),
+            status_change=(ChangesetStatus.get_status_lbl(status) 
+                           if status and change_status else None)
         )
 
         # get status if set !
-        status = request.POST.get('changeset_status')
-        if status and request.POST.get('change_changeset_status'):
+        if status and change_status:
             ChangesetStatusModel().set_status(
                 c.rhodecode_db_repo.repo_id,
                 revision,
--- a/rhodecode/model/comment.py	Thu May 17 00:47:45 2012 +0200
+++ b/rhodecode/model/comment.py	Thu May 17 12:54:44 2012 +0200
@@ -52,9 +52,10 @@
         return user_objects
 
     def create(self, text, repo_id, user_id, revision, f_path=None,
-               line_no=None):
+               line_no=None, status_change=None):
         """
-        Creates new comment for changeset
+        Creates new comment for changeset. IF status_change is not none
+        this comment is associated with a status change of changeset
 
         :param text:
         :param repo_id:
@@ -62,6 +63,7 @@
         :param revision:
         :param f_path:
         :param line_no:
+        :param status_change:
         """
 
         if text:
@@ -104,7 +106,8 @@
 
             NotificationModel().create(
               created_by=user_id, subject=subj, body=body,
-              recipients=recipients, type_=Notification.TYPE_CHANGESET_COMMENT
+              recipients=recipients, type_=Notification.TYPE_CHANGESET_COMMENT,
+              email_kwargs={'status_change': status_change}
             )
 
             mention_recipients = set(self._extract_mentions(body))\
--- a/rhodecode/model/db.py	Thu May 17 00:47:45 2012 +0200
+++ b/rhodecode/model/db.py	Thu May 17 12:54:44 2012 +0200
@@ -1256,9 +1256,13 @@
     repo = relationship('Repository')
     comment = relationship('ChangesetComment', lazy='joined')
 
+    @classmethod
+    def get_status_lbl(cls, value):
+        return dict(cls.STATUSES).get(value)
+
     @property
     def status_lbl(self):
-        return dict(self.STATUSES).get(self.status)
+        return ChangesetStatus.get_status_lbl(self.status)
 
 
 class Notification(Base, BaseModel):
--- a/rhodecode/model/notification.py	Thu May 17 00:47:45 2012 +0200
+++ b/rhodecode/model/notification.py	Thu May 17 12:54:44 2012 +0200
@@ -108,6 +108,7 @@
             email_subject = NotificationModel().make_description(notif, False)
             type_ = type_
             email_body = body
+            ## this is passed into template
             kwargs = {'subject': subject, 'body': h.rst_w_mentions(body)}
             kwargs.update(email_kwargs)
             email_body_html = EmailNotificationModel()\
--- a/rhodecode/templates/email_templates/changeset_comment.html	Thu May 17 00:47:45 2012 +0200
+++ b/rhodecode/templates/email_templates/changeset_comment.html	Thu May 17 12:54:44 2012 +0200
@@ -4,3 +4,9 @@
 <h4>${subject}</h4>
 
 ${body}
+
+% if status_change is not None:
+<div>
+    New status -> ${status_change}
+</div>    
+% endif
\ No newline at end of file