realms-wiki/realms/modules/search/hooks.py

43 lines
1 KiB
Python
Raw Normal View History

from __future__ import absolute_import
2016-08-20 20:37:22 +03:00
from realms import search
from realms.modules.wiki.models import WikiPage
2014-11-13 01:06:56 +02:00
2014-11-10 18:54:46 +02:00
@WikiPage.after('write')
def wiki_write_page(page, content, message=None, username=None, email=None, **kwargs):
2014-11-13 01:06:56 +02:00
if not hasattr(search, 'index_wiki'):
# using simple search or none
return
body = dict(name=page.name,
2014-11-12 01:06:28 +02:00
content=content,
message=message,
email=email,
username=username)
return search.index_wiki(page.name, body)
2014-11-10 18:54:46 +02:00
@WikiPage.before('rename')
def wiki_rename_page_del(page, *args, **kwargs):
if not hasattr(search, 'index_wiki'):
return
return search.delete_wiki(page.name)
2015-09-28 07:57:56 +03:00
@WikiPage.after('rename')
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):
2015-09-28 07:57:56 +03:00
if not hasattr(search, 'index_wiki'):
return
return search.delete_wiki(page.name)