def post(self, request): plugin_id = request.form['id'] plugin = prism.get_plugin(plugin_id) action = request.form['action'] if plugin is not None and action is not None: if action == 'get_settings': options = {} for option_id, option in plugin.settings.options.items(): options[option_id] = option options[option_id]['locale'] = prism.helpers.locale_(plugin_id, 'setting.' + option_id) return plugin.settings.options elif action == 'set_settings': settings = json.loads(request.form['settings']) for setting, value in settings.items(): plugin.settings[setting] = value return '' elif action == 'enable': if plugin_id not in prism.settings.PRISM_CONFIG['enabled_plugins']: prism.settings.PRISM_CONFIG['enabled_plugins'].append(plugin_id) elif action == 'disable': if plugin_id in prism.settings.PRISM_CONFIG['enabled_plugins']: prism.settings.PRISM_CONFIG['enabled_plugins'].remove(plugin_id) return ('core.RestartView', {'return_url': 'dashboard.PluginListView'}) return ('dashboard.PluginListView')
def plugin_static(plugin_id, static_file): """ Allows plugins to load files from their own static directories """ plugin = prism.get_plugin(plugin_id) if plugin is None: return 'Unknown plugin: %s' % plugin_id plugin_id = 'prism_' + plugin_id if plugin.is_core: static_dir = os.path.join(prism.settings.CORE_PLUGINS_PATH, plugin_id) else: static_dir = os.path.join(prism.settings.PLUGINS_PATH, plugin_id) static_dir = os.path.join(static_dir, 'static') return flask.send_from_directory(static_dir, static_file)
def locale(s): if not isinstance(s, str): return repr(s) """ Used for localization """ plugin_id = flask.g.current_plugin if plugin_id is None: plugin_id = 'prism' # Allow setting their own plugin id (Iunno why, but it might be useful) if ':' in s: new_plugin_id, ns = s.split(':', 1) if new_plugin_id == 'prism' or prism.get_plugin( new_plugin_id) is not None: plugin_id = new_plugin_id s = ns return locale_(plugin_id, s)
def edit_post(self, request): prism_dashboard = prism.get_plugin('dashboard') action = request.form['action'] if action == 'show' or action == 'hide': widget_id = request.form['id'] if action == 'show': prism_dashboard._widgets[widget_id]['shown'] = True else: prism_dashboard._widgets[widget_id]['shown'] = False elif action == 'order': data = request.form['data'] for pack in data.split(','): if pack == '': continue pack = pack.split('=') prism_dashboard._widgets[pack[0]]['order'] = int(pack[1]) prism_dashboard.save_widgets() return '1'
def locale_(plugin_id, s): # Search the plugin that's rendering the template for the requested locale if plugin_id == 'prism': ns = prism.settings.PRISM_LOCALE[s] else: plugin = prism.get_plugin(plugin_id) if plugin is None: prism.output('Unknown plugin ID. Offender: %s' % plugin_id) return s ns = plugin.locale[s] if s == ns: return s ns = publish_string( ns, writer=html_fragment_writer).decode('utf-8').rstrip('\r\n') if '<p>' not in ns: return '' ns = ns.split('<p>', 1)[1] ns = ns[:ns.rfind('</p>')] return jinja2.Markup(ns)
def edit_get(self, request): return ('dashboard_edit.html', {'widgets': prism.get_plugin('dashboard').get_widgets(all=True)})
def get(self, request): return ('dashboard.html', {'widgets': prism.get_plugin('dashboard').get_widgets()})