def build_menu(self): """ Build a simple menu for all plugin methods witch have a "menu_section" Use the internal page template "admin_menu.plugin_menu" ! In the plugin config (plugin_manager_data) must be exist some meta information for the menu: "menu_section" : The upper block name "menu_description" : Link text (optional, otherwise method name used) More info: http://pylucid.org/_goto/148/self-build_menu/ """ plugin = Plugin.objects.get(plugin_name=self.plugin_name) plugin_config = get_plugin_config( package_name = plugin.package_name, plugin_name = self.plugin_name, ) plugin_version = get_plugin_version( package_name = plugin.package_name, plugin_name = self.plugin_name, ) # debug_plugin_config(self.page_msg, plugin_config) plugin_manager_data = plugin_config.plugin_manager_data menu_data = {} for method_name, data in plugin_manager_data.iteritems(): if not "menu_section" in data: continue menu_section = data["menu_section"] if not menu_section in menu_data: menu_data[menu_section] = [] menu_data[menu_section].append( { "link": self.URLs.methodLink(method_name), "description": data.get("menu_description", method_name), } ) self.context["PAGE"].title = "%s (%s)" % ( self.plugin_name.replace("_", " "), plugin_version ) context = {"menu_data": menu_data,} # Change the internal_page and use them from "admin_menu" plugin. plugin_internal_page = self.internal_page self.internal_page = InternalPage( self.context, plugin_name="admin_menu" ) self._render_template("plugin_menu", context)#, debug=False) # change back to the original internal pages from the current plugin. self.internal_page = plugin_internal_page
def _generate_menu(self): """ Generate the dynamic admin sub menu """ # Get the preferences from the database: preferences = self.get_preferences() if preferences == None: # preferences not in database -> reinit required if self.request.debug == True: msg = ( '<a href="http://www.pylucid.org/_goto/121/changes/">' 'reinit "admin_menu" plugin required!</a>' ) self.page_msg.red(mark_safe(msg)) section_weights = {} else: # Sort the sections with the weight information from the preferences section_weights = preferences["section_weights"] # All installed + active plugins plugins = Plugin.objects.all().filter(active = True).order_by( 'package_name', 'plugin_name' ) menu = Menu(self.page_msg, section_weights) # Get the plugin config and build the menu data for plugin in plugins: try: config = get_plugin_config( package_name = plugin.package_name, plugin_name = plugin.plugin_name, ) except Exception, err: msg = "Error: Can't get plugin config for '%s': %s" % ( plugin.plugin_name, err ) self.page_msg(msg) continue for method, data in config.plugin_manager_data.iteritems(): if "admin_sub_menu" not in data: # This method should not listed into the admin sub menu continue menu_data = data["admin_sub_menu"] section = unicode(menu_data["section"]) # translate gettext_lazy # Add the _command link to the menu data link = self.URLs.commandLink( plugin_name = plugin.plugin_name, method_name = method, ) menu_data["link"] = link menu.add_entry(section, menu_data)
def get_pref_form(self, page_msg, verbosity): """ Get the 'PreferencesForm' newform class from the plugin modul, insert initial information into the help text and return the form. """ plugin_config = get_plugin_config(self.package_name, self.plugin_name) form = getattr(plugin_config, "PreferencesForm") if verbosity>1: page_msg("setup preferences form help text.") setup_help_text(form) return form
def install_plugin(package_name, plugin_name, page_msg, verbosity, user, active=False): """ Get the config object from disk and insert the plugin into the database """ plugin_config = get_plugin_config(package_name, plugin_name) if verbosity > 1: obsolete_test = hasattr(plugin_config, "__important_buildin__") or hasattr( plugin_config, "__essential_buildin__" ) if obsolete_test: page_msg("*** DeprecationWarning: ***") page_msg(" - '__important_buildin__'" " or '__essential_buildin__'" " are obsolete.") plugin = _install_plugin(package_name, plugin_name, plugin_config, user, page_msg, verbosity, active) return plugin
def _get_uninstalled_plugins(self, installed_names): """ Read all Plugin names from the disk and crop it with the given list. """ uninstalled_plugins = [] for path_cfg in settings.PLUGIN_PATH: package_name = ".".join(path_cfg["path"]) plugin_path = os.path.join(settings.MAIN_APP_PATH, path_cfg["path"][1]) plugin_list = get_plugin_list(plugin_path) for plugin_name in plugin_list: if plugin_name in installed_names: continue try: plugin_cfg = get_plugin_config(package_name, plugin_name) except Exception, err: if self.request.debug: raise msg = "Can't get plugin config for %s.%s, Error: %s" % ( package_name, plugin_name, err ) self.page_msg(msg) continue try: plugin_version = get_plugin_version( package_name, plugin_name ) except Exception, err: plugin_version = ( "Can't get plugin version for %s.%s, Error: %s" ) % (package_name, plugin_name, err) uninstalled_plugins.append({ "plugin_name": plugin_name, "package_name": package_name, "description": plugin_cfg.__description__, "url": plugin_cfg.__url__, "author": plugin_cfg.__author__, "version": plugin_version, })
def error(msg): msg = "Error run plugin/plugin '%s.%s: %s" % (plugin_name, method_name, msg) request.page_msg(msg) msg2 = ('<i title="(Error details in page messages.)">["%s.%s" error.]</i>') % (plugin_name, method_name) local_response.write(msg2) # request.page_msg(plugin_name, method_name) try: plugin = Plugin.objects.get(plugin_name=plugin_name) except Plugin.DoesNotExist, e: if request.debug: # don't use errorhandling -> raise the prior error raise error("Plugin not exists in database: %s" % e) return plugin_config = get_plugin_config(plugin.package_name, plugin.plugin_name) # request.page_msg(plugin_config.plugin_manager_data) try: method_cfg = plugin_config.plugin_manager_data[method_name] except KeyError: if request.debug: # don't use errorhandling -> raise the prior error raise error("Can't get config for the method '%s'." % method_name) return # request.page_msg(method_cfg) if method_cfg["must_login"]: # User must be login to use this method # http://www.djangoproject.com/documentation/authentication/ if request.user.is_anonymous(): # User is not logged in