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
|
from realms import search
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Wiki.after('write_page')
|
@Wiki.after('write_page')
|
||||||
def wiki_write_page(name, content, message=None, username=None, email=None, **kwargs):
|
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')
|
@Wiki.after('rename_page')
|
||||||
def wiki_rename_page(*args, **kwargs):
|
def wiki_rename_page(old_name, *args, **kwargs):
|
||||||
pass
|
|
||||||
|
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.update_document(path=id_.decode("utf-8"), body=body["content"].decode("utf-8"))
|
||||||
writer.commit()
|
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):
|
def index_wiki(self, name, body):
|
||||||
self.index('wiki', 'page', id_=name, body=body)
|
self.index('wiki', 'page', id_=name, body=body)
|
||||||
|
|
||||||
|
def delete_wiki(self, name):
|
||||||
|
self.delete(id_=name)
|
||||||
|
|
||||||
def delete_index(self, index):
|
def delete_index(self, index):
|
||||||
from whoosh import index as whoosh_index
|
from whoosh import index as whoosh_index
|
||||||
self.search_index.close()
|
self.search_index.close()
|
||||||
|
@ -133,9 +143,15 @@ class ElasticSearch(BaseSearch):
|
||||||
def index(self, index, doc_type, id_=None, body=None):
|
def index(self, index, doc_type, id_=None, body=None):
|
||||||
return self.elastic.index(index=index, doc_type=doc_type, id=id_, body=body)
|
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):
|
def index_wiki(self, name, body):
|
||||||
self.index('wiki', 'page', id_=name, body=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):
|
def delete_index(self, index):
|
||||||
return self.elastic.indices.delete(index=index, ignore=[400, 404])
|
return self.elastic.indices.delete(index=index, ignore=[400, 404])
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue