예제 #1
0
def admin_log() -> str:
    form = LogForm()
    form.user.choices = [(0, _('all'))] + UserMapper.get_users()
    table = Table(['date', 'priority', 'type', 'message', 'user', 'info'], order='[[0, "desc"]]')
    logs = logger.get_system_logs(form.limit.data, form.priority.data, form.user.data)
    for row in logs:
        user = UserMapper.get_by_id(row.user_id) if row.user_id else None
        table.rows.append([format_datetime(row.created),
                           str(row.priority) + ' ' + app.config['LOG_LEVELS'][row.priority],
                           row.type,
                           row.message,
                           link(user) if user and user.id else row.user_id,
                           row.info.replace('\n', '<br />')])
    return render_template('admin/log.html', table=table, form=form)
예제 #2
0
def user_activity(user_id=0):
    form = ActivityForm()
    form.user.choices = [(0, _('all'))] + UserMapper.get_users()
    table = {'id': 'activity', 'header': ['date', 'user', 'action', 'entity'], 'data': []}
    if form.validate_on_submit():
        activities = UserMapper.get_activities(form.limit.data, form.user.data, form.action.data)
    elif user_id:
        form.user.data = user_id
        activities = UserMapper.get_activities(100, user_id, 'all')
    else:
        activities = UserMapper.get_activities(100, 0, 'all')
    for row in activities:
        entity = EntityMapper.get_by_id(row.entity_id, True)
        user = UserMapper.get_by_id(row.user_id)
        table['data'].append([
            format_date(row.created),
            link(user) if user else 'id ' + str(row.user_id),
            _(row.action),
            link(entity) if entity else 'id ' + str(row.entity_id)])
    return render_template('user/activity.html', table=table, form=form)
예제 #3
0
def user_activity(user_id: Optional[int] = 0) -> str:
    form = ActivityForm()
    form.user.choices = [(0, _('all'))] + UserMapper.get_users()
    if form.validate_on_submit():
        activities = UserMapper.get_activities(form.limit.data, form.user.data,
                                               form.action.data)
    elif user_id:
        form.user.data = user_id
        activities = UserMapper.get_activities(100, user_id, 'all')
    else:
        activities = UserMapper.get_activities(100, 0, 'all')
    table = Table(['date', 'user', 'action', 'entity'])
    for row in activities:
        entity = EntityMapper.get_by_id(row.entity_id, ignore_not_found=True)
        user = UserMapper.get_by_id(row.user_id)
        table.rows.append([
            format_date(row.created),
            link(user) if user else 'id ' + str(row.user_id),
            _(row.action),
            link(entity) if entity else 'id ' + str(row.entity_id)
        ])
    return render_template('user/activity.html', table=table, form=form)