mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-28 16:28:01 -05:00
plugins: Add hook for watching Thing commits.
This commit is contained in:
@@ -256,20 +256,20 @@ class DataThing(object):
|
||||
# (including the return in the above branch)
|
||||
begin()
|
||||
|
||||
to_set = self._dirties.copy()
|
||||
if keys:
|
||||
keys = tup(keys)
|
||||
to_set = dict((k, self._dirties[k][1])
|
||||
for k in keys if self._dirties.has_key(k))
|
||||
else:
|
||||
to_set = dict((k, v[1]) for k, v in self._dirties.iteritems())
|
||||
for key in to_set.keys():
|
||||
if key not in keys:
|
||||
del to_set[key]
|
||||
|
||||
data_props = {}
|
||||
thing_props = {}
|
||||
for k, v in to_set.iteritems():
|
||||
for k, (old_value, new_value) in to_set.iteritems():
|
||||
if k.startswith('_'):
|
||||
thing_props[k[1:]] = v
|
||||
thing_props[k[1:]] = new_value
|
||||
else:
|
||||
data_props[k] = v
|
||||
data_props[k] = new_value
|
||||
|
||||
if data_props:
|
||||
self._set_data(self._type_id,
|
||||
@@ -297,6 +297,8 @@ class DataThing(object):
|
||||
if lock:
|
||||
lock.release()
|
||||
|
||||
g.plugins.on_thing_commit(self, to_set)
|
||||
|
||||
@classmethod
|
||||
def _load_multi(cls, need):
|
||||
need = tup(need)
|
||||
|
||||
@@ -78,6 +78,9 @@ class Plugin(object):
|
||||
def load_controllers(self):
|
||||
pass
|
||||
|
||||
def on_thing_commit(self, thing, changes):
|
||||
pass
|
||||
|
||||
|
||||
class PluginLoader(object):
|
||||
def __init__(self, plugin_names=None):
|
||||
@@ -137,3 +140,7 @@ class PluginLoader(object):
|
||||
def load_controllers(self):
|
||||
for plugin in self:
|
||||
plugin.load_controllers()
|
||||
|
||||
def on_thing_commit(self, thing, changes):
|
||||
for plugin in self:
|
||||
plugin.on_thing_commit(thing, changes)
|
||||
|
||||
Reference in New Issue
Block a user