Beispiel #1
0
def activity_panel(db):

    host = zoom.system.request.host

    data = db(
        """
    select
        log.id,
        users.username,
        log.address,
        log.path,
        log.timestamp,
        log.elapsed
    from log left join users on log.user_id = users.id
    where server = %s and path not like "%%\\/\\_%%"
    and log.status = 'C'
    order by timestamp desc
    limit 15
    """, host)

    rows = []
    for rec in data:
        row = [
            link_to(str(rec[0]), '/admin/entry/' + str(rec[0])),
            link_to_user(rec[1]),
            rec[2],
            zoom.link_to(rec[3]),
            how_long_ago(rec[4]),
            rec[4],
            rec[5],
        ]
        rows.append(row)

    labels = 'id', 'user', 'address', 'path', 'when', 'timestamp', 'elapsed'
    return zoom.browse(rows, labels=labels, title=link_to_page('Requests'))
Beispiel #2
0
    def index(self, q='', *args, **kwargs):
        """collection landing page"""

        c = self.collection
        user = c.user

        if c.request.route[-1:] == ['index']:
            return zoom.redirect_to('/'+'/'.join(c.request.route[:-1]), **kwargs)

        actions = user.can('create', c) and ['New'] or []

        if q:
            title = 'Selected ' + c.title
            records = c.search(q)
        else:
            title = c.title
            records = c.store.find(type='U')

        authorized = (i for i in records if user.can('read', i))
        items = sorted(authorized, key=c.order)
        num_items = len(items)

        if num_items != 1:
            footer_name = c.title.lower()
        else:
            footer_name = c.item_title.lower()

        if q:
            footer = '{:,} {} found in search of {:,} {}'.format(
                num_items,
                footer_name,
                len(c.store),
                c.title.lower(),
            )
        else:
            footer = '%s %s' % (len(items), footer_name)

        admin_ids = [item.admin_group_id for item in items]
        admin_lookup = {
            group.group_id: zoom.link_to(group.name, 'groups', group.group_id)
            for group in zoom.system.site.groups
            if group.group_id in admin_ids
        }

        for item in items:
            item.administrators = admin_lookup.get(item.admin_group_id, '')

        content = zoom.browse(
            [c.model(i) for i in items],
            labels=c.get_labels(),
            columns=c.get_columns(),
            footer=footer
        )

        return zoom.page(content, title=title, actions=actions, search=q)
Beispiel #3
0
def get_impersonation_notice():
    username = get_impersonated_username()
    if username is None:
        return ''
    return str(
        zoom.Component(
            h.div(
                'Impersonating {}'.format(username),
                zoom.link_to(
                    'Stop Impersonating',
                    '/stop-impersonation',
                    classed='action'
                ),
                id='impersonation-notice'
            )
        )
    )
Beispiel #4
0
 def index(self):
     def get_title(method):
         code = getsource(method)
         title = method.__doc__.splitlines()[0]
         return title
     thumbnails = []
     for name, method in getmembers(self, predicate=ismethod):
         if not name.startswith('_') and not name in ['index', 'show']:
             link = link_to(get_title(method), name)
             thumbnails.append(method()['visualization'])
     content = ul(div(t, Class='thumbnail') for t in thumbnails)
     return page(
         div(
             div(
                 markdown(toc),
                 Class="col-md-3",
             ) + div(
                 content,
                 Class="col-md-9 thumbnails",
             ),
             Class='row',
         ), css=css)
Beispiel #5
0
    def index(self):
        def get_title(method):
            code = getsource(method)
            title = method.__doc__.splitlines()[0]
            return title

        thumbnails = []
        for name, method in getmembers(self, predicate=ismethod):
            if not name.startswith('_') and not name in ['index', 'show']:
                link = link_to(get_title(method), name)
                thumbnails.append(method()['visualization'])
        content = ul(div(t, Class='thumbnail') for t in thumbnails)
        return page(div(
            div(
                markdown(toc),
                Class="col-md-3",
            ) + div(
                content,
                Class="col-md-9 thumbnails",
            ),
            Class='row',
        ),
                    css=css)
Beispiel #6
0
def log_data(db, status, n, limit, q):
    """retreive log data"""

    host = zoom.system.request.host

    statuses = tuple(status)
    offset = int(n) * int(limit)
    cmd = """
        select
            id,
            status,
            user_id,
            address,
            app,
            path,
            timestamp,
            elapsed
        from log
        where status in %s and server = %s
        order by id desc
        limit {limit}
        offset {offset}
        """.format(limit=int(limit), offset=offset, statuses=statuses)
    data = db(cmd, statuses, host)
    data = [[
        link_to(str(item[0]), '/admin/entry/' + str(item[0])),
        item[1],
        zoom.helpers.who(item[2]),
        item[3],
        item[4],
        zoom.link_to(item[5]),
        how_long_ago(item[6]),
    ] + list(item[6:]) for item in data if q in repr(item)]
    labels = ('id', 'status', 'user', 'address', 'app', 'path', 'when',
              'timestamp', 'elapsed')
    return zoom.browse(data, labels=labels)
Beispiel #7
0
 def fmt(rec):
     entry = (link_to(str(rec[0]), '/admin/entry/' + str(rec[0])), )
     user = (zoom.helpers.who(rec[4]), )
     link = (zoom.link_to(rec[2]), )
     return entry + (rec[1], ) + link + rec[3:4] + user + rec[5:]
Beispiel #8
0
 def toc_guide(name):
     """generate a toc entry for a guide"""
     return link_to(name, id_for(name))
Beispiel #9
0
 def toc_guide(name):
     """generate a toc entry for a guide"""
     return link_to(name, id_for(name))