# Path: yubiadmin/util/app.py
# class App(object):
#     sections = []
#     priority = 50
# 
#     @property
#     def name(self):
#         self.__class__.name = sys.modules[self.__module__].__file__ \
#             .split('/')[-1].rsplit('.', 1)[0]
#         return self.name
# 
#     def __call__(self, request):
#         section_name = request.path_info_pop()
# 
#         if not section_name:
#             return self.redirect('/%s/%s' % (self.name, self.sections[0]))
# 
#         if not hasattr(self, section_name):
#             raise exc.HTTPNotFound
# 
#         sections = [{
#             'name': section,
#             'title': (getattr(self, section).__doc__ or section.capitalize()
#                       ).strip(),
#             'active': section == section_name,
#             'advanced': bool(getattr(getattr(self, section), 'advanced',
#                                      False))
#         } for section in self.sections]
# 
#         request.environ['yubiadmin.response'].extend('content', render(
#             'app_base',
#             name=self.name,
#             sections=sections,
#             title='YubiAdmin - %s - %s' % (self.name, section_name)
#         ))
# 
#         resp = getattr(self, section_name)(request)
#         if isinstance(resp, Response):
#             return resp
#         request.environ['yubiadmin.response'].extend('page', resp)
# 
#     def redirect(self, url):
#         raise exc.HTTPSeeOther(location=url)
# 
#     def render_forms(self, request, forms, template='form',
#                      success_msg='Settings updated!', **kwargs):
#         alerts = []
#         if not request.params:
#             for form in filter(lambda x: hasattr(x, 'load'), forms):
#                 form.load()
#         else:
#             errors = False
#             for form in forms:
#                 form.process(request.params)
#                 errors = not form.validate() or errors
#             if not errors:
#                 try:
#                     if success_msg:
#                         alerts = [{'type': 'success', 'title': success_msg}]
#                     for form in filter(lambda x: hasattr(x, 'save'), forms):
#                         form.save()
#                 except Exception as e:
#                     alerts = [{'type': 'error', 'title': 'Error:',
#                                'message': str(e)}]
#             else:
#                 alerts = [{'type': 'error', 'title': 'Invalid data!'}]
# 
#         return render(template, target=request.path, fieldsets=forms,
#                       alerts=alerts, **kwargs)
# 
# def render(tmpl, **kwargs):
#     return TemplateBinding(tmpl, **kwargs)


from yubiadmin.util.app import App, render
        from yubiadmin.apps import apps
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.


__all__ = [
    'app',
    'panel'
]


def panel(title, content, link=None, level=None):
    return {
        'title': title,
        'content': content,
        'link': link,
        'level': level
    }


class DashboardApp(App):
    hidden = True

    def __call__(self, request):
        panels = [panel for app in apps if not getattr(app, 'disabled', False)
                  and hasattr(app, 'dash_panels') for panel in app.dash_panels]
        request.environ['yubiadmin.response'].extend('content',

# Path: yubiadmin/util/app.py
# class App(object):
#     sections = []
#     priority = 50
# 
#     @property
#     def name(self):
#         self.__class__.name = sys.modules[self.__module__].__file__ \
#             .split('/')[-1].rsplit('.', 1)[0]
#         return self.name
# 
#     def __call__(self, request):
#         section_name = request.path_info_pop()
# 
#         if not section_name:
#             return self.redirect('/%s/%s' % (self.name, self.sections[0]))
# 
#         if not hasattr(self, section_name):
#             raise exc.HTTPNotFound
# 
#         sections = [{
#             'name': section,
#             'title': (getattr(self, section).__doc__ or section.capitalize()
#                       ).strip(),
#             'active': section == section_name,
#             'advanced': bool(getattr(getattr(self, section), 'advanced',
#                                      False))
#         } for section in self.sections]
# 
#         request.environ['yubiadmin.response'].extend('content', render(
#             'app_base',
#             name=self.name,
#             sections=sections,
#             title='YubiAdmin - %s - %s' % (self.name, section_name)
#         ))
# 
#         resp = getattr(self, section_name)(request)
#         if isinstance(resp, Response):
#             return resp
#         request.environ['yubiadmin.response'].extend('page', resp)
# 
#     def redirect(self, url):
#         raise exc.HTTPSeeOther(location=url)
# 
#     def render_forms(self, request, forms, template='form',
#                      success_msg='Settings updated!', **kwargs):
#         alerts = []
#         if not request.params:
#             for form in filter(lambda x: hasattr(x, 'load'), forms):
#                 form.load()
#         else:
#             errors = False
#             for form in forms:
#                 form.process(request.params)
#                 errors = not form.validate() or errors
#             if not errors:
#                 try:
#                     if success_msg:
#                         alerts = [{'type': 'success', 'title': success_msg}]
#                     for form in filter(lambda x: hasattr(x, 'save'), forms):
#                         form.save()
#                 except Exception as e:
#                     alerts = [{'type': 'error', 'title': 'Error:',
#                                'message': str(e)}]
#             else:
#                 alerts = [{'type': 'error', 'title': 'Invalid data!'}]
# 
#         return render(template, target=request.path, fieldsets=forms,
#                       alerts=alerts, **kwargs)
# 
# def render(tmpl, **kwargs):
#     return TemplateBinding(tmpl, **kwargs)


# Path: yubiadmin/apps/dashboard.py
from yubiadmin.util.app import App, render
        from yubiadmin.apps import apps

# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.


__all__ = [
    'app',
    'panel'
]


def panel(title, content, link=None, level=None):
    return {
        'title': title,
        'content': content,
        'link': link,
        'level': level
    }


class DashboardApp(App):
    hidden = True

    def __call__(self, request):
        panels = [panel for app in apps if not getattr(app, 'disabled', False)
                  and hasattr(app, 'dash_panels') for panel in app.dash_panels]
        request.environ['yubiadmin.response'].extend('content',

                                                     render('dashboard',