Merge branch 'master' into history_optimization
This commit is contained in:
commit
fcb23466dd
|
@ -145,7 +145,7 @@ class Config(object):
|
|||
def __init__(self):
|
||||
for k, v in self.read().iteritems():
|
||||
setattr(self, k, v)
|
||||
if hasattr(self, 'AUTH_LOCAL_ENABLE'):
|
||||
if getattr(self, 'AUTH_LOCAL_ENABLE', True):
|
||||
self.MODULES.append('auth.local')
|
||||
if hasattr(self, 'OAUTH'):
|
||||
self.MODULES.append('auth.oauth')
|
||||
|
|
|
@ -7,7 +7,7 @@ def hook_func(name, fn):
|
|||
@wraps(fn)
|
||||
def wrapper(self, *args, **kwargs):
|
||||
for hook, a, kw in self.__class__._pre_hooks.get(name) or []:
|
||||
hook(*args, **kwargs)
|
||||
hook(self, *args, **kwargs)
|
||||
|
||||
rv = fn(self, *args, **kwargs)
|
||||
|
||||
|
@ -15,7 +15,7 @@ def hook_func(name, fn):
|
|||
kwargs.update(dict(rv=rv))
|
||||
|
||||
for hook, a, kw in self.__class__._post_hooks.get(name) or []:
|
||||
hook(*args, **kwargs)
|
||||
hook(self, *args, **kwargs)
|
||||
|
||||
return rv
|
||||
return wrapper
|
||||
|
|
|
@ -1,35 +1,40 @@
|
|||
from realms.modules.wiki.models import Wiki
|
||||
from realms.modules.wiki.models import WikiPage
|
||||
from realms import search
|
||||
|
||||
|
||||
@Wiki.after('write_page')
|
||||
def wiki_write_page(name, content, message=None, username=None, email=None, **kwargs):
|
||||
@WikiPage.after('write')
|
||||
def wiki_write_page(page, content, message=None, username=None, email=None, **kwargs):
|
||||
|
||||
if not hasattr(search, 'index_wiki'):
|
||||
# using simple search or none
|
||||
return
|
||||
|
||||
body = dict(name=name,
|
||||
body = dict(name=page.name,
|
||||
content=content,
|
||||
message=message,
|
||||
email=email,
|
||||
username=username)
|
||||
return search.index_wiki(name, body)
|
||||
return search.index_wiki(page.name, body)
|
||||
|
||||
|
||||
@Wiki.after('rename_page')
|
||||
def wiki_rename_page(old_name, *args, **kwargs):
|
||||
@WikiPage.before('rename')
|
||||
def wiki_rename_page_del(page, *args, **kwargs):
|
||||
|
||||
if not hasattr(search, 'index_wiki'):
|
||||
return
|
||||
|
||||
return search.delete_wiki(old_name)
|
||||
return search.delete_wiki(page.name)
|
||||
|
||||
|
||||
@Wiki.after('delete_page')
|
||||
def wiki_delete_page(name, *args, **kwargs):
|
||||
@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):
|
||||
|
||||
if not hasattr(search, 'index_wiki'):
|
||||
return
|
||||
|
||||
return search.delete_wiki(name)
|
||||
return search.delete_wiki(page.name)
|
||||
|
|
|
@ -42,6 +42,27 @@ class Wiki(HookMixin):
|
|||
def __repr__(self):
|
||||
return "Wiki: %s" % self.path
|
||||
|
||||
def commit(self, name, email, message, files):
|
||||
"""Commit to the underlying git repo.
|
||||
|
||||
:param name: Committer name
|
||||
:param email: Committer email
|
||||
:param message: Commit message
|
||||
:param files: list of file names that should be committed
|
||||
:return:
|
||||
"""
|
||||
# Dulwich and gittle seem to want us to encode ourselves at the moment. see #152
|
||||
if isinstance(name, unicode):
|
||||
name = name.encode('utf-8')
|
||||
if isinstance(email, unicode):
|
||||
email = email.encode('utf-8')
|
||||
if isinstance(message, unicode):
|
||||
message = message.encode('utf-8')
|
||||
return self.gittle.commit(name=name,
|
||||
email=email,
|
||||
message=message,
|
||||
files=files)
|
||||
|
||||
def get_page(self, name, sha='HEAD'):
|
||||
"""Get page data, partials, commit info.
|
||||
|
||||
|
@ -71,7 +92,7 @@ class Wiki(HookMixin):
|
|||
return rv
|
||||
|
||||
|
||||
class WikiPage(object):
|
||||
class WikiPage(HookMixin):
|
||||
def __init__(self, name, wiki, sha='HEAD'):
|
||||
self.name = name
|
||||
self.filename = cname_to_filename(name)
|
||||
|
@ -202,7 +223,7 @@ class WikiPage(object):
|
|||
return username, email
|
||||
|
||||
def _clear_cache(self):
|
||||
cache.delete_many(self._cache_key(p) for p in ['data', 'info'])
|
||||
cache.delete_many(*(self._cache_key(p) for p in ['data', 'info']))
|
||||
|
||||
def delete(self, username=None, email=None, message=None):
|
||||
"""Delete page.
|
||||
|
@ -219,7 +240,7 @@ class WikiPage(object):
|
|||
# gittle.rm won't actually remove the file, have to do it ourselves
|
||||
os.remove(os.path.join(self.wiki.path, self.filename))
|
||||
self.wiki.gittle.rm(self.filename)
|
||||
commit = self.wiki.gittle.commit(name=username,
|
||||
commit = self.wiki.commit(name=username,
|
||||
email=email,
|
||||
message=message,
|
||||
files=[self.filename])
|
||||
|
@ -256,7 +277,7 @@ class WikiPage(object):
|
|||
self.wiki.gittle.add(new_filename)
|
||||
self.wiki.gittle.rm(old_filename)
|
||||
|
||||
commit = self.wiki.gittle.commit(name=username,
|
||||
commit = self.wiki.commit(name=username,
|
||||
email=email,
|
||||
message=message,
|
||||
files=[old_filename, new_filename])
|
||||
|
@ -296,7 +317,7 @@ class WikiPage(object):
|
|||
|
||||
username, email = self._get_user(username, email)
|
||||
|
||||
ret = self.wiki.gittle.commit(name=username,
|
||||
ret = self.wiki.commit(name=username,
|
||||
email=email,
|
||||
message=message,
|
||||
files=[self.filename])
|
||||
|
|
Loading…
Reference in a new issue