Add delete wiki page feature, delete wiki page after rename
This commit is contained in:
parent
fdf482d14b
commit
4ef08cc988
|
@ -2,7 +2,6 @@ from realms.modules.wiki.models import Wiki
|
|||
from realms import search
|
||||
|
||||
|
||||
|
||||
@Wiki.after('write_page')
|
||||
def wiki_write_page(name, content, message=None, username=None, email=None, **kwargs):
|
||||
|
||||
|
@ -19,5 +18,9 @@ def wiki_write_page(name, content, message=None, username=None, email=None, **kw
|
|||
|
||||
|
||||
@Wiki.after('rename_page')
|
||||
def wiki_rename_page(*args, **kwargs):
|
||||
pass
|
||||
def wiki_rename_page(old_name, *args, **kwargs):
|
||||
|
||||
if not hasattr(search, 'index_wiki'):
|
||||
return
|
||||
|
||||
return search.delete_wiki(old_name)
|
||||
|
|
|
@ -92,9 +92,19 @@ class WhooshSearch(BaseSearch):
|
|||
writer.update_document(path=id_.decode("utf-8"), body=body["content"].decode("utf-8"))
|
||||
writer.commit()
|
||||
|
||||
def delete(self, id_):
|
||||
with self.search_index.searcher() as s:
|
||||
doc_num = s.document_number(path=id_.decode("utf-8"))
|
||||
writer = self.search_index.writer()
|
||||
writer.delete_document(doc_num)
|
||||
writer.commit()
|
||||
|
||||
def index_wiki(self, name, body):
|
||||
self.index('wiki', 'page', id_=name, body=body)
|
||||
|
||||
def delete_wiki(self, name):
|
||||
self.delete(id_=name)
|
||||
|
||||
def delete_index(self, index):
|
||||
from whoosh import index as whoosh_index
|
||||
self.search_index.close()
|
||||
|
@ -133,9 +143,15 @@ class ElasticSearch(BaseSearch):
|
|||
def index(self, index, doc_type, id_=None, body=None):
|
||||
return self.elastic.index(index=index, doc_type=doc_type, id=id_, body=body)
|
||||
|
||||
def delete(self, index, doc_type, id_):
|
||||
return self.elastic.delete(index=index, doc_type=doc_type, id=id_)
|
||||
|
||||
def index_wiki(self, name, body):
|
||||
self.index('wiki', 'page', id_=name, body=body)
|
||||
|
||||
def delete_wiki(self, name):
|
||||
self.delete('wiki', 'page', id_=name)
|
||||
|
||||
def delete_index(self, index):
|
||||
return self.elastic.indices.delete(index=index, ignore=[400, 404])
|
||||
|
||||
|
|
Loading…
Reference in a new issue