예제 #1
0
def audited_views(request, *args, **kwargs):
    db = AccessAudit.get_db()
    views = db.view('auditcare/urlpath_by_user_date', reduce=False).all()
    template = "auditcare/audit_views.html"
    return render_to_response(template,
            {"audit_views": views},
        context_instance=RequestContext(request))
예제 #2
0
파일: views.py 프로젝트: dimagi/auditcare
def audited_views(request, *args, **kwargs):
    db = AccessAudit.get_db()
    views = db.view('auditcare/urlpath_by_user_date', reduce=False).all()
    template = "auditcare/audit_views.html"
    return render_to_response(template,
            {"audit_views": views},
        context_instance=RequestContext(request))
예제 #3
0
def single_model_history(request, model_name, *args, **kwargs):
    # it's for a particular model
    context=RequestContext(request)
    db = AccessAudit.get_db()
    vals = db.view('auditcare/model_actions_by_id', group=True, startkey=[model_name,u''], endkey=[model_name,u'z']).all()
    model_dict= dict((x['key'][1], x['value']) for x in vals)
    context['instances_dict']=model_dict
    context['model'] = model_name
    return render_to_response('auditcare/single_model_changes.html', context)
예제 #4
0
파일: views.py 프로젝트: dimagi/auditcare
def single_model_history(request, model_name, *args, **kwargs):
    # it's for a particular model
    context=RequestContext(request)
    db = AccessAudit.get_db()
    vals = db.view('auditcare/model_actions_by_id', group=True, startkey=[model_name,u''], endkey=[model_name,u'z']).all()
    model_dict= dict((x['key'][1], x['value']) for x in vals)
    context['instances_dict']=model_dict
    context['model'] = model_name
    return render_to_response('auditcare/single_model_changes.html', context)
예제 #5
0
def model_histories(request, *args, **kwargs):
    """
    Looks at all the audit model histories and shows for a given model
    """
    db = AccessAudit.get_db()
    vals = db.view('auditcare/model_actions_by_id', group=True, group_level=1).all()
    # do a dict comprehension here because we know all the keys in this reduce are unique
    model_dict = dict((x['value'][0], x['value']) for x in vals)
    context = {'model_dict': model_dict}
    return render(request, 'auditcare/model_changes.html', context)
예제 #6
0
def model_instance_history(request, model_name, model_uuid, *args, **kwargs):
    # it's for a particular model
    context=RequestContext(request)
    db = AccessAudit.get_db()

    if ContentType.objects.filter(name=model_name).count() == 0:
        # it's couchdbkit
        obj = db.get(model_uuid)
    else:
        obj = ContentType.objects.filter(name=model_name)[0].model_class().objects.get(id=model_uuid)

    context['change_history'] = history_for_doc(obj)
    context['model'] = model_name
    context['model_uuid'] = model_uuid
    return render_to_response('auditcare/model_instance_history.html', context)
예제 #7
0
파일: views.py 프로젝트: dimagi/auditcare
def model_instance_history(request, model_name, model_uuid, *args, **kwargs):
    # it's for a particular model
    context=RequestContext(request)
    db = AccessAudit.get_db()

    if ContentType.objects.filter(name=model_name).count() == 0:
        # it's couchdbkit
        obj = db.get(model_uuid)
    else:
        obj = ContentType.objects.filter(name=model_name)[0].model_class().objects.get(id=model_uuid)

    context['change_history'] = history_for_doc(obj)
    context['model'] = model_name
    context['model_uuid'] = model_uuid
    return render_to_response('auditcare/model_instance_history.html', context)
예제 #8
0
def model_instance_history(request, model_name, model_uuid, *args, **kwargs):
    #it's for a particular model
    context=RequestContext(request)
    db = AccessAudit.get_db()
    changes=db.view('auditcare/model_actions_by_id', reduce=False, key=[model_name, model_uuid], include_docs=True).all()
    #context['changes']= sorted([(x['doc']['_id'], x['doc']) for x in changes], key=lambda y: y[1]['event_date'], reverse=True)

    if ContentType.objects.filter(name=model_name).count() == 0:
        #it's couchdbkit
        obj = db.get(model_uuid)
    else:
        obj = ContentType.objects.filter(name=model_name)[0].model_class().objects.get(id=model_uuid)

    context['change_history'] = history_for_doc(obj)
    context['model'] = model_name
    context['model_uuid'] = model_uuid
    return render_to_response('auditcare/model_instance_history.html', context)
