{"action":"created","issue":{"url":"https://api.github.com/repos/django-helpdesk/django-helpdesk/issues/512","repository_url":"https://api.github.com/repos/django-helpdesk/django-helpdesk","labels_url":"https://api.github.com/repos/django-helpdesk/django-helpdesk/issues/512/labels{/name}","comments_url":"https://api.github.com/repos/django-helpdesk/django-helpdesk/issues/512/comments","events_url":"https://api.github.com/repos/django-helpdesk/django-helpdesk/issues/512/events","html_url":"https://github.com/django-helpdesk/django-helpdesk/issues/512","id":232459307,"number":512,"title":"Optimisation in num_to_link (eliminate ReverseProxy class)","user":{"login":"mrkiwi-nz","id":17169553,"avatar_url":"https://avatars0.githubusercontent.com/u/17169553?v=3","gravatar_id":"","url":"https://api.github.com/users/mrkiwi-nz","html_url":"https://github.com/mrkiwi-nz","followers_url":"https://api.github.com/users/mrkiwi-nz/followers","following_url":"https://api.github.com/users/mrkiwi-nz/following{/other_user}","gists_url":"https://api.github.com/users/mrkiwi-nz/gists{/gist_id}","starred_url":"https://api.github.com/users/mrkiwi-nz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrkiwi-nz/subscriptions","organizations_url":"https://api.github.com/users/mrkiwi-nz/orgs","repos_url":"https://api.github.com/users/mrkiwi-nz/repos","events_url":"https://api.github.com/users/mrkiwi-nz/events{/privacy}","received_events_url":"https://api.github.com/users/mrkiwi-nz/received_events","type":"User","site_admin":false},"labels":[{"id":95428,"url":"https://api.github.com/repos/django-helpdesk/django-helpdesk/labels/enhancement","name":"enhancement","color":"d7e102","default":true}],"state":"open","locked":false,"assignee":{"login":"gwasser","id":4760531,"avatar_url":"https://avatars0.githubusercontent.com/u/4760531?v=3","gravatar_id":"","url":"https://api.github.com/users/gwasser","html_url":"https://github.com/gwasser","followers_url":"https://api.github.com/users/gwasser/followers","following_url":"https://api.github.com/users/gwasser/following{/other_user}","gists_url":"https://api.github.com/users/gwasser/gists{/gist_id}","starred_url":"https://api.github.com/users/gwasser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gwasser/subscriptions","organizations_url":"https://api.github.com/users/gwasser/orgs","repos_url":"https://api.github.com/users/gwasser/repos","events_url":"https://api.github.com/users/gwasser/events{/privacy}","received_events_url":"https://api.github.com/users/gwasser/received_events","type":"User","site_admin":false},"assignees":[{"login":"gwasser","id":4760531,"avatar_url":"https://avatars0.githubusercontent.com/u/4760531?v=3","gravatar_id":"","url":"https://api.github.com/users/gwasser","html_url":"https://github.com/gwasser","followers_url":"https://api.github.com/users/gwasser/followers","following_url":"https://api.github.com/users/gwasser/following{/other_user}","gists_url":"https://api.github.com/users/gwasser/gists{/gist_id}","starred_url":"https://api.github.com/users/gwasser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gwasser/subscriptions","organizations_url":"https://api.github.com/users/gwasser/orgs","repos_url":"https://api.github.com/users/gwasser/repos","events_url":"https://api.github.com/users/gwasser/events{/privacy}","received_events_url":"https://api.github.com/users/gwasser/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/django-helpdesk/django-helpdesk/milestones/2","html_url":"https://github.com/django-helpdesk/django-helpdesk/milestone/2","labels_url":"https://api.github.com/repos/django-helpdesk/django-helpdesk/milestones/2/labels","id":2082081,"number":2,"title":"0.2","description":null,"creator":{"login":"flinz","id":97735,"avatar_url":"https://avatars3.githubusercontent.com/u/97735?v=3","gravatar_id":"","url":"https://api.github.com/users/flinz","html_url":"https://github.com/flinz","followers_url":"https://api.github.com/users/flinz/followers","following_url":"https://api.github.com/users/flinz/following{/other_user}","gists_url":"https://api.github.com/users/flinz/gists{/gist_id}","starred_url":"https://api.github.com/users/flinz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flinz/subscriptions","organizations_url":"https://api.github.com/users/flinz/orgs","repos_url":"https://api.github.com/users/flinz/repos","events_url":"https://api.github.com/users/flinz/events{/privacy}","received_events_url":"https://api.github.com/users/flinz/received_events","type":"User","site_admin":false},"open_issues":6,"closed_issues":4,"state":"open","created_at":"2016-10-20T10:35:38Z","updated_at":"2017-06-01T01:36:09Z","due_on":null,"closed_at":null},"comments":0,"created_at":"2017-05-31T05:42:59Z","updated_at":"2017-06-01T01:46:14Z","closed_at":null,"body":"What is the purpose of ReverseProxy in ticket_to_link.py?\r\n\r\n```\r\ndef num_to_link(text):\r\n    if text == '':\r\n        return text\r\n\r\n    matches = []\r\n    for match in re.finditer(r\"(?:[^&]|\\b|^)#(\\d+)\\b\", text):\r\n        matches.append(match)\r\n\r\n    for match in ReverseProxy(matches):\r\n        start = match.start()\r\n        end = match.end()\r\n        number = match.groups()[0]\r\n        url = reverse('helpdesk_view', args=[number])\r\n        try:\r\n            ticket = Ticket.objects.get(id=number)\r\n        except Ticket.DoesNotExist:\r\n            ticket = None\r\n\r\n        if ticket:\r\n            style = ticket.get_status_display()\r\n            text = \"%s <a href='%s' class='ticket_link_status ticket_link_status_%s'>#%s</a>%s\" % (text[:match.start()], url, style, match.groups()[0], text[match.end():])\r\n    return mark_safe(text)\r\n\r\nregister = template.Library()\r\nregister.filter(num_to_link)\r\n```\r\n\r\nWhat does ReverseProxy() do (see below) that reversed() would not do?\r\nWhy use a custom class over the builtin reversed?\r\n\r\n\r\n```\r\nclass ReverseProxy:\r\n    def __init__(self, sequence):\r\n        self.sequence = sequence\r\n\r\n    def __iter__(self):\r\n        length = len(self.sequence)\r\n        i = length\r\n        while i > 0:\r\n            i = i - 1\r\n            yield self.sequence[i]\r\n```"},"comment":{"url":"https://api.github.com/repos/django-helpdesk/django-helpdesk/issues/comments/305365795","html_url":"https://github.com/django-helpdesk/django-helpdesk/issues/512#issuecomment-305365795","issue_url":"https://api.github.com/repos/django-helpdesk/django-helpdesk/issues/512","id":305365795,"user":{"login":"gwasser","id":4760531,"avatar_url":"https://avatars0.githubusercontent.com/u/4760531?v=3","gravatar_id":"","url":"https://api.github.com/users/gwasser","html_url":"https://github.com/gwasser","followers_url":"https://api.github.com/users/gwasser/followers","following_url":"https://api.github.com/users/gwasser/following{/other_user}","gists_url":"https://api.github.com/users/gwasser/gists{/gist_id}","starred_url":"https://api.github.com/users/gwasser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gwasser/subscriptions","organizations_url":"https://api.github.com/users/gwasser/orgs","repos_url":"https://api.github.com/users/gwasser/repos","events_url":"https://api.github.com/users/gwasser/events{/privacy}","received_events_url":"https://api.github.com/users/gwasser/received_events","type":"User","site_admin":false},"created_at":"2017-06-01T01:46:14Z","updated_at":"2017-06-01T01:46:14Z","body":"Very good questions! It looks to me like it's going backwards through the list because of the way the loop is written; at each step, it's replacing the whole text string with the link, so if you iterate through the string from the beginning, you will replace any `#` with a link to a `#` which will then get matched again and you get stuck in an infinite loop. Am I reading that right? This is just my initial glance.\r\n\r\nI'm not sure how old the code base is, it's possible `ReverseProxy` was a workaround before `reversed` was added, or some type of bug. But I agree that we can probably ditch the custom class and rewrite the regex loop to maybe not even need reversing anymore. Let me play with some patches as I look at #511 and #513 too."}}
{"actor":{"display_login":"gwasser"}}