From 2ff433523343b9be520b866bc4dad54ead20b900 Mon Sep 17 00:00:00 2001 From: Jonas Pfannschmidt Date: Fri, 23 Jan 2015 12:28:34 +0000 Subject: [PATCH] ajax bug example --- .../dashboards/mydashboard/__init__.py | 0 .../dashboards/mydashboard/dashboard.py | 13 ++++++ .../dashboards/mydashboard/models.py | 3 ++ .../dashboards/mydashboard/mypanel/__init__.py | 0 .../dashboards/mydashboard/mypanel/models.py | 3 ++ .../dashboards/mydashboard/mypanel/panel.py | 15 +++++++ .../dashboards/mydashboard/mypanel/tables.py | 47 ++++++++++++++++++++++ .../dashboards/mydashboard/mypanel/tabs.py | 33 +++++++++++++++ .../mypanel/templates/mypanel/first_tab.html | 1 + .../mypanel/templates/mypanel/index.html | 17 ++++++++ .../dashboards/mydashboard/mypanel/tests.py | 7 ++++ .../dashboards/mydashboard/mypanel/urls.py | 14 +++++++ .../dashboards/mydashboard/mypanel/views.py | 10 +++++ .../static/mydashboard/css/mydashboard.css | 1 + .../static/mydashboard/js/mydashboard.js | 1 + .../mydashboard/templates/mydashboard/base.html | 11 +++++ openstack_dashboard/enabled/_50_mydashboard.py | 10 +++++ 17 files changed, 186 insertions(+) create mode 100644 openstack_dashboard/dashboards/mydashboard/__init__.py create mode 100644 openstack_dashboard/dashboards/mydashboard/dashboard.py create mode 100644 openstack_dashboard/dashboards/mydashboard/models.py create mode 100644 openstack_dashboard/dashboards/mydashboard/mypanel/__init__.py create mode 100644 openstack_dashboard/dashboards/mydashboard/mypanel/models.py create mode 100644 openstack_dashboard/dashboards/mydashboard/mypanel/panel.py create mode 100644 openstack_dashboard/dashboards/mydashboard/mypanel/tables.py create mode 100644 openstack_dashboard/dashboards/mydashboard/mypanel/tabs.py create mode 100644 openstack_dashboard/dashboards/mydashboard/mypanel/templates/mypanel/first_tab.html create mode 100644 openstack_dashboard/dashboards/mydashboard/mypanel/templates/mypanel/index.html create mode 100644 openstack_dashboard/dashboards/mydashboard/mypanel/tests.py create mode 100644 openstack_dashboard/dashboards/mydashboard/mypanel/urls.py create mode 100644 openstack_dashboard/dashboards/mydashboard/mypanel/views.py create mode 100644 openstack_dashboard/dashboards/mydashboard/static/mydashboard/css/mydashboard.css create mode 100644 openstack_dashboard/dashboards/mydashboard/static/mydashboard/js/mydashboard.js create mode 100644 openstack_dashboard/dashboards/mydashboard/templates/mydashboard/base.html create mode 100644 openstack_dashboard/enabled/_50_mydashboard.py diff --git a/openstack_dashboard/dashboards/mydashboard/__init__.py b/openstack_dashboard/dashboards/mydashboard/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/openstack_dashboard/dashboards/mydashboard/dashboard.py b/openstack_dashboard/dashboards/mydashboard/dashboard.py new file mode 100644 index 0000000..15180c4 --- /dev/null +++ b/openstack_dashboard/dashboards/mydashboard/dashboard.py @@ -0,0 +1,13 @@ +from django.utils.translation import ugettext_lazy as _ + +import horizon + + +class Mydashboard(horizon.Dashboard): + name = _("Mydashboard") + slug = "mydashboard" + panels = ('mypanel',) # Add your panels here. + default_panel = 'mypanel' # Specify the slug of the default panel. + + +horizon.register(Mydashboard) diff --git a/openstack_dashboard/dashboards/mydashboard/models.py b/openstack_dashboard/dashboards/mydashboard/models.py new file mode 100644 index 0000000..1b3d5f9 --- /dev/null +++ b/openstack_dashboard/dashboards/mydashboard/models.py @@ -0,0 +1,3 @@ +""" +Stub file to work around django bug: https://code.djangoproject.com/ticket/7198 +""" diff --git a/openstack_dashboard/dashboards/mydashboard/mypanel/__init__.py b/openstack_dashboard/dashboards/mydashboard/mypanel/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/openstack_dashboard/dashboards/mydashboard/mypanel/models.py b/openstack_dashboard/dashboards/mydashboard/mypanel/models.py new file mode 100644 index 0000000..1b3d5f9 --- /dev/null +++ b/openstack_dashboard/dashboards/mydashboard/mypanel/models.py @@ -0,0 +1,3 @@ +""" +Stub file to work around django bug: https://code.djangoproject.com/ticket/7198 +""" diff --git a/openstack_dashboard/dashboards/mydashboard/mypanel/panel.py b/openstack_dashboard/dashboards/mydashboard/mypanel/panel.py new file mode 100644 index 0000000..3e7f156 --- /dev/null +++ b/openstack_dashboard/dashboards/mydashboard/mypanel/panel.py @@ -0,0 +1,15 @@ +from django.utils.translation import ugettext_lazy as _ + +import horizon + +from openstack_dashboard.dashboards.mydashboard import dashboard + + +class Mypanel(horizon.Panel): + name = _("Mypanel") + slug = "mypanel" + + +dashboard.Mydashboard.register(Mypanel) + + diff --git a/openstack_dashboard/dashboards/mydashboard/mypanel/tables.py b/openstack_dashboard/dashboards/mydashboard/mypanel/tables.py new file mode 100644 index 0000000..a481764 --- /dev/null +++ b/openstack_dashboard/dashboards/mydashboard/mypanel/tables.py @@ -0,0 +1,47 @@ +from django.utils.translation import ugettext_lazy as _ + +from horizon import tables + +data = { + 1: 'one', + 2: 'two', + 3: 'three', + 4: 'four', + 5: 'five', + 6: 'six', + 7: 'seven', + 8: 'eight', + 9: 'nine', + 10: 'ten' +} + +def is_loaded(i): + if isinstance(i, (int, long)): + return None + else: + return True + +def get_data_or_wait(i): + if is_loaded(i): + return i + else: + return "Loading ..." + +class AjaxUpdateRow(tables.Row): + ajax = True + + def get_data(self, request, id): + return data[int(id)] + +class MyTable(tables.DataTable): + name = tables.Column(get_data_or_wait, verbose_name=_("Data")) + status = tables.Column(is_loaded, verbose_name=("Status")) + + def get_object_id(self, id): + return id + + class Meta: + name = "my" + verbose_name = _("Test") + row_class = AjaxUpdateRow + status_columns = ['status', ] \ No newline at end of file diff --git a/openstack_dashboard/dashboards/mydashboard/mypanel/tabs.py b/openstack_dashboard/dashboards/mydashboard/mypanel/tabs.py new file mode 100644 index 0000000..d391314 --- /dev/null +++ b/openstack_dashboard/dashboards/mydashboard/mypanel/tabs.py @@ -0,0 +1,33 @@ +from django.utils.translation import ugettext_lazy as _ +from horizon import tabs +from openstack_dashboard.dashboards.mydashboard.mypanel import tables + +class FirstTab(tabs.Tab): + name = _("First Tab") + slug = "first_tab" + + template_name = ("mydashboard/mypanel/first_tab.html") + +class SecondTab(tabs.TableTab): + name = _("Second Tab") + slug = "second_tab" + table_classes = (tables.MyTable,) + template_name = ("horizon/common/_detail_table.html") + preload = False + + def has_more_data(self, table): + return False + + def get_my_data(self): + return [1, 2, 3, 4, 5, 6,7,8,9,10] + +class MypanelTabs(tabs.TabGroup): + slug = "mypanel_tabs" + + # this doesn't work + tabs = (FirstTab, SecondTab) + + # this works + # tabs = (SecondTab, FirstTab) + + sticky = True diff --git a/openstack_dashboard/dashboards/mydashboard/mypanel/templates/mypanel/first_tab.html b/openstack_dashboard/dashboards/mydashboard/mypanel/templates/mypanel/first_tab.html new file mode 100644 index 0000000..e87b459 --- /dev/null +++ b/openstack_dashboard/dashboards/mydashboard/mypanel/templates/mypanel/first_tab.html @@ -0,0 +1 @@ +

