Ejemplo n.º 1
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)
Ejemplo n.º 2
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)