{"action":"created","comment":{"url":"https://api.github.com/repos/allegro/ralph/pulls/comments/37706105","id":37706105,"diff_hunk":"@@ -0,0 +1,172 @@\n+# -*- coding: utf-8 -*-\n+import re\n+from datetime import datetime\n+from functools import lru_cache\n+\n+from django.contrib.admin import SimpleListFilter\n+from django.db.models import Q\n+from django.utils.encoding import smart_text\n+from django.utils.formats import get_format\n+from django.utils.translation import ugettext_lazy as _\n+\n+\n+@lru_cache()\n+def date_format_to_human(value):\n+    \"\"\"\n+    Convert Python format date to human.\n+\n+    Example:\n+        >>> date_format_to_human('%Y-%m-%d')\n+        YYYY-MM-DD\n+\n+    :param value: Date format example: %Y-%m\n+    \"\"\"\n+    maps = {\n+        '%y': 'YY',\n+        '%Y': 'YYYY',\n+        '%m': 'MM',\n+        '%d': 'DD',\n+    }\n+    for k, v in maps.items():\n+        value = value.replace(k, v)\n+    return value\n+\n+\n+class BaseCustomFilter(SimpleListFilter):\n+\n+    def has_output(self):\n+        return True\n+\n+    def lookups(self, request, model_admin):\n+        return None\n+\n+\n+class ChoicesFilter(BaseCustomFilter):\n+\n+    \"\"\"Renders filter form with choices field.\"\"\"\n+\n+    template = 'admin/filters/choices_filter.html'\n+    choices_list = []\n+\n+    def choices(self, cl):\n+        yield {\n+            'selected': False,\n+            'value': '',\n+            'display': _('All'),\n+            'parameter_name': self.parameter_name\n+        }\n+        for lookup, title in self.choices_list:\n+            yield {\n+                'selected': smart_text(lookup) == self.value(),\n+                'value': lookup,\n+                'display': title,\n+            }\n+\n+    def queryset(self, request, queryset):\n+        if self.value():\n+            return queryset.filter(**{self.parameter_name: self.value()})\n+\n+\n+class BooleanFilter(ChoicesFilter):\n+\n+    \"\"\"Renders filter form with boolean field.\"\"\"\n+\n+    choices_list = [\n+        ('', _('All')),\n+        ('1', _('Yes')),\n+        ('0', _('No')),\n+    ]\n+\n+    def choices(self, cl):","path":"src/ralph/admin/filters.py","position":80,"original_position":80,"commit_id":"0052f59a36bea8c449f79e465c95cf6fe643c3f8","original_commit_id":"0052f59a36bea8c449f79e465c95cf6fe643c3f8","user":{"login":"szok","id":2209581,"avatar_url":"https://avatars.githubusercontent.com/u/2209581?v=3","gravatar_id":"","url":"https://api.github.com/users/szok","html_url":"https://github.com/szok","followers_url":"https://api.github.com/users/szok/followers","following_url":"https://api.github.com/users/szok/following{/other_user}","gists_url":"https://api.github.com/users/szok/gists{/gist_id}","starred_url":"https://api.github.com/users/szok/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/szok/subscriptions","organizations_url":"https://api.github.com/users/szok/orgs","repos_url":"https://api.github.com/users/szok/repos","events_url":"https://api.github.com/users/szok/events{/privacy}","received_events_url":"https://api.github.com/users/szok/received_events","type":"User","site_admin":false},"body":"is needed because BooleanFilter and ChoiceFilter returned are completely different values.","created_at":"2015-08-23T14:04:49Z","updated_at":"2015-08-23T14:04:49Z","html_url":"https://github.com/allegro/ralph/pull/1708#discussion_r37706105","pull_request_url":"https://api.github.com/repos/allegro/ralph/pulls/1708","_links":{"self":{"href":"https://api.github.com/repos/allegro/ralph/pulls/comments/37706105"},"html":{"href":"https://github.com/allegro/ralph/pull/1708#discussion_r37706105"},"pull_request":{"href":"https://api.github.com/repos/allegro/ralph/pulls/1708"}}},"pull_request":{"url":"https://api.github.com/repos/allegro/ralph/pulls/1708","id":42318510,"html_url":"https://github.com/allegro/ralph/pull/1708","diff_url":"https://github.com/allegro/ralph/pull/1708.diff","patch_url":"https://github.com/allegro/ralph/pull/1708.patch","issue_url":"https://api.github.com/repos/allegro/ralph/issues/1708","number":1708,"state":"open","locked":false,"title":"Advanced search","user":{"login":"szok","id":2209581,"avatar_url":"https://avatars.githubusercontent.com/u/2209581?v=3","gravatar_id":"","url":"https://api.github.com/users/szok","html_url":"https://github.com/szok","followers_url":"https://api.github.com/users/szok/followers","following_url":"https://api.github.com/users/szok/following{/other_user}","gists_url":"https://api.github.com/users/szok/gists{/gist_id}","starred_url":"https://api.github.com/users/szok/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/szok/subscriptions","organizations_url":"https://api.github.com/users/szok/orgs","repos_url":"https://api.github.com/users/szok/repos","events_url":"https://api.github.com/users/szok/events{/privacy}","received_events_url":"https://api.github.com/users/szok/received_events","type":"User","site_admin":false},"body":"Added search filter to:\r\n- Data Center Asset\r\n- Back Office Asset\r\n\r\nConnected to #1695 ","created_at":"2015-08-13T06:24:51Z","updated_at":"2015-08-23T14:04:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"19e549f1ddcf039a63a63e28b79903ce2cdb2315","assignee":null,"milestone":{"url":"https://api.github.com/repos/allegro/ralph/milestones/17","html_url":"https://github.com/allegro/ralph/milestones/7.%20Search","labels_url":"https://api.github.com/repos/allegro/ralph/milestones/17/labels","id":1234762,"number":17,"title":"7. Search","description":"","creator":{"login":"xliiv","id":298994,"avatar_url":"https://avatars.githubusercontent.com/u/298994?v=3","gravatar_id":"","url":"https://api.github.com/users/xliiv","html_url":"https://github.com/xliiv","followers_url":"https://api.github.com/users/xliiv/followers","following_url":"https://api.github.com/users/xliiv/following{/other_user}","gists_url":"https://api.github.com/users/xliiv/gists{/gist_id}","starred_url":"https://api.github.com/users/xliiv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xliiv/subscriptions","organizations_url":"https://api.github.com/users/xliiv/orgs","repos_url":"https://api.github.com/users/xliiv/repos","events_url":"https://api.github.com/users/xliiv/events{/privacy}","received_events_url":"https://api.github.com/users/xliiv/received_events","type":"User","site_admin":false},"open_issues":15,"closed_issues":11,"state":"open","created_at":"2015-07-31T08:41:21Z","updated_at":"2015-08-21T16:00:37Z","due_on":"2015-08-23T22:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/allegro/ralph/pulls/1708/commits","review_comments_url":"https://api.github.com/repos/allegro/ralph/pulls/1708/comments","review_comment_url":"https://api.github.com/repos/allegro/ralph/pulls/comments{/number}","comments_url":"https://api.github.com/repos/allegro/ralph/issues/1708/comments","statuses_url":"https://api.github.com/repos/allegro/ralph/statuses/0052f59a36bea8c449f79e465c95cf6fe643c3f8","head":{"label":"szok:ng-filters","ref":"ng-filters","sha":"0052f59a36bea8c449f79e465c95cf6fe643c3f8","user":{"login":"szok","id":2209581,"avatar_url":"https://avatars.githubusercontent.com/u/2209581?v=3","gravatar_id":"","url":"https://api.github.com/users/szok","html_url":"https://github.com/szok","followers_url":"https://api.github.com/users/szok/followers","following_url":"https://api.github.com/users/szok/following{/other_user}","gists_url":"https://api.github.com/users/szok/gists{/gist_id}","starred_url":"https://api.github.com/users/szok/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/szok/subscriptions","organizations_url":"https://api.github.com/users/szok/orgs","repos_url":"https://api.github.com/users/szok/repos","events_url":"https://api.github.com/users/szok/events{/privacy}","received_events_url":"https://api.github.com/users/szok/received_events","type":"User","site_admin":false},"repo":{"id":32583868,"name":"ralph","full_name":"szok/ralph","owner":{"login":"szok","id":2209581,"avatar_url":"https://avatars.githubusercontent.com/u/2209581?v=3","gravatar_id":"","url":"https://api.github.com/users/szok","html_url":"https://github.com/szok","followers_url":"https://api.github.com/users/szok/followers","following_url":"https://api.github.com/users/szok/following{/other_user}","gists_url":"https://api.github.com/users/szok/gists{/gist_id}","starred_url":"https://api.github.com/users/szok/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/szok/subscriptions","organizations_url":"https://api.github.com/users/szok/orgs","repos_url":"https://api.github.com/users/szok/repos","events_url":"https://api.github.com/users/szok/events{/privacy}","received_events_url":"https://api.github.com/users/szok/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/szok/ralph","description":"Ralph is an asset management system for your data center.","fork":true,"url":"https://api.github.com/repos/szok/ralph","forks_url":"https://api.github.com/repos/szok/ralph/forks","keys_url":"https://api.github.com/repos/szok/ralph/keys{/key_id}","collaborators_url":"https://api.github.com/repos/szok/ralph/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/szok/ralph/teams","hooks_url":"https://api.github.com/repos/szok/ralph/hooks","issue_events_url":"https://api.github.com/repos/szok/ralph/issues/events{/number}","events_url":"https://api.github.com/repos/szok/ralph/events","assignees_url":"https://api.github.com/repos/szok/ralph/assignees{/user}","branches_url":"https://api.github.com/repos/szok/ralph/branches{/branch}","tags_url":"https://api.github.com/repos/szok/ralph/tags","blobs_url":"https://api.github.com/repos/szok/ralph/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/szok/ralph/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/szok/ralph/git/refs{/sha}","trees_url":"https://api.github.com/repos/szok/ralph/git/trees{/sha}","statuses_url":"https://api.github.com/repos/szok/ralph/statuses/{sha}","languages_url":"https://api.github.com/repos/szok/ralph/languages","stargazers_url":"https://api.github.com/repos/szok/ralph/stargazers","contributors_url":"https://api.github.com/repos/szok/ralph/contributors","subscribers_url":"https://api.github.com/repos/szok/ralph/subscribers","subscription_url":"https://api.github.com/repos/szok/ralph/subscription","commits_url":"https://api.github.com/repos/szok/ralph/commits{/sha}","git_commits_url":"https://api.github.com/repos/szok/ralph/git/commits{/sha}","comments_url":"https://api.github.com/repos/szok/ralph/comments{/number}","issue_comment_url":"https://api.github.com/repos/szok/ralph/issues/comments{/number}","contents_url":"https://api.github.com/repos/szok/ralph/contents/{+path}","compare_url":"https://api.github.com/repos/szok/ralph/compare/{base}...{head}","merges_url":"https://api.github.com/repos/szok/ralph/merges","archive_url":"https://api.github.com/repos/szok/ralph/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/szok/ralph/downloads","issues_url":"https://api.github.com/repos/szok/ralph/issues{/number}","pulls_url":"https://api.github.com/repos/szok/ralph/pulls{/number}","milestones_url":"https://api.github.com/repos/szok/ralph/milestones{/number}","notifications_url":"https://api.github.com/repos/szok/ralph/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/szok/ralph/labels{/name}","releases_url":"https://api.github.com/repos/szok/ralph/releases{/id}","created_at":"2015-03-20T13:01:10Z","updated_at":"2015-04-15T13:29:16Z","pushed_at":"2015-08-21T12:12:11Z","git_url":"git://github.com/szok/ralph.git","ssh_url":"git@github.com:szok/ralph.git","clone_url":"https://github.com/szok/ralph.git","svn_url":"https://github.com/szok/ralph","homepage":"http://ralph.allegrogroup.com/","size":20768,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"develop"}},"base":{"label":"allegro:ng","ref":"ng","sha":"7367135fab7ab8d1434f905230d5fcabdf2315f1","user":{"login":"allegro","id":562236,"avatar_url":"https://avatars.githubusercontent.com/u/562236?v=3","gravatar_id":"","url":"https://api.github.com/users/allegro","html_url":"https://github.com/allegro","followers_url":"https://api.github.com/users/allegro/followers","following_url":"https://api.github.com/users/allegro/following{/other_user}","gists_url":"https://api.github.com/users/allegro/gists{/gist_id}","starred_url":"https://api.github.com/users/allegro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/allegro/subscriptions","organizations_url":"https://api.github.com/users/allegro/orgs","repos_url":"https://api.github.com/users/allegro/repos","events_url":"https://api.github.com/users/allegro/events{/privacy}","received_events_url":"https://api.github.com/users/allegro/received_events","type":"Organization","site_admin":false},"repo":{"id":4359038,"name":"ralph","full_name":"allegro/ralph","owner":{"login":"allegro","id":562236,"avatar_url":"https://avatars.githubusercontent.com/u/562236?v=3","gravatar_id":"","url":"https://api.github.com/users/allegro","html_url":"https://github.com/allegro","followers_url":"https://api.github.com/users/allegro/followers","following_url":"https://api.github.com/users/allegro/following{/other_user}","gists_url":"https://api.github.com/users/allegro/gists{/gist_id}","starred_url":"https://api.github.com/users/allegro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/allegro/subscriptions","organizations_url":"https://api.github.com/users/allegro/orgs","repos_url":"https://api.github.com/users/allegro/repos","events_url":"https://api.github.com/users/allegro/events{/privacy}","received_events_url":"https://api.github.com/users/allegro/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/allegro/ralph","description":"Ralph is an asset management system for your data center.","fork":false,"url":"https://api.github.com/repos/allegro/ralph","forks_url":"https://api.github.com/repos/allegro/ralph/forks","keys_url":"https://api.github.com/repos/allegro/ralph/keys{/key_id}","collaborators_url":"https://api.github.com/repos/allegro/ralph/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/allegro/ralph/teams","hooks_url":"https://api.github.com/repos/allegro/ralph/hooks","issue_events_url":"https://api.github.com/repos/allegro/ralph/issues/events{/number}","events_url":"https://api.github.com/repos/allegro/ralph/events","assignees_url":"https://api.github.com/repos/allegro/ralph/assignees{/user}","branches_url":"https://api.github.com/repos/allegro/ralph/branches{/branch}","tags_url":"https://api.github.com/repos/allegro/ralph/tags","blobs_url":"https://api.github.com/repos/allegro/ralph/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/allegro/ralph/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/allegro/ralph/git/refs{/sha}","trees_url":"https://api.github.com/repos/allegro/ralph/git/trees{/sha}","statuses_url":"https://api.github.com/repos/allegro/ralph/statuses/{sha}","languages_url":"https://api.github.com/repos/allegro/ralph/languages","stargazers_url":"https://api.github.com/repos/allegro/ralph/stargazers","contributors_url":"https://api.github.com/repos/allegro/ralph/contributors","subscribers_url":"https://api.github.com/repos/allegro/ralph/subscribers","subscription_url":"https://api.github.com/repos/allegro/ralph/subscription","commits_url":"https://api.github.com/repos/allegro/ralph/commits{/sha}","git_commits_url":"https://api.github.com/repos/allegro/ralph/git/commits{/sha}","comments_url":"https://api.github.com/repos/allegro/ralph/comments{/number}","issue_comment_url":"https://api.github.com/repos/allegro/ralph/issues/comments{/number}","contents_url":"https://api.github.com/repos/allegro/ralph/contents/{+path}","compare_url":"https://api.github.com/repos/allegro/ralph/compare/{base}...{head}","merges_url":"https://api.github.com/repos/allegro/ralph/merges","archive_url":"https://api.github.com/repos/allegro/ralph/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/allegro/ralph/downloads","issues_url":"https://api.github.com/repos/allegro/ralph/issues{/number}","pulls_url":"https://api.github.com/repos/allegro/ralph/pulls{/number}","milestones_url":"https://api.github.com/repos/allegro/ralph/milestones{/number}","notifications_url":"https://api.github.com/repos/allegro/ralph/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/allegro/ralph/labels{/name}","releases_url":"https://api.github.com/repos/allegro/ralph/releases{/id}","created_at":"2012-05-17T14:04:57Z","updated_at":"2015-08-21T10:14:31Z","pushed_at":"2015-08-22T10:04:53Z","git_url":"git://github.com/allegro/ralph.git","ssh_url":"git@github.com:allegro/ralph.git","clone_url":"https://github.com/allegro/ralph.git","svn_url":"https://github.com/allegro/ralph","homepage":"http://allegro.tech/ralph/","size":28446,"stargazers_count":304,"watchers_count":304,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":75,"mirror_url":null,"open_issues_count":84,"forks":75,"open_issues":84,"watchers":304,"default_branch":"ng"}},"_links":{"self":{"href":"https://api.github.com/repos/allegro/ralph/pulls/1708"},"html":{"href":"https://github.com/allegro/ralph/pull/1708"},"issue":{"href":"https://api.github.com/repos/allegro/ralph/issues/1708"},"comments":{"href":"https://api.github.com/repos/allegro/ralph/issues/1708/comments"},"review_comments":{"href":"https://api.github.com/repos/allegro/ralph/pulls/1708/comments"},"review_comment":{"href":"https://api.github.com/repos/allegro/ralph/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/allegro/ralph/pulls/1708/commits"},"statuses":{"href":"https://api.github.com/repos/allegro/ralph/statuses/0052f59a36bea8c449f79e465c95cf6fe643c3f8"}}}}