The first tab

\ No newline at end of file diff --git a/openstack_dashboard/dashboards/mydashboard/mypanel/templates/mypanel/index.html b/openstack_dashboard/dashboards/mydashboard/mypanel/templates/mypanel/index.html new file mode 100644 index 0000000..f25c931 --- /dev/null +++ b/openstack_dashboard/dashboards/mydashboard/mypanel/templates/mypanel/index.html @@ -0,0 +1,17 @@ +{% extends 'mydashboard/base.html' %} +{% load i18n %} +{% block title %}{% trans "Mypanel" %}{% endblock %} + +{% block page_header %} + {% include "horizon/common/_page_header.html" with title=_("Mypanel") %} +{% endblock page_header %} + +{% block mydashboard_main %} +
+
+ {{ tab_group.render }} +
+
+{% endblock %} + + diff --git a/openstack_dashboard/dashboards/mydashboard/mypanel/tests.py b/openstack_dashboard/dashboards/mydashboard/mypanel/tests.py new file mode 100644 index 0000000..6ee36f9 --- /dev/null +++ b/openstack_dashboard/dashboards/mydashboard/mypanel/tests.py @@ -0,0 +1,7 @@ +from horizon.test import helpers as test + + +class MypanelTests(test.TestCase): + # Unit tests for mypanel. + def test_me(self): + self.assertTrue(1 + 1 == 2) diff --git a/openstack_dashboard/dashboards/mydashboard/mypanel/urls.py b/openstack_dashboard/dashboards/mydashboard/mypanel/urls.py new file mode 100644 index 0000000..e547265 --- /dev/null +++ b/openstack_dashboard/dashboards/mydashboard/mypanel/urls.py @@ -0,0 +1,14 @@ +from django.conf.urls import patterns +from django.conf.urls import url + +from openstack_dashboard.dashboards.mydashboard.mypanel.views \ + import IndexView + + +urlpatterns = patterns( + '', + url(r'^$', IndexView.as_view(), name='index'), + + url(r'^\?tab=mypanel_tabs_tab$', + IndexView.as_view(), name='mypanel_tabs'), +) diff --git a/openstack_dashboard/dashboards/mydashboard/mypanel/views.py b/openstack_dashboard/dashboards/mydashboard/mypanel/views.py new file mode 100644 index 0000000..17ad62b --- /dev/null +++ b/openstack_dashboard/dashboards/mydashboard/mypanel/views.py @@ -0,0 +1,10 @@ +from horizon import tabs +import tabs as mypanel + +class IndexView(tabs.TabbedTableView): + tab_group_class = mypanel.MypanelTabs + template_name = 'mydashboard/mypanel/index.html' + + def get_data(self, request, context, *args, **kwargs): + # Add data to the context here... + return context diff --git a/openstack_dashboard/dashboards/mydashboard/static/mydashboard/css/mydashboard.css b/openstack_dashboard/dashboards/mydashboard/static/mydashboard/css/mydashboard.css new file mode 100644 index 0000000..a329e7d --- /dev/null +++ b/openstack_dashboard/dashboards/mydashboard/static/mydashboard/css/mydashboard.css @@ -0,0 +1 @@ +/* Additional CSS for mydashboard. */ diff --git a/openstack_dashboard/dashboards/mydashboard/static/mydashboard/js/mydashboard.js b/openstack_dashboard/dashboards/mydashboard/static/mydashboard/js/mydashboard.js new file mode 100644 index 0000000..d8a2176 --- /dev/null +++ b/openstack_dashboard/dashboards/mydashboard/static/mydashboard/js/mydashboard.js @@ -0,0 +1 @@ +/* Additional JavaScript for mydashboard. */ diff --git a/openstack_dashboard/dashboards/mydashboard/templates/mydashboard/base.html b/openstack_dashboard/dashboards/mydashboard/templates/mydashboard/base.html new file mode 100644 index 0000000..b28b819 --- /dev/null +++ b/openstack_dashboard/dashboards/mydashboard/templates/mydashboard/base.html @@ -0,0 +1,11 @@ +{% extends 'base.html' %} + +{% block sidebar %} + {% include 'horizon/common/_sidebar.html' %} +{% endblock %} + +{% block main %} + {% include "horizon/_messages.html" %} + {% block mydashboard_main %}{% endblock %} +{% endblock %} + diff --git a/openstack_dashboard/enabled/_50_mydashboard.py b/openstack_dashboard/enabled/_50_mydashboard.py new file mode 100644 index 0000000..d54b259 --- /dev/null +++ b/openstack_dashboard/enabled/_50_mydashboard.py @@ -0,0 +1,10 @@ +# The name of the dashboard to be added to HORIZON['dashboards']. Required. +DASHBOARD = 'mydashboard' + +# If set to True, this dashboard will not be added to the settings. +DISABLED = False + +# A list of applications to be added to INSTALLED_APPS. +ADD_INSTALLED_APPS = [ + 'openstack_dashboard.dashboards.mydashboard', +] \ No newline at end of file -- 1.9.1