changeset 2937:d439d408b415 beta

Update last_change from VCS data on request. - lightweight dashboard shows now last_date also taken from db and it is fast !
author Marcin Kuzminski <marcin@python-works.com>
date Thu, 18 Oct 2012 20:54:25 +0200
parents 62e493c7f436
children 0497d9d9e0c8
files rhodecode/controllers/home.py rhodecode/lib/base.py rhodecode/model/db.py rhodecode/templates/data_table/_dt_elements.html rhodecode/templates/index_base.html
diffstat 5 files changed, 21 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/controllers/home.py	Thu Oct 18 20:16:00 2012 +0200
+++ b/rhodecode/controllers/home.py	Thu Oct 18 20:54:25 2012 +0200
@@ -70,6 +70,8 @@
                 template.get_def("repo_name")
                 .render(name, rtype, private, fork_of, short_name=False,
                         admin=False, _=_, h=h, c=c))
+            last_change = lambda last_change:  (template.get_def("last_change")
+                                           .render(last_change, _=_, h=h, c=c))
             rss_lnk = lambda repo_name: (template.get_def("rss")
                                            .render(repo_name, _=_, h=h, c=c))
             atom_lnk = lambda repo_name: (template.get_def("atom")
@@ -81,7 +83,7 @@
                     "raw_name": repo.repo_name.lower(),
                     "name": repo_lnk(repo.repo_name, repo.repo_type,
                                      repo.private, repo.fork),
-                    "last_change": h.age(repo.last_db_change),
+                    "last_change": last_change(repo.last_db_change),
                     "desc": repo.description,
                     "owner": h.person(repo.user.username),
                     "rss": rss_lnk(repo.repo_name),
--- a/rhodecode/lib/base.py	Thu Oct 18 20:16:00 2012 +0200
+++ b/rhodecode/lib/base.py	Thu Oct 18 20:54:25 2012 +0200
@@ -307,7 +307,8 @@
 
             dbr = c.rhodecode_db_repo = Repository.get_by_repo_name(c.repo_name)
             c.rhodecode_repo = c.rhodecode_db_repo.scm_instance
-
+            # update last change according to VCS data
+            dbr.update_last_change(c.rhodecode_repo.last_change)
             if c.rhodecode_repo is None:
                 log.error('%s this repository is present in database but it '
                           'cannot be created as an scm instance', c.repo_name)
--- a/rhodecode/model/db.py	Thu Oct 18 20:16:00 2012 +0200
+++ b/rhodecode/model/db.py	Thu Oct 18 20:54:25 2012 +0200
@@ -874,6 +874,15 @@
         cs = self.get_changeset(self.landing_rev) or self.get_changeset()
         return cs
 
+    def update_last_change(self, last_change=None):
+        if last_change is None:
+            last_change = datetime.datetime.now()
+        if self.updated_on is None or self.updated_on != last_change:
+            log.debug('updated repo %s with new date %s' % (self, last_change))
+            self.updated_on = last_change
+            Session().add(self)
+            Session().commit()
+
     @property
     def tip(self):
         return self.get_changeset('tip')
--- a/rhodecode/templates/data_table/_dt_elements.html	Thu Oct 18 20:16:00 2012 +0200
+++ b/rhodecode/templates/data_table/_dt_elements.html	Thu Oct 18 20:54:25 2012 +0200
@@ -82,7 +82,9 @@
   </div>
 </%def>
 
-
+<%def name="last_change(last_change)">
+  <span class="tooltip" date="${last_change}" title="${h.tooltip(h.fmt_date(last_change))}">${h.age(last_change)}</span>
+</%def>
 
 <%def name="revision(name,rev,tip,author,last_msg)">
   <div>
--- a/rhodecode/templates/index_base.html	Thu Oct 18 20:16:00 2012 +0200
+++ b/rhodecode/templates/index_base.html	Thu Oct 18 20:54:25 2012 +0200
@@ -98,7 +98,7 @@
                     </td>
                     ##LAST CHANGE DATE
                     <td>
-                      <span class="tooltip" date="${repo['last_change']}" title="${h.tooltip(h.fmt_date(repo['last_change']))}">${h.age(repo['last_change'])}</span>
+                      ${dt.last_change(repo['last_change'])}
                     </td>
                     ##LAST REVISION
                     <td>
@@ -232,7 +232,7 @@
                {key:"raw_name"},
                {key:"name"},
                {key:"desc"},
-               //{key:"last_change"},
+               {key:"last_change"},
                {key:"owner"},
                {key:"rss"},
                {key:"atom"},
@@ -264,8 +264,8 @@
             {key:"name",label:"${_('Name')}",sortable:true,
                 sortOptions: { sortFunction: nameSort }},
             {key:"desc",label:"${_('Description')}",sortable:true},
-            //{key:"last_change",label:"${_('Last Change')}",sortable:true,
-            //    sortOptions: { sortFunction: ageSort }},
+            {key:"last_change",label:"${_('Last Change')}",sortable:true,
+                sortOptions: { sortFunction: ageSort }},
             {key:"owner",label:"${_('Owner')}",sortable:true},
             {key:"rss",label:"",sortable:false},
             {key:"atom",label:"",sortable:false},