From 2aecf4470b61086f75c6af9889379b121c7beb44 Mon Sep 17 00:00:00 2001 From: David Lyle Date: Mon, 12 Jan 2015 21:13:53 -0700 Subject: [PATCH] Updating startpanel for pluggables 'run_tests.sh -m startpanel ' command for creating new panels still requires specifying the dashboard with the '--dashboard=' otherwise it fails. With the new mechanism for plugging in extensions, this should no longer be a requirement as the handling of the enabled file will do the registration. It is still a valid option for integrated content generation though. Closes-Bug: #1410025 Change-Id: Ibaaa6c4d36defeae420919d0ea647e18127afefb --- doc/source/ref/run_tests.rst | 8 +++--- horizon/conf/panel_template/models.py | 3 --- horizon/conf/panel_template/panel.py.tmpl | 8 +++--- .../templates/panel_name/index.html | 2 +- horizon/management/commands/startpanel.py | 26 ++++++++----------- 5 files changed, 20 insertions(+), 27 deletions(-) delete mode 100644 horizon/conf/panel_template/models.py diff --git a/doc/source/ref/run_tests.rst b/doc/source/ref/run_tests.rst index 6cff42b1b7..a8e731ea80 100644 --- a/doc/source/ref/run_tests.rst +++ b/doc/source/ref/run_tests.rst @@ -117,7 +117,7 @@ Panels To create a new panel, run the following:: - ./run_tests -m startpanel --dashboard= + ./run_tests -m startpanel This will create a directory with the given panel name, and ``panel.py`` module with the basic panel code filled in, and various other common @@ -125,8 +125,10 @@ module with the basic panel code filled in, and various other common Available options: -* ``-d``, ``--dashboard``: The dotted python path to your dashboard app (the module - which containers the ``dashboard.py`` file.). +* ``-d``, ``--dashboard``: The dotted python path to your dashboard app (the + module which containers the ``dashboard.py`` file.). If not specified, the + target dashboard should be specified in a pluggable settings file for the + panel. * ``--target``: the directory in which the panel files should be created. If the value is ``auto`` the panel will be created as a new directory inside the dashboard module's directory structure. Default: A new directory within diff --git a/horizon/conf/panel_template/models.py b/horizon/conf/panel_template/models.py deleted file mode 100644 index 1b3d5f9efc..0000000000 --- a/horizon/conf/panel_template/models.py +++ /dev/null @@ -1,3 +0,0 @@ -""" -Stub file to work around django bug: https://code.djangoproject.com/ticket/7198 -""" diff --git a/horizon/conf/panel_template/panel.py.tmpl b/horizon/conf/panel_template/panel.py.tmpl index 4364438e21..949ac09690 100644 --- a/horizon/conf/panel_template/panel.py.tmpl +++ b/horizon/conf/panel_template/panel.py.tmpl @@ -1,13 +1,11 @@ from django.utils.translation import ugettext_lazy as _ import horizon - -from {{ dash_path }} import dashboard - +{% if dashboard %}from {{ dash_path }} import dashboard{% endif %} class {{ panel_name|title }}(horizon.Panel): name = _("{{ panel_name|title }}") slug = "{{ panel_name|slugify }}" +{% if dashboard %} - -dashboard.{{ dash_name|title }}.register({{ panel_name|title }}) +dashboard.{{ dash_name|title }}.register({{ panel_name|title }}){% endif %} diff --git a/horizon/conf/panel_template/templates/panel_name/index.html b/horizon/conf/panel_template/templates/panel_name/index.html index e4aa591d23..97a0d57be4 100644 --- a/horizon/conf/panel_template/templates/panel_name/index.html +++ b/horizon/conf/panel_template/templates/panel_name/index.html @@ -6,7 +6,7 @@ [% include "horizon/common/_page_header.html" with title=_("{{ panel_name|title }}") %] [% endblock page_header %] -[% block {{ dash_name }}_main %] +[% block main %] [% endblock %] {% endjstemplate %} diff --git a/horizon/management/commands/startpanel.py b/horizon/management/commands/startpanel.py index a35f02fba5..855fe33054 100644 --- a/horizon/management/commands/startpanel.py +++ b/horizon/management/commands/startpanel.py @@ -50,25 +50,21 @@ class Command(TemplateCommand): if panel_name is None: raise CommandError("You must provide a panel name.") - if options.get('dashboard') is None: - raise CommandError("You must specify the name of the dashboard " - "this panel will be registered with using the " - "-d or --dashboard option.") - - dashboard_path = options.get('dashboard') - dashboard_mod_path = ".".join([dashboard_path, "dashboard"]) + if options.get('dashboard'): + dashboard_path = options.get('dashboard') + dashboard_mod_path = ".".join([dashboard_path, "dashboard"]) # Check the dashboard.py file in the dashboard app can be imported. # Add the dashboard information to our options to pass along if all # goes well. - try: - dashboard_mod = import_module(dashboard_mod_path) - options["dash_path"] = dashboard_path - options["dash_name"] = dashboard_path.split(".")[-1] - except ImportError: - raise CommandError("A dashboard.py module could not be imported " - " from the dashboard at %r." - % options.get("dashboard")) + try: + dashboard_mod = import_module(dashboard_mod_path) + options["dash_path"] = dashboard_path + options["dash_name"] = dashboard_path.split(".")[-1] + except ImportError: + raise CommandError("A dashboard.py module could not be " + "imported from the dashboard at %r." + % options.get("dashboard")) target = options.pop("target", None) if target == "auto":