Skip to content

Commit

Permalink
Call plugin initialize after it is saved (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
gigxz authored Nov 22, 2021
1 parent 22acd45 commit ba860e4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
3 changes: 1 addition & 2 deletions metagov/metagov/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,10 @@ def __str__(self):
def save(self, *args, **kwargs):
if not self.pk:
self.state = DataStore.objects.create()
self.initialize()
super(Plugin, self).save(*args, **kwargs)

def initialize(self):
"""Initialize the plugin. Invoked once, when the plugin instance is created."""
"""Initialize the plugin. Invoked once, directly after the plugin instance is created."""
pass

def start_process(self, process_name, callback_url=None, **kwargs):
Expand Down
2 changes: 2 additions & 0 deletions metagov/metagov/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def create_or_update_plugin(plugin_name, plugin_config, community):
name=plugin_name, community=community, config=plugin_config, community_platform_id=community_platform_id
)
logger.info(f"Created plugin '{inst}'")
inst.initialize()
return (inst, True)
else:
if plugin.config != plugin_config:
Expand All @@ -119,6 +120,7 @@ def create_or_update_plugin(plugin_name, plugin_config, community):
config=plugin_config,
community_platform_id=community_platform_id,
)
inst.initialize()
return (inst, True)

logger.info(f"Not updating '{plugin}', no change in config.")
Expand Down
3 changes: 1 addition & 2 deletions metagov/metagov/plugins/loomio/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ def initialize(self):
self.state.set("api_key_group_map", api_key_group_map)

# Set the community_platform_id to the main group handle
parent_group_handle = api_key_group_map[self.config["api_key"]]["handle"]
self.community_platform_id = parent_group_handle
self.community_platform_id = api_key_group_map[self.config["api_key"]]["handle"]
self.save()

def _get_api_key(self, key_or_handle=None):
Expand Down

0 comments on commit ba860e4

Please sign in to comment.