コード例 #1
0
    def _render_sidebar(sidebar: admin.SideBar) -> htmler.Aside:
        """Render admin's sidebar
        """
        aside = htmler.Aside(css='main-sidebar')
        sidebar_section_em = htmler.Section(css='sidebar')
        aside.append_child(sidebar_section_em)

        root_menu_ul = htmler.Ul(css='sidebar-menu')
        sidebar_section_em.append_child(root_menu_ul)

        sections, menus = sidebar.items

        # Do actual rendering
        for section in sections:
            li = htmler.Li(lang.t(section['title']),
                           css='header',
                           data_section_weight=section['weight'])
            root_menu_ul.append_child(li)

            # Building top level menu item
            for menu in menus[section['sid']]:
                # Link
                a = htmler.A(
                    href=router.url(menu['path'], lang=lang.get_current()))

                # Icon
                if menu['icon']:
                    a.append_child(htmler.I(css=menu['icon']))

                # Title
                a.append_child(htmler.Span(lang.t(menu['title'])))

                # Label
                if menu['label']:
                    label_class = 'label pull-right label-' + menu[
                        'label_class']
                    a.append_child(
                        htmler.Span(lang.t(menu['label']), css=label_class))

                # List element
                li = htmler.Li(data_menu_weight=menu['weight'])

                # Active state
                if menu['active']:
                    li.set_attr('css', 'active')

                li.append_child(a)
                root_menu_ul.append_child(li)

        return aside
コード例 #2
0
ファイル: _browser.py プロジェクト: pytsite/plugin-odm_ui
    def render(self) -> str:
        # 'Create' toolbar button
        if self._model_class.odm_ui_creation_allowed(
        ) and odm_auth.check_model_permissions(self._model, PERM_CREATE):
            create_form_url = router.rule_url(
                self._m_form_rule, {
                    'model': self._model,
                    'eid': 0,
                    '__redirect': router.current_url(),
                })
            title = lang.t('odm_ui@create')
            btn = htmler.A(href=create_form_url,
                           css='btn btn-default btn-light add-button',
                           title=title)
            btn.append_child(htmler.I(css='fa fas fa-fw fa-plus'))
            self._widget.toolbar.append_child(btn)
            self._widget.toolbar.append_child(htmler.Span(' '))

        # 'Delete' toolbar button
        if self._model_class.odm_ui_deletion_allowed():
            delete_form_url = router.rule_url(self._d_form_rule,
                                              {'model': self._model})
            title = lang.t('odm_ui@delete_selected')
            btn = htmler.A(
                href=delete_form_url,
                css='hidden btn btn-danger mass-action-button sr-only',
                title=title)
            btn.append_child(htmler.I(css='fa fas fa-fw fa-remove fa-times'))
            self._widget.toolbar.append_child(btn)
            self._widget.toolbar.append_child(htmler.Span(' '))

        # Additional toolbar buttons
        for btn_data in self._model_class.odm_ui_browser_mass_action_buttons():
            ep = btn_data.get('ep')
            url = router.rule_url(ep) if ep else '#'
            css = 'btn btn-{} mass-action-button'.format(
                btn_data.get('color', 'default btn-light'))
            icon = 'fa fas fa-fw fa-' + btn_data.get('icon', 'question')
            button = htmler.A(href=url, css=css, title=btn_data.get('title'))
            if icon:
                button.append_child(htmler.I(css=icon))
            self._widget.toolbar.append_child(button)
            self._widget.toolbar.append_child(htmler.Span(' '))

        frm = htmler.Form(self._widget.render(),
                          action='#',
                          method='post',
                          css='table-responsive odm-ui-browser')

        return frm.render()
コード例 #3
0
    def _get_role_row(role: auth.AbstractRole) -> dict:

        perms = []
        for perm_name in role.permissions:
            # If permission was renamed or deleted (sometimes it happens), juts ignore it
            if not permissions.is_permission_defined(perm_name):
                continue

            perm = permissions.get_permission(perm_name)
            css = 'label label-default permission-' + perm[0]
            if perm[0] == 'admin':
                css += ' label-danger'
            perms.append(str(htmler.Span(lang.t(perm[1]), css=css)))

        role_desc = role.description
        try:
            role_desc = lang.t(role_desc)
        except lang.error.Error:
            pass

        m_url = router.rule_url(
            'auth_admin@form_role_modify', {
                'uid': role.uid,
                '__redirect': router.rule_url('auth_admin@browse_roles')
            })
        actions = '<a href="{}" class="btn btn-default btn-light btn-sm">' \
                  '<i class="fa fas fa-edit"></i></a>'.format(m_url)
        d_url = router.rule_url(
            'auth_admin@form_role_delete', {
                'eids': role.uid,
                '__redirect': router.rule_url('auth_admin@browse_roles')
            })
        if role.name not in ('dev', 'admin', 'user', 'anonymous'):
            actions += '&nbsp;<a href="{}" class="btn btn-danger btn-sm">' \
                       '<i class="fa fas fa-remove fa-times"></i></a>'.format(d_url)

        return {
            'name': role.name,
            'description': role_desc,
            'permissions': ' '.join(perms),
            '_actions': '<div class="entity-actions">{}</div>'.format(actions),
        }
