{"action":"created","comment":{"url":"https://api.github.com/repos/OCA/server-tools/pulls/comments/35955570","id":35955570,"diff_hunk":"@@ -0,0 +1,60 @@\n+# -*- encoding: utf-8 -*-\n+from openerp import api, fields, models\n+from openerp.tools import (DEFAULT_SERVER_DATE_FORMAT,\n+                           DEFAULT_SERVER_TIME_FORMAT)\n+\n+# Available modes for :param:`.ResLang.datetime_formatter.template`\n+MODE_DATETIME = \"MODE_DATETIME\"\n+MODE_DATE = \"MODE_DATE\"\n+MODE_TIME = \"MODE_TIME\"\n+\n+\n+class ResLang(models.Model):\n+    _inherit = \"res.lang\"\n+\n+    @api.model\n+    def datetime_formatter(self, value, lang=None, template=MODE_DATETIME,\n+                           separator=\" \"):\n+        \"\"\"Convert a datetime field to lang's default format.\n+\n+        :type value: `str` or `datetime.datetime`\n+        :param value:\n+            Datetime that will be formatted to the user's preferred format.\n+\n+        :param str lang:\n+            Language code, formatted like \"en_US\". If not set, the program will\n+            try to guess the best match.\n+\n+        :param str template:\n+            Will be used to format :param:`value`. If it is one of the special\n+            constants :const:`MODE_DATETIME`, :const:`MODE_DATE` or\n+            :const:`MODE_TIME`, it will use the :param:`lang`'s default\n+            template for that mode.\n+\n+        :param str separator:\n+            Only used when :param:`template` is :const:`MODE_DATETIME`, as the\n+            separator between the date and time parts.\n+        \"\"\"\n+        # Get the correct lang\n+        if not lang:\n+            lang = (self.env.context.get(\"lang\") or\n+                    self.env.user.lang or\n+                    self.search([(\"active\", \"=\", True)], limit=1).code)","path":"datetime_formatter/models.py","position":42,"original_position":42,"commit_id":"91e18780bb842731f8917d7dd3db259aeaa713bb","original_commit_id":"91e18780bb842731f8917d7dd3db259aeaa713bb","user":{"login":"hbrunn","id":2563186,"avatar_url":"https://avatars.githubusercontent.com/u/2563186?v=3","gravatar_id":"","url":"https://api.github.com/users/hbrunn","html_url":"https://github.com/hbrunn","followers_url":"https://api.github.com/users/hbrunn/followers","following_url":"https://api.github.com/users/hbrunn/following{/other_user}","gists_url":"https://api.github.com/users/hbrunn/gists{/gist_id}","starred_url":"https://api.github.com/users/hbrunn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hbrunn/subscriptions","organizations_url":"https://api.github.com/users/hbrunn/orgs","repos_url":"https://api.github.com/users/hbrunn/repos","events_url":"https://api.github.com/users/hbrunn/events{/privacy}","received_events_url":"https://api.github.com/users/hbrunn/received_events","type":"User","site_admin":false},"body":"you might want to check before if self.ids is truthy, then you were called on a browse record, and in this case, simply use self[:1][0]. This way, we can say things like `my_object.lang.datetime_formatter(mydate)` and get it in the object's languge","created_at":"2015-07-31T08:35:25Z","updated_at":"2015-07-31T08:35:25Z","html_url":"https://github.com/OCA/server-tools/pull/214#discussion_r35955570","pull_request_url":"https://api.github.com/repos/OCA/server-tools/pulls/214","_links":{"self":{"href":"https://api.github.com/repos/OCA/server-tools/pulls/comments/35955570"},"html":{"href":"https://github.com/OCA/server-tools/pull/214#discussion_r35955570"},"pull_request":{"href":"https://api.github.com/repos/OCA/server-tools/pulls/214"}}},"pull_request":{"url":"https://api.github.com/repos/OCA/server-tools/pulls/214","id":40555668,"html_url":"https://github.com/OCA/server-tools/pull/214","diff_url":"https://github.com/OCA/server-tools/pull/214.diff","patch_url":"https://github.com/OCA/server-tools/pull/214.patch","issue_url":"https://api.github.com/repos/OCA/server-tools/issues/214","number":214,"state":"open","locked":false,"title":"Add module datetime_formatter.","user":{"login":"Yajo","id":973709,"avatar_url":"https://avatars.githubusercontent.com/u/973709?v=3","gravatar_id":"","url":"https://api.github.com/users/Yajo","html_url":"https://github.com/Yajo","followers_url":"https://api.github.com/users/Yajo/followers","following_url":"https://api.github.com/users/Yajo/following{/other_user}","gists_url":"https://api.github.com/users/Yajo/gists{/gist_id}","starred_url":"https://api.github.com/users/Yajo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yajo/subscriptions","organizations_url":"https://api.github.com/users/Yajo/orgs","repos_url":"https://api.github.com/users/Yajo/repos","events_url":"https://api.github.com/users/Yajo/events{/privacy}","received_events_url":"https://api.github.com/users/Yajo/received_events","type":"User","site_admin":false},"body":"This module allows the developer to format any date/time combination in the most comfortable way for the user, just with a quick call to :meth:`~.datetime_formatter` under any context.","created_at":"2015-07-22T11:38:49Z","updated_at":"2015-07-31T08:35:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3687d9f4d2ad3f5c526ff731c644de38ab288faf","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/OCA/server-tools/pulls/214/commits","review_comments_url":"https://api.github.com/repos/OCA/server-tools/pulls/214/comments","review_comment_url":"https://api.github.com/repos/OCA/server-tools/pulls/comments{/number}","comments_url":"https://api.github.com/repos/OCA/server-tools/issues/214/comments","statuses_url":"https://api.github.com/repos/OCA/server-tools/statuses/91e18780bb842731f8917d7dd3db259aeaa713bb","head":{"label":"grupoesoc:datetime-format-helper","ref":"datetime-format-helper","sha":"91e18780bb842731f8917d7dd3db259aeaa713bb","user":{"login":"grupoesoc","id":8087470,"avatar_url":"https://avatars.githubusercontent.com/u/8087470?v=3","gravatar_id":"","url":"https://api.github.com/users/grupoesoc","html_url":"https://github.com/grupoesoc","followers_url":"https://api.github.com/users/grupoesoc/followers","following_url":"https://api.github.com/users/grupoesoc/following{/other_user}","gists_url":"https://api.github.com/users/grupoesoc/gists{/gist_id}","starred_url":"https://api.github.com/users/grupoesoc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grupoesoc/subscriptions","organizations_url":"https://api.github.com/users/grupoesoc/orgs","repos_url":"https://api.github.com/users/grupoesoc/repos","events_url":"https://api.github.com/users/grupoesoc/events{/privacy}","received_events_url":"https://api.github.com/users/grupoesoc/received_events","type":"Organization","site_admin":false},"repo":{"id":24185646,"name":"server-tools","full_name":"grupoesoc/server-tools","owner":{"login":"grupoesoc","id":8087470,"avatar_url":"https://avatars.githubusercontent.com/u/8087470?v=3","gravatar_id":"","url":"https://api.github.com/users/grupoesoc","html_url":"https://github.com/grupoesoc","followers_url":"https://api.github.com/users/grupoesoc/followers","following_url":"https://api.github.com/users/grupoesoc/following{/other_user}","gists_url":"https://api.github.com/users/grupoesoc/gists{/gist_id}","starred_url":"https://api.github.com/users/grupoesoc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grupoesoc/subscriptions","organizations_url":"https://api.github.com/users/grupoesoc/orgs","repos_url":"https://api.github.com/users/grupoesoc/repos","events_url":"https://api.github.com/users/grupoesoc/events{/privacy}","received_events_url":"https://api.github.com/users/grupoesoc/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/grupoesoc/server-tools","description":"","fork":true,"url":"https://api.github.com/repos/grupoesoc/server-tools","forks_url":"https://api.github.com/repos/grupoesoc/server-tools/forks","keys_url":"https://api.github.com/repos/grupoesoc/server-tools/keys{/key_id}","collaborators_url":"https://api.github.com/repos/grupoesoc/server-tools/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/grupoesoc/server-tools/teams","hooks_url":"https://api.github.com/repos/grupoesoc/server-tools/hooks","issue_events_url":"https://api.github.com/repos/grupoesoc/server-tools/issues/events{/number}","events_url":"https://api.github.com/repos/grupoesoc/server-tools/events","assignees_url":"https://api.github.com/repos/grupoesoc/server-tools/assignees{/user}","branches_url":"https://api.github.com/repos/grupoesoc/server-tools/branches{/branch}","tags_url":"https://api.github.com/repos/grupoesoc/server-tools/tags","blobs_url":"https://api.github.com/repos/grupoesoc/server-tools/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/grupoesoc/server-tools/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/grupoesoc/server-tools/git/refs{/sha}","trees_url":"https://api.github.com/repos/grupoesoc/server-tools/git/trees{/sha}","statuses_url":"https://api.github.com/repos/grupoesoc/server-tools/statuses/{sha}","languages_url":"https://api.github.com/repos/grupoesoc/server-tools/languages","stargazers_url":"https://api.github.com/repos/grupoesoc/server-tools/stargazers","contributors_url":"https://api.github.com/repos/grupoesoc/server-tools/contributors","subscribers_url":"https://api.github.com/repos/grupoesoc/server-tools/subscribers","subscription_url":"https://api.github.com/repos/grupoesoc/server-tools/subscription","commits_url":"https://api.github.com/repos/grupoesoc/server-tools/commits{/sha}","git_commits_url":"https://api.github.com/repos/grupoesoc/server-tools/git/commits{/sha}","comments_url":"https://api.github.com/repos/grupoesoc/server-tools/comments{/number}","issue_comment_url":"https://api.github.com/repos/grupoesoc/server-tools/issues/comments{/number}","contents_url":"https://api.github.com/repos/grupoesoc/server-tools/contents/{+path}","compare_url":"https://api.github.com/repos/grupoesoc/server-tools/compare/{base}...{head}","merges_url":"https://api.github.com/repos/grupoesoc/server-tools/merges","archive_url":"https://api.github.com/repos/grupoesoc/server-tools/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/grupoesoc/server-tools/downloads","issues_url":"https://api.github.com/repos/grupoesoc/server-tools/issues{/number}","pulls_url":"https://api.github.com/repos/grupoesoc/server-tools/pulls{/number}","milestones_url":"https://api.github.com/repos/grupoesoc/server-tools/milestones{/number}","notifications_url":"https://api.github.com/repos/grupoesoc/server-tools/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/grupoesoc/server-tools/labels{/name}","releases_url":"https://api.github.com/repos/grupoesoc/server-tools/releases{/id}","created_at":"2014-09-18T11:32:58Z","updated_at":"2015-01-30T12:44:55Z","pushed_at":"2015-07-30T11:15:14Z","git_url":"git://github.com/grupoesoc/server-tools.git","ssh_url":"git@github.com:grupoesoc/server-tools.git","clone_url":"https://github.com/grupoesoc/server-tools.git","svn_url":"https://github.com/grupoesoc/server-tools","homepage":null,"size":1562,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"8.0"}},"base":{"label":"OCA:8.0","ref":"8.0","sha":"ef3813e5f5edeb68a7d32731d13afd97cb0272c4","user":{"login":"OCA","id":7600578,"avatar_url":"https://avatars.githubusercontent.com/u/7600578?v=3","gravatar_id":"","url":"https://api.github.com/users/OCA","html_url":"https://github.com/OCA","followers_url":"https://api.github.com/users/OCA/followers","following_url":"https://api.github.com/users/OCA/following{/other_user}","gists_url":"https://api.github.com/users/OCA/gists{/gist_id}","starred_url":"https://api.github.com/users/OCA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OCA/subscriptions","organizations_url":"https://api.github.com/users/OCA/orgs","repos_url":"https://api.github.com/users/OCA/repos","events_url":"https://api.github.com/users/OCA/events{/privacy}","received_events_url":"https://api.github.com/users/OCA/received_events","type":"Organization","site_admin":false},"repo":{"id":20896532,"name":"server-tools","full_name":"OCA/server-tools","owner":{"login":"OCA","id":7600578,"avatar_url":"https://avatars.githubusercontent.com/u/7600578?v=3","gravatar_id":"","url":"https://api.github.com/users/OCA","html_url":"https://github.com/OCA","followers_url":"https://api.github.com/users/OCA/followers","following_url":"https://api.github.com/users/OCA/following{/other_user}","gists_url":"https://api.github.com/users/OCA/gists{/gist_id}","starred_url":"https://api.github.com/users/OCA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OCA/subscriptions","organizations_url":"https://api.github.com/users/OCA/orgs","repos_url":"https://api.github.com/users/OCA/repos","events_url":"https://api.github.com/users/OCA/events{/privacy}","received_events_url":"https://api.github.com/users/OCA/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/OCA/server-tools","description":"Tools for Odoo Administrators to improve some technical features on Odoo.","fork":false,"url":"https://api.github.com/repos/OCA/server-tools","forks_url":"https://api.github.com/repos/OCA/server-tools/forks","keys_url":"https://api.github.com/repos/OCA/server-tools/keys{/key_id}","collaborators_url":"https://api.github.com/repos/OCA/server-tools/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/OCA/server-tools/teams","hooks_url":"https://api.github.com/repos/OCA/server-tools/hooks","issue_events_url":"https://api.github.com/repos/OCA/server-tools/issues/events{/number}","events_url":"https://api.github.com/repos/OCA/server-tools/events","assignees_url":"https://api.github.com/repos/OCA/server-tools/assignees{/user}","branches_url":"https://api.github.com/repos/OCA/server-tools/branches{/branch}","tags_url":"https://api.github.com/repos/OCA/server-tools/tags","blobs_url":"https://api.github.com/repos/OCA/server-tools/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/OCA/server-tools/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/OCA/server-tools/git/refs{/sha}","trees_url":"https://api.github.com/repos/OCA/server-tools/git/trees{/sha}","statuses_url":"https://api.github.com/repos/OCA/server-tools/statuses/{sha}","languages_url":"https://api.github.com/repos/OCA/server-tools/languages","stargazers_url":"https://api.github.com/repos/OCA/server-tools/stargazers","contributors_url":"https://api.github.com/repos/OCA/server-tools/contributors","subscribers_url":"https://api.github.com/repos/OCA/server-tools/subscribers","subscription_url":"https://api.github.com/repos/OCA/server-tools/subscription","commits_url":"https://api.github.com/repos/OCA/server-tools/commits{/sha}","git_commits_url":"https://api.github.com/repos/OCA/server-tools/git/commits{/sha}","comments_url":"https://api.github.com/repos/OCA/server-tools/comments{/number}","issue_comment_url":"https://api.github.com/repos/OCA/server-tools/issues/comments{/number}","contents_url":"https://api.github.com/repos/OCA/server-tools/contents/{+path}","compare_url":"https://api.github.com/repos/OCA/server-tools/compare/{base}...{head}","merges_url":"https://api.github.com/repos/OCA/server-tools/merges","archive_url":"https://api.github.com/repos/OCA/server-tools/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/OCA/server-tools/downloads","issues_url":"https://api.github.com/repos/OCA/server-tools/issues{/number}","pulls_url":"https://api.github.com/repos/OCA/server-tools/pulls{/number}","milestones_url":"https://api.github.com/repos/OCA/server-tools/milestones{/number}","notifications_url":"https://api.github.com/repos/OCA/server-tools/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/OCA/server-tools/labels{/name}","releases_url":"https://api.github.com/repos/OCA/server-tools/releases{/id}","created_at":"2014-06-16T18:52:44Z","updated_at":"2015-07-22T10:44:09Z","pushed_at":"2015-07-30T11:15:15Z","git_url":"git://github.com/OCA/server-tools.git","ssh_url":"git@github.com:OCA/server-tools.git","clone_url":"https://github.com/OCA/server-tools.git","svn_url":"https://github.com/OCA/server-tools","homepage":"https://community.odoo.com/project/30","size":7864,"stargazers_count":58,"watchers_count":58,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":156,"mirror_url":null,"open_issues_count":71,"forks":156,"open_issues":71,"watchers":58,"default_branch":"8.0"}},"_links":{"self":{"href":"https://api.github.com/repos/OCA/server-tools/pulls/214"},"html":{"href":"https://github.com/OCA/server-tools/pull/214"},"issue":{"href":"https://api.github.com/repos/OCA/server-tools/issues/214"},"comments":{"href":"https://api.github.com/repos/OCA/server-tools/issues/214/comments"},"review_comments":{"href":"https://api.github.com/repos/OCA/server-tools/pulls/214/comments"},"review_comment":{"href":"https://api.github.com/repos/OCA/server-tools/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/OCA/server-tools/pulls/214/commits"},"statuses":{"href":"https://api.github.com/repos/OCA/server-tools/statuses/91e18780bb842731f8917d7dd3db259aeaa713bb"}}}}