{"id":1200,"date":"2010-12-31T17:07:40","date_gmt":"2010-12-31T16:07:40","guid":{"rendered":"http:\/\/blog.fh-kaernten.at\/wehr\/?p=1200"},"modified":"2010-12-31T17:26:27","modified_gmt":"2010-12-31T16:26:27","slug":"last-login-patch-for-trac-usermanager-plugin","status":"publish","type":"post","link":"https:\/\/blog.fh-kaernten.at\/wehr\/2010\/12\/31\/last-login-patch-for-trac-usermanager-plugin\/","title":{"rendered":"Last login patch for Trac UserManager plugin"},"content":{"rendered":"<p id=\"top\" \/>\n<p>I just have added a <em>visit motivation <\/em>feature to the <a href=\"http:\/\/trac.edgewall.org\/\">Trac <\/a><a href=\"http:\/\/trac-hacks.org\/wiki\/UserManagerPlugin\">Usermanager <\/a>plugin. With the included patch set you will get an additional column<strong> Last Login<\/strong> in the &#8220;UserProfilesList&#8221; macro.<\/p>\n<p><a href=\"http:\/\/blog.fh-kaernten.at\/wehr\/files\/2010\/12\/last_loggin2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1213\" title=\"last_loggin\" src=\"https:\/\/blog.fh-kaernten.at\/wehr\/files\/2010\/12\/last_loggin2.jpg\" alt=\"\" width=\"571\" height=\"351\" \/><\/a><\/p>\n<p>This patch applies to <a href=\"wordpress syntac higlight\">UserManager <\/a>plugin rev 5520\u00a0 \ud83d\ude42<\/p>\n<pre class=\"brush:diff\">--- macros.py\t(revision 300)\r\n+++ macros.py\t(revision 301)\r\n@@ -10,6 +10,8 @@\r\n from trac.wiki.macros import WikiMacroBase\r\n from trac.wiki.formatter import wiki_to_html\r\n from trac.web.chrome import Chrome, add_stylesheet, add_script\r\n-from trac.util.datefmt import format_datetime\r\n+from trac.util.datefmt import format_datetime, to_datetime\r\n+from datetime import datetime\r\n\r\n from tracusermanager.api import UserManager, User\r\n from tracusermanager.profile.api import UserProfileManager, IUserProfilesListMacroCellContributor\r\n@@ -72,9 +73,29 @@\r\n             data['user_profiles'] = UserManager(self.env).search_users(user_profile_templates)\r\n         else:\r\n             data['user_profiles'] = UserManager(self.env).get_active_users()\r\n-\r\n+\r\n+        db = self.env.get_db_cnx()\r\n+        cursor = db.cursor()\r\n+        cursor.execute(\"SELECT sid,last_visit FROM session WHERE authenticated=1\")\r\n+        last_visits={}\r\n+        for username, last_visit in cursor:\r\n+          for user in  data['user_profiles']:\r\n+\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 date_diff = datetime.now().date()\u00a0 - datetime.date(to_datetime(last_visit))\r\n+\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if date_diff.days &gt; 1:\r\n+\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 user['last_visit'] = \"%d days ago\" % date_diff.days\r\n+\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 elif date_diff.days == 1:\r\n+\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 user['last_visit'] = \"%d day ago\" % date_diff.days\r\n+\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 else:\r\n+\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 user['last_visit'] = \"today\"\r\n+\r\n+\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 #user['last_visit'] = format_datetime(last_visit,\"%b %d.%m.%Y %H:%M:%S\")\r\n+\r\n+\r\n         data['cells']=list(self._get_cells(data['user_profiles']))\r\n-\r\n+\r\n         # add stylesheet&amp;script\r\n         add_stylesheet(formatter.req,'tracusermanager\/css\/macros_um_profile.css')\r\n         add_script(formatter.req,'tracusermanager\/js\/macros_um_profile.js')\r\n@@ -102,8 +113,9 @@\r\n         yield ('name', _('Name'),0)\r\n         yield ('email', _('Email'),1)\r\n         yield ('role', _('Role'),2)\r\n+        yield ('last_visit', _('Last login'),3)\r\n     def render_userlistmacro_cell(self, cell_name, user):\r\n-        \"\"\"Should render user cell\"\"\"\r\n+        \"\"\"Should render user cell\"\"\"\r\n         return user[cell_name]\r\n\r\n class TeamRosterMacro(UserProfilesListMacro):<\/pre>\n<p>have fun<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I just have added a visit motivation feature to the Trac Usermanager plugin. With the included patch set you will get an additional column Last Login in the &#8220;UserProfilesList&#8221; macro. This patch applies to UserManager plugin rev 5520\u00a0 \ud83d\ude42 &#8212; macros.py (revision 300) +++ macros.py (revision 301) @@ -10,6 +10,8 @@ from trac.wiki.macros import WikiMacroBase &hellip; <a href=\"https:\/\/blog.fh-kaernten.at\/wehr\/2010\/12\/31\/last-login-patch-for-trac-usermanager-plugin\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Last login patch for Trac UserManager plugin<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"ngg_post_thumbnail":0,"footnotes":""},"categories":[7],"tags":[11],"class_list":["post-1200","post","type-post","status-publish","format-standard","hentry","category-cool-tools","tag-trac"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Last login patch for Trac UserManager plugin - Mario&#039;s TinyLab<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blog.fh-kaernten.at\/wehr\/2010\/12\/31\/last-login-patch-for-trac-usermanager-plugin\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Last login patch for Trac UserManager plugin - Mario&#039;s TinyLab\" \/>\n<meta property=\"og:description\" content=\"I just have added a visit motivation feature to the Trac Usermanager plugin. With the included patch set you will get an additional column Last Login in the &#8220;UserProfilesList&#8221; macro. This patch applies to UserManager plugin rev 5520\u00a0 \ud83d\ude42 --- macros.py (revision 300) +++ macros.py (revision 301) @@ -10,6 +10,8 @@ from trac.wiki.macros import WikiMacroBase &hellip; Continue reading Last login patch for Trac UserManager plugin &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blog.fh-kaernten.at\/wehr\/2010\/12\/31\/last-login-patch-for-trac-usermanager-plugin\/\" \/>\n<meta property=\"og:site_name\" content=\"Mario&#039;s TinyLab\" \/>\n<meta property=\"article:published_time\" content=\"2010-12-31T16:07:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2010-12-31T16:26:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/blog.fh-kaernten.at\/wehr\/files\/2010\/12\/last_loggin2.jpg\" \/>\n<meta name=\"author\" content=\"Mario Wehr\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mario Wehr\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/blog.fh-kaernten.at\\\/wehr\\\/2010\\\/12\\\/31\\\/last-login-patch-for-trac-usermanager-plugin\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blog.fh-kaernten.at\\\/wehr\\\/2010\\\/12\\\/31\\\/last-login-patch-for-trac-usermanager-plugin\\\/\"},\"author\":{\"name\":\"Mario Wehr\",\"@id\":\"https:\\\/\\\/blog.fh-kaernten.at\\\/wehr\\\/#\\\/schema\\\/person\\\/8761b4d788b13b547de9ccd6504ce62d\"},\"headline\":\"Last login patch for Trac UserManager plugin\",\"datePublished\":\"2010-12-31T16:07:40+00:00\",\"dateModified\":\"2010-12-31T16:26:27+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/blog.fh-kaernten.at\\\/wehr\\\/2010\\\/12\\\/31\\\/last-login-patch-for-trac-usermanager-plugin\\\/\"},\"wordCount\":47,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/blog.fh-kaernten.at\\\/wehr\\\/2010\\\/12\\\/31\\\/last-login-patch-for-trac-usermanager-plugin\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/blog.fh-kaernten.at\\\/wehr\\\/files\\\/2010\\\/12\\\/last_loggin2.jpg\",\"keywords\":[\"trac\"],\"articleSection\":[\"Cool Stuff\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/blog.fh-kaernten.at\\\/wehr\\\/2010\\\/12\\\/31\\\/last-login-patch-for-trac-usermanager-plugin\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/blog.fh-kaernten.at\\\/wehr\\\/2010\\\/12\\\/31\\\/last-login-patch-for-trac-usermanager-plugin\\\/\",\"url\":\"https:\\\/\\\/blog.fh-kaernten.at\\\/wehr\\\/2010\\\/12\\\/31\\\/last-login-patch-for-trac-usermanager-plugin\\\/\",\"name\":\"Last login patch for Trac UserManager plugin - Mario&#039;s TinyLab\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blog.fh-kaernten.at\\\/wehr\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/blog.fh-kaernten.at\\\/wehr\\\/2010\\\/12\\\/31\\\/last-login-patch-for-trac-usermanager-plugin\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/blog.fh-kaernten.at\\\/wehr\\\/2010\\\/12\\\/31\\\/last-login-patch-for-trac-usermanager-plugin\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/blog.fh-kaernten.at\\\/wehr\\\/files\\\/2010\\\/12\\\/last_loggin2.jpg\",\"datePublished\":\"2010-12-31T16:07:40+00:00\",\"dateModified\":\"2010-12-31T16:26:27+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/blog.fh-kaernten.at\\\/wehr\\\/#\\\/schema\\\/person\\\/8761b4d788b13b547de9ccd6504ce62d\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/blog.fh-kaernten.at\\\/wehr\\\/2010\\\/12\\\/31\\\/last-login-patch-for-trac-usermanager-plugin\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/blog.fh-kaernten.at\\\/wehr\\\/2010\\\/12\\\/31\\\/last-login-patch-for-trac-usermanager-plugin\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/blog.fh-kaernten.at\\\/wehr\\\/2010\\\/12\\\/31\\\/last-login-patch-for-trac-usermanager-plugin\\\/#primaryimage\",\"url\":\"https:\\\/\\\/blog.fh-kaernten.at\\\/wehr\\\/files\\\/2010\\\/12\\\/last_loggin2.jpg\",\"contentUrl\":\"https:\\\/\\\/blog.fh-kaernten.at\\\/wehr\\\/files\\\/2010\\\/12\\\/last_loggin2.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/blog.fh-kaernten.at\\\/wehr\\\/2010\\\/12\\\/31\\\/last-login-patch-for-trac-usermanager-plugin\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/blog.fh-kaernten.at\\\/wehr\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Last login patch for Trac UserManager plugin\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/blog.fh-kaernten.at\\\/wehr\\\/#website\",\"url\":\"https:\\\/\\\/blog.fh-kaernten.at\\\/wehr\\\/\",\"name\":\"Mario&#039;s TinyLab\",\"description\":\"About cool\\\/interesting Projects and Technologies\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/blog.fh-kaernten.at\\\/wehr\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/blog.fh-kaernten.at\\\/wehr\\\/#\\\/schema\\\/person\\\/8761b4d788b13b547de9ccd6504ce62d\",\"name\":\"Mario Wehr\",\"url\":\"https:\\\/\\\/blog.fh-kaernten.at\\\/wehr\\\/author\\\/wehr\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Last login patch for Trac UserManager plugin - Mario&#039;s TinyLab","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blog.fh-kaernten.at\/wehr\/2010\/12\/31\/last-login-patch-for-trac-usermanager-plugin\/","og_locale":"en_US","og_type":"article","og_title":"Last login patch for Trac UserManager plugin - Mario&#039;s TinyLab","og_description":"I just have added a visit motivation feature to the Trac Usermanager plugin. With the included patch set you will get an additional column Last Login in the &#8220;UserProfilesList&#8221; macro. This patch applies to UserManager plugin rev 5520\u00a0 \ud83d\ude42 --- macros.py (revision 300) +++ macros.py (revision 301) @@ -10,6 +10,8 @@ from trac.wiki.macros import WikiMacroBase &hellip; Continue reading Last login patch for Trac UserManager plugin &rarr;","og_url":"https:\/\/blog.fh-kaernten.at\/wehr\/2010\/12\/31\/last-login-patch-for-trac-usermanager-plugin\/","og_site_name":"Mario&#039;s TinyLab","article_published_time":"2010-12-31T16:07:40+00:00","article_modified_time":"2010-12-31T16:26:27+00:00","og_image":[{"url":"https:\/\/blog.fh-kaernten.at\/wehr\/files\/2010\/12\/last_loggin2.jpg","type":"","width":"","height":""}],"author":"Mario Wehr","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Mario Wehr","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blog.fh-kaernten.at\/wehr\/2010\/12\/31\/last-login-patch-for-trac-usermanager-plugin\/#article","isPartOf":{"@id":"https:\/\/blog.fh-kaernten.at\/wehr\/2010\/12\/31\/last-login-patch-for-trac-usermanager-plugin\/"},"author":{"name":"Mario Wehr","@id":"https:\/\/blog.fh-kaernten.at\/wehr\/#\/schema\/person\/8761b4d788b13b547de9ccd6504ce62d"},"headline":"Last login patch for Trac UserManager plugin","datePublished":"2010-12-31T16:07:40+00:00","dateModified":"2010-12-31T16:26:27+00:00","mainEntityOfPage":{"@id":"https:\/\/blog.fh-kaernten.at\/wehr\/2010\/12\/31\/last-login-patch-for-trac-usermanager-plugin\/"},"wordCount":47,"commentCount":0,"image":{"@id":"https:\/\/blog.fh-kaernten.at\/wehr\/2010\/12\/31\/last-login-patch-for-trac-usermanager-plugin\/#primaryimage"},"thumbnailUrl":"https:\/\/blog.fh-kaernten.at\/wehr\/files\/2010\/12\/last_loggin2.jpg","keywords":["trac"],"articleSection":["Cool Stuff"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/blog.fh-kaernten.at\/wehr\/2010\/12\/31\/last-login-patch-for-trac-usermanager-plugin\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/blog.fh-kaernten.at\/wehr\/2010\/12\/31\/last-login-patch-for-trac-usermanager-plugin\/","url":"https:\/\/blog.fh-kaernten.at\/wehr\/2010\/12\/31\/last-login-patch-for-trac-usermanager-plugin\/","name":"Last login patch for Trac UserManager plugin - Mario&#039;s TinyLab","isPartOf":{"@id":"https:\/\/blog.fh-kaernten.at\/wehr\/#website"},"primaryImageOfPage":{"@id":"https:\/\/blog.fh-kaernten.at\/wehr\/2010\/12\/31\/last-login-patch-for-trac-usermanager-plugin\/#primaryimage"},"image":{"@id":"https:\/\/blog.fh-kaernten.at\/wehr\/2010\/12\/31\/last-login-patch-for-trac-usermanager-plugin\/#primaryimage"},"thumbnailUrl":"https:\/\/blog.fh-kaernten.at\/wehr\/files\/2010\/12\/last_loggin2.jpg","datePublished":"2010-12-31T16:07:40+00:00","dateModified":"2010-12-31T16:26:27+00:00","author":{"@id":"https:\/\/blog.fh-kaernten.at\/wehr\/#\/schema\/person\/8761b4d788b13b547de9ccd6504ce62d"},"breadcrumb":{"@id":"https:\/\/blog.fh-kaernten.at\/wehr\/2010\/12\/31\/last-login-patch-for-trac-usermanager-plugin\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.fh-kaernten.at\/wehr\/2010\/12\/31\/last-login-patch-for-trac-usermanager-plugin\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blog.fh-kaernten.at\/wehr\/2010\/12\/31\/last-login-patch-for-trac-usermanager-plugin\/#primaryimage","url":"https:\/\/blog.fh-kaernten.at\/wehr\/files\/2010\/12\/last_loggin2.jpg","contentUrl":"https:\/\/blog.fh-kaernten.at\/wehr\/files\/2010\/12\/last_loggin2.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/blog.fh-kaernten.at\/wehr\/2010\/12\/31\/last-login-patch-for-trac-usermanager-plugin\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blog.fh-kaernten.at\/wehr\/"},{"@type":"ListItem","position":2,"name":"Last login patch for Trac UserManager plugin"}]},{"@type":"WebSite","@id":"https:\/\/blog.fh-kaernten.at\/wehr\/#website","url":"https:\/\/blog.fh-kaernten.at\/wehr\/","name":"Mario&#039;s TinyLab","description":"About cool\/interesting Projects and Technologies","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog.fh-kaernten.at\/wehr\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blog.fh-kaernten.at\/wehr\/#\/schema\/person\/8761b4d788b13b547de9ccd6504ce62d","name":"Mario Wehr","url":"https:\/\/blog.fh-kaernten.at\/wehr\/author\/wehr\/"}]}},"_links":{"self":[{"href":"https:\/\/blog.fh-kaernten.at\/wehr\/wp-json\/wp\/v2\/posts\/1200","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.fh-kaernten.at\/wehr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.fh-kaernten.at\/wehr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.fh-kaernten.at\/wehr\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.fh-kaernten.at\/wehr\/wp-json\/wp\/v2\/comments?post=1200"}],"version-history":[{"count":0,"href":"https:\/\/blog.fh-kaernten.at\/wehr\/wp-json\/wp\/v2\/posts\/1200\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.fh-kaernten.at\/wehr\/wp-json\/wp\/v2\/media?parent=1200"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.fh-kaernten.at\/wehr\/wp-json\/wp\/v2\/categories?post=1200"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.fh-kaernten.at\/wehr\/wp-json\/wp\/v2\/tags?post=1200"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}