コード例 #4
0
ファイル: _model.py プロジェクト: pytsite/plugin-content
    def odm_ui_browser_row(self) -> dict:
        """Hook
        """
        r = {}

        # Title
        if self.has_field('title'):
            r['title'] = (str(htmler.A(self.title, href=self.url)) if self.url else self.title)

        # Status
        if self.has_field('status'):
            status = self.status
            status_str = self.t('content_status_{}_{}'.format(self.model, status))
            label_css = badge_css = 'primary'
            if status == CONTENT_STATUS_WAITING:
                label_css = badge_css = 'warning'
            elif status == CONTENT_STATUS_UNPUBLISHED:
                label_css = 'default'
                badge_css = 'secondary'
            status = str(htmler.Span(status_str, css='label label-{} badge badge-{}'.format(label_css, badge_css)))
            r['status'] = status

        # Images
        if self.has_field('images'):
            label_css = 'default' if not len(self.images) else 'primary'
            badge_css = 'secondary' if not len(self.images) else 'primary'
            images_count = '<span class="label label-{} badge badge-{}">{}</span>'. \
                format(label_css, badge_css, len(self.images))
            r['images'] = images_count

        # Author
        if self.has_field('author') and self.odm_auth_check_model_permissions(self.model, PERM_MODIFY):
            r['author'] = self.author.first_last_name if self.author else '&nbsp;'

        # Publish time
        if self.has_field('publish_time'):
            r['publish_time'] = self.f_get('publish_time', fmt='%d.%m.%Y %H:%M')

        return r
コード例 #5
0
    def _get_user_row(user: auth.AbstractUser) -> dict:
        yes = lang.t('auth_admin@word_yes')

        roles = ''
        for role in sorted(user.roles, key=lambda rl: rl.name):
            css = 'label label-default'
            if role.name in ('admin', 'dev'):
                css += ' label-danger'
            role_desc = role.description
            try:
                role_desc = lang.t(role_desc)
            except lang.error.Error:
                pass
            roles += str(htmler.Span(role_desc, css=css)) + ' '

        status = user.status
        if status == auth.USER_STATUS_ACTIVE:
            status_css = 'info'
        elif status == auth.USER_STATUS_WAITING:
            status_css = 'warning'
        else:
            status_css = 'default'
        status_word = lang.t('auth@status_' + user.status)
        status = '<span class="label label-{}">{}</span>'.format(
            status_css, status_word)

        is_online = '<span class="label label-success">{}</span>'.format(yes) \
            if (user.last_activity and ((datetime.now() - user.last_activity).seconds < 180)) else ''

        m_url = router.rule_url(
            'auth_admin@form_user_modify', {
                'uid': user.uid,
                '__redirect': router.rule_url('auth_admin@browse_users')
            })
        actions = '<a href="{}" class="btn btn-default btn-light btn-sm">' \
                  '<i class="fa fas fa-edit"></i></a>'.format(m_url)
        if user != auth.get_current_user():
            d_url = router.rule_url(
                'auth_admin@form_user_delete', {
                    'eids': user.uid,
                    '__redirect': router.rule_url('auth_admin@browse_users')
                })
            actions += '&nbsp;<a href="{}" class="btn btn-danger btn-sm">' \
                       '<i class="fa fas fa-remove fa-times"></i></a>'.format(d_url)

        return {
            'login':
            user.login,
            'first_last_name':
            user.first_last_name,
            'roles':
            roles,
            'status':
            status,
            'is_public':
            '<span class="label label-info">{}</span>'.format(yes)
            if user.is_public else '',
            'is_online':
            is_online,
            'created':
            lang.pretty_date_time(user.created),
            'last_activity':
            lang.pretty_date_time(user.last_activity)
            if user.last_activity else '',
            '_actions':
            '<div class="entity-actions">{}</div>'.format(actions),
        }