호라이즌 MyPanel3

1 개요[ | ]

호라이즌 MyPanel3

2 panel.py[ | ]

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)

3 urls.py[ | ]

from django.conf.urls import url
from openstack_dashboard.dashboards.mydashboard.mypanel import views

urlpatterns = [
    url(r'^$', views.IndexView.as_view(), name='index'),
]

4 views.py[ | ]

from horizon import tables
from .tables import EmployeeTable

class Employee:
    def __init__(self, id, name, team):
        self.id = id
        self.name = name
        self.team = team

class IndexView(tables.DataTableView):
    table_class = EmployeeTable
    template_name = 'mydashboard/mypanel/index.html'
    
    def get_data(self):
        employees = []
        employees.append(Employee(111,"Alice","MyTeam"))
        employees.append(Employee(222,"Bob","MyTeam"))
        employees.append(Employee(333,"Carol","MyTeam"))
        return employees

5 tables.py[ | ]

from django.utils.translation import ugettext_lazy as _
from horizon import tables

class EmployeeTable(tables.DataTable):
    id = tables.Column("id", verbose_name=_("ID"))
    name = tables.Column("name", verbose_name=_("Name"))
    team = tables.Column("team", verbose_name=_("Team"))
    class Meta:
        name = "employeetable"
        verbose_name = _("EmployeeTable")

6 templates/mypanel/index.html[ | ]

{% extends 'base.html' %}
{% load i18n %}
{% block title %}{% trans "Employees" %}{% endblock %}
 
{% block page_header %}
  {% include "horizon/common/_page_header.html" with title=_("Employees") %}
{% endblock page_header %}
 
{% block main %}
  {{ table.render }}
{% endblock %}

7 같이 보기[ | ]

8 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}