예제 #9
0
    def handle(self, **options):
        recompute = options['recompute']
        print recompute
        db = AccessAudit.get_db()
        vals = db.view('auditcare/model_actions_by_id',
                       group=True,
                       group_level=1).all()

        #get all model types
        #python 2.7 dict comprehension
        #model_dict= {x['key'][0]: x['value'] for x in vals}
        model_dict = dict((x['key'][0], x['value']) for x in vals)

        for model, count in model_dict.items():
            #for each model type, query ALL audit instances.
            print "### %s" % (model)
            model_counts = db.view('auditcare/model_actions_by_id',
                                   group=True,
                                   startkey=[model, u''],
                                   endkey=[model, u'z']).all()
            #within a given model, query ALL instances

            #sort the models by id, then by rev descending
            #{u'value': <num>, u'key': [u'model', u'uuid']}
            for mc in model_counts:
                num = mc['value']
                model_uuid = mc['key'][1]
                #now for each model uuid, do a query again to get all the rev numbers
                item_revs = db.view('auditcare/model_actions_by_id',
                                    reduce=False,
                                    startkey=[model, model_uuid],
                                    endkey=[model, model_uuid]).all()
                revs = sorted([(x['id'], x['value']) for x in item_revs],
                              key=lambda y: y[1],
                              reverse=True)
                #tuples of (audit_id, rev_id)
                #print "%s:%s -> %s" % (model, model_uuid, revs)

                #ok, for each arr of revs, if it's length greater than 1, then do it
                #we're going backwards, so...yeah
                if len(revs) > 1:
                    for i, t in enumerate(revs):
                        audit_id = t[0]
                        current = ModelActionAudit.get(audit_id)

                        if i + 1 == len(revs):
                            current.prev_id = None
                            current.save()
                            break

                        prev_audit_id = revs[i + 1][0]
                        prev_rev = ModelActionAudit.get(prev_audit_id)

                        if i == 0:
                            current.next_id = None

                        if current.prev_id != prev_rev._id:
                            current.prev_id = prev_rev._id
                            #current saves later
                        if prev_rev.next_id != current._id:
                            prev_rev.next_id = current._id
                            prev_rev.save()

#                        #sanity check
#                        if prev_rev.revision_checksum == current.revision_checksum:
#                            continue
#
#                        if (current.archived_data.get('doc_type', None) =='XFormInstance' and prev_rev.archived_data.get('doc_type', None) == 'XFormInstance'):
#                            #it's an xforminstance
#                            removed, added, changed = utils.dict_diff(current.archived_data['form'], prev_rev.archived_data['form'])
#                        else:
#                            removed, added, changed = utils.dict_diff(current.archived_data, prev_rev.archived_data)
#                        current.removed = removed
#                        current.added = added
#                        current.changed = changed
#                        current.save()
                        current.compute_changes(save=True)
예제 #10
0
def audited_views(request, *args, **kwargs):
    db = AccessAudit.get_db()
    views = db.view('auditcare/urlpath_by_user_date', reduce=False).all()
    template = "auditcare/audit_views.html"
    context = {"audit_views": views}
    return render(request, template, context)
예제 #11
0
    def handle(self, **options):
        recompute = options['recompute']
        print recompute
        db = AccessAudit.get_db()
        vals = db.view('auditcare/model_actions_by_id', group=True, group_level=1).all()

        #get all model types
        #python 2.7 dict comprehension
        #model_dict= {x['key'][0]: x['value'] for x in vals}
        model_dict= dict((x['key'][0], x['value']) for x in vals)

        for model, count in model_dict.items():
            #for each model type, query ALL audit instances.
            print "### %s" % (model)
            model_counts = db.view('auditcare/model_actions_by_id', group=True, startkey=[model,u''], endkey=[model,u'z']).all()
            #within a given model, query ALL instances

            #sort the models by id, then by rev descending
            #{u'value': <num>, u'key': [u'model', u'uuid']}
            for mc in model_counts:
                num = mc['value']
                model_uuid = mc['key'][1]
                #now for each model uuid, do a query again to get all the rev numbers
                item_revs = db.view('auditcare/model_actions_by_id', reduce=False, startkey=[model,model_uuid], endkey=[model,model_uuid]).all()
                revs = sorted([(x['id'], x['value']) for x in item_revs], key=lambda y: y[1], reverse=True)
                #tuples of (audit_id, rev_id)
                #print "%s:%s -> %s" % (model, model_uuid, revs)


                #ok, for each arr of revs, if it's length greater than 1, then do it
                #we're going backwards, so...yeah
                if len(revs) > 1:
                    for i, t in enumerate(revs):
                        audit_id = t[0]
                        current = ModelActionAudit.get(audit_id)

                        if i+1 == len(revs):
                            current.prev_id = None
                            current.save()
                            break

                        prev_audit_id = revs[i+1][0]
                        prev_rev = ModelActionAudit.get(prev_audit_id)

                        if i == 0:
                            current.next_id = None

                        if current.prev_id != prev_rev._id:
                            current.prev_id = prev_rev._id
                            #current saves later
                        if prev_rev.next_id != current._id:
                            prev_rev.next_id = current._id
                            prev_rev.save()

#                        #sanity check
#                        if prev_rev.revision_checksum == current.revision_checksum:
#                            continue
#
#                        if (current.archived_data.get('doc_type', None) =='XFormInstance' and prev_rev.archived_data.get('doc_type', None) == 'XFormInstance'):
#                            #it's an xforminstance
#                            removed, added, changed = utils.dict_diff(current.archived_data['form'], prev_rev.archived_data['form'])
#                        else:
#                            removed, added, changed = utils.dict_diff(current.archived_data, prev_rev.archived_data)
#                        current.removed = removed
#                        current.added = added
#                        current.changed = changed
#                        current.save()
                        current.compute_changes(save=True)
예제 #12
0
def audited_views(request, *args, **kwargs):
    db = AccessAudit.get_db()
    views = db.view('auditcare/urlpath_by_user_date', reduce=False).all()
    template = "auditcare/audit_views.html"
    context = {"audit_views": views}
    return render(request, template, context)