Example #1
0
def evt(operation, resource, composed_resource_id, event=None, reference=None):
    try:
        kwargs = {
            'resource': resource,
            'operation': operation,
            'resource_id': find_resource_id(composed_resource_id),
        }
        if not reference:
            if hasattr(request, 'user_id'):
                reference = 'user:'******'client') and hasattr(request, 'namespace'):
                reference = 'space:{}:client:'.format(request.namespace,
                                                      request.client)
            elif hasattr(request, 'namespace'):
                reference = 'space:{}:'.format(request.namespace)
            else:
                reference = 'unknown'
        kwargs['reference'] = reference

        if not event and request.method in ['PATCH', 'POST', 'PUT']:
            event = request.json
        if 'password' in event:
            event['password'] = '******'
        if 'old_password' in event:
            event['old_password'] = '******'
        kwargs['event'] = event

        Audit.create(db.session, **kwargs)
    except Exception as e:
        print(e)
Example #2
0
def new_audit():
    form = NewAuditForm()
    if form.validate_on_submit():
        this_audit = Audit()
        this_audit.user_id = current_user.id
        this_audit.brand_id = form.brand_id.data
        db.session.add(this_audit)
        db.session.commit()
        return redirect(url_for('audit_report', audit_id=this_audit.id))
    return render_template('audit/add.html', title='Add new audit', form=form)
Example #3
0
def order_item(request, pk):
    item = Item.objects.get(id=pk)
    qs = Audit.objects.filter(item_id=pk,
                              new_owner=request.user,
                              donor_id=item.owner.pk)
    if qs:
        messages.error(request, 'Você já requisitou este Item')
        return redirect('/home')
    else:
        audit = Audit(new_owner=request.user, donor=item.owner, item=item)
        audit.save()
        messages.success(request, 'Uma nova auditoria foi criada')
        return redirect('/audits')
Example #4
0
def accept_notification(request, pk):
    # data = request.GET

    notification = Notification.objects.get(id=pk)
    notification.status = 'ACEITO'
    notification.is_read = True
    notification.save()
    audit = Audit(new_owner=request.user,
                  donor=notification.match.item.owner,
                  item=notification.match.item,
                  match=notification.match)
    audit.save()
    messages.success(request, 'Uma nova auditoria foi criada')
    return redirect('/notifications')
Example #5
0
def writeaudit(parent_id, before, after):
    if before:
        change = "change"
    else:
        change = "add"
    var = Audit(model='keyval',
                parent_id=parent_id,
                a_datetime=datetime.now(),
                a_user_id=current_user.id,
                a_username=load_user(current_user.id).username,
                action=change,
                before=before,
                after=after)

    db.session.add(var)