def start(heap_id, url=None): """Modified the webserver to serve the given heap index page on the given URL. **Arguments:** - `heap_id` (|HeapId|) - `url` (str | ``None``) -- If ``None``, it will be ``"/" + heap_id``. """ if url is None: url = '/' + heap_id + '-issue-tracker' def make_CustomHeapServer(flat_issues): class CustomHeapServer(hkweb.HkPageServer): """Serves the index page that shows all posts.""" def __init__(self): hkweb.HkPageServer.__init__(self) def GET(self): generator = WebITGenerator(self._postdb, heap_id) generator.options.flat_issues = flat_issues content = generator.print_main() return self.serve_html(content, generator) return CustomHeapServer hkweb.insert_urls( [url, make_CustomHeapServer(flat_issues=True)]) hkweb.insert_urls( [url + '-threaded', make_CustomHeapServer(flat_issues=False)]) def issue_target(post, pattern): postdb = post._postdb root = postdb.root(post) gen = BaseITGenerator(postdb) if pattern == 'issue': return gen.is_thread_issue(root) elif pattern == 'open': return gen.is_thread_open(root) else: return False hksearch.add_target_type('issue', issue_target)
def start(heap_id, url=None): """Modified the webserver to serve the given heap index page on the given URL. **Arguments:** - `heap_id` (|HeapId|) - `url` (str | ``None``) -- If ``None``, it will be ``"/" + heap_id``. """ if url is None: url = '/' + heap_id class CustomHeapServer(hkweb.HkPageServer): """Serves the index page that shows all posts.""" def __init__(self): hkweb.HkPageServer.__init__(self) def GET(self): generator = CustomHeapGenerator(self._postdb, heap_id) content = generator.print_main() # Inserting "heap:<heap_id>" into the search bar fill_searchbar_js = \ ('$("#searchbar-term").val(' + json.dumps("heap:" + heap_id + " ") + ');\n') js_code = \ ('<script type="text/javascript" language="JavaScript">\n', fill_searchbar_js, '</script>\n') content = (content, js_code) return self.serve_html(content, generator) hkweb.insert_urls([url, CustomHeapServer])
def start(): """Starts the plugin.""" global postpage_old_init global index_old_init global postpage_old_print_additional_header global index_old_print_additional_header postpage_old_init = hkweb.PostPageGenerator.__init__ index_old_init = hkweb.IndexGenerator.__init__ postpage_old_print_additional_header = \ hkweb.PostPageGenerator.print_additional_header index_old_print_additional_header = \ hkweb.IndexGenerator.print_additional_header hkweb.IndexGenerator.__init__ = index_new_init hkweb.PostPageGenerator.__init__ = postpage_new_init hkweb.IndexGenerator.print_additional_header = \ index_print_additional_header hkweb.PostPageGenerator.print_additional_header = \ postpage_print_additional_header hkweb.insert_urls(('/chat-send', SendChatMessage)) hkweb.insert_urls(('/chat-poll/(.*)', PollChatMessage))
def start(review_command_name='r'): """Starts the plugin. **Argument:** - `review_command_name` (str) -- The name of the |hkshell| command that shall be defined. """ hkshell.register_cmd(review_command_name, set_to_reviewed) hkweb.insert_urls(['/set-post-reviewed', 'hkp_review.SetPostReviewed']) old_init = hkweb.PostPageGenerator.__init__ def __init__(self, postdb): # __init__ method from base class 'PostPageGenerator' is not called # pylint: disable=W0231 old_init(self, postdb) self.options.js_files.append('plugins/review/static/js/hkp_review.js') hkweb.PostPageGenerator.__init__ = __init__