def __init__(self, user_info=None): """ user_info: {"username": "******", "userimg": "xxxx", "userstatus":"online"} """ super(self.__class__, self).__init__("aside", {"class": "main-sidebar"}) self.section = ZenWidget("section", {"class": "sidebar"}) self.user_info = user_info if not self.user_info: self.user_info = {} self.sidebar_menu = ZenWidget("ul", {"class": "sidebar-menu"}) self.menu_items = []
def set_footer(self, msg, link_href=None): self.header = ZenWidget("li", {"class": "footer"}) if link_href: link = Link(link_href) link.append_text(msg) self.append_widget(link) else: self.header.append_text(msg)
class DropdownMenu(ZenWidget): def __init__(self): super(self.__class__, self).__init__("ul", {"class": "dropdown-menu"}) self.header = None self.footer = None self.menu_items = [] def set_header(self, msg, link_href=None): self.header = ZenWidget("li", {"class": "header"}) if link_href: link = Link(link_href) link.append_text(msg) self.append_widget(link) else: self.header.append_text(msg) def set_footer(self, msg, link_href=None): self.header = ZenWidget("li", {"class": "footer"}) if link_href: link = Link(link_href) link.append_text(msg) self.append_widget(link) else: self.header.append_text(msg) def append_menuitem(self, item): self.menu_items.append(item) def render(self): self.sub_widgets = [] if self.header: self.append_widget(self.header) for item in self.menu_items: self.append_widget(item) if self.footer: self.append_widget(self.footer) return super(self.__class__, self).render()
class SideBar(ZenWidget): def __init__(self, user_info=None): """ user_info: {"username": "******", "userimg": "xxxx", "userstatus":"online"} """ super(self.__class__, self).__init__("aside", {"class": "main-sidebar"}) self.section = ZenWidget("section", {"class": "sidebar"}) self.user_info = user_info if not self.user_info: self.user_info = {} self.sidebar_menu = ZenWidget("ul", {"class": "sidebar-menu"}) self.menu_items = [] def update_user_info(self, user_info): self.user_info.merge(user_info) def _compose_user_panel(self): userpanel = ZenWidget("div", {"class": "user-panel"}) userimagediv = ZenWidget("div", {"class": "pull-left image"}) userpanel.append_widget(userimagediv) userimg = Image(self.user_info["src"], self.user_info["css_classes"], self.user_info["alt"]) userimagediv.append_widget(userimg) usernamediv = ZenWidget("div", {"class": "pull-left info"}) p = ZenWidget("p") p.append_text(self.user_info["username"]) userimagediv.append_widget(p) userstatus = Link("#") userstatusicon = Icon("fa fa-circle text-success") userstatusicon.append_text(self.user_info["userstatus"]) userstatus.append_widget(userstatusicon) userimagediv.append_widget(userstatus) userpanel.append_widget(userstatus) return userpanel def append_menuitem(self, item): self.menu_items.append(item) def render(self): if self.user_info: self.section.append_widget(self._compose_user_panel()) if self.menu_items: for i in self.menu_items: self.sidebar_menu.append_widget(i) self.append_widget(self.section) self.section.append_widget(self.sidebar_menu) return super(self.__class__, self).render()
def _compose_user_panel(self): userpanel = ZenWidget("div", {"class": "user-panel"}) userimagediv = ZenWidget("div", {"class": "pull-left image"}) userpanel.append_widget(userimagediv) userimg = Image(self.user_info["src"], self.user_info["css_classes"], self.user_info["alt"]) userimagediv.append_widget(userimg) usernamediv = ZenWidget("div", {"class": "pull-left info"}) p = ZenWidget("p") p.append_text(self.user_info["username"]) userimagediv.append_widget(p) userstatus = Link("#") userstatusicon = Icon("fa fa-circle text-success") userstatusicon.append_text(self.user_info["userstatus"]) userstatus.append_widget(userstatusicon) userimagediv.append_widget(userstatus) userpanel.append_widget(userstatus) return userpanel