Merge pull request #151 from gazpachoking/fix_search_hooks

Fix search hooks with WikiPage refactor
This commit is contained in:
Chase Sterling 2016-07-08 18:52:18 -04:00 committed by GitHub
commit 9d80adf65e
3 changed files with 19 additions and 14 deletions

View file

@ -7,7 +7,7 @@ def hook_func(name, fn):
@wraps(fn) @wraps(fn)
def wrapper(self, *args, **kwargs): def wrapper(self, *args, **kwargs):
for hook, a, kw in self.__class__._pre_hooks.get(name) or []: for hook, a, kw in self.__class__._pre_hooks.get(name) or []:
hook(*args, **kwargs) hook(self, *args, **kwargs)
rv = fn(self, *args, **kwargs) rv = fn(self, *args, **kwargs)
@ -15,7 +15,7 @@ def hook_func(name, fn):
kwargs.update(dict(rv=rv)) kwargs.update(dict(rv=rv))
for hook, a, kw in self.__class__._post_hooks.get(name) or []: for hook, a, kw in self.__class__._post_hooks.get(name) or []:
hook(*args, **kwargs) hook(self, *args, **kwargs)
return rv return rv
return wrapper return wrapper

View file

@ -1,35 +1,40 @@
from realms.modules.wiki.models import Wiki from realms.modules.wiki.models import WikiPage
from realms import search from realms import search
@Wiki.after('write_page') @WikiPage.after('write')
def wiki_write_page(name, content, message=None, username=None, email=None, **kwargs): def wiki_write_page(page, content, message=None, username=None, email=None, **kwargs):
if not hasattr(search, 'index_wiki'): if not hasattr(search, 'index_wiki'):
# using simple search or none # using simple search or none
return return
body = dict(name=name, body = dict(name=page.name,
content=content, content=content,
message=message, message=message,
email=email, email=email,
username=username) username=username)
return search.index_wiki(name, body) return search.index_wiki(page.name, body)
@Wiki.after('rename_page') @WikiPage.before('rename')
def wiki_rename_page(old_name, *args, **kwargs): def wiki_rename_page_del(page, *args, **kwargs):
if not hasattr(search, 'index_wiki'): if not hasattr(search, 'index_wiki'):
return return
return search.delete_wiki(old_name) return search.delete_wiki(page.name)
@Wiki.after('delete_page') @WikiPage.after('rename')
def wiki_delete_page(name, *args, **kwargs): def wiki_rename_page_add(page, new_name, *args, **kwargs):
wiki_write_page(page, page.data, *args, **kwargs)
@WikiPage.after('delete')
def wiki_delete_page(page, *args, **kwargs):
if not hasattr(search, 'index_wiki'): if not hasattr(search, 'index_wiki'):
return return
return search.delete_wiki(name) return search.delete_wiki(page.name)

View file

@ -69,7 +69,7 @@ class Wiki(HookMixin):
return rv return rv
class WikiPage(object): class WikiPage(HookMixin):
def __init__(self, name, wiki, sha='HEAD'): def __init__(self, name, wiki, sha='HEAD'):
self.name = name self.name = name
self.filename = cname_to_filename(name) self.filename = cname_to_filename(name)