當前位置: 首頁>>代碼示例>>Python>>正文


Python AccessAudit.get_db方法代碼示例

本文整理匯總了Python中auditcare.models.AccessAudit.get_db方法的典型用法代碼示例。如果您正苦於以下問題:Python AccessAudit.get_db方法的具體用法?Python AccessAudit.get_db怎麽用?Python AccessAudit.get_db使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在auditcare.models.AccessAudit的用法示例。


在下文中一共展示了AccessAudit.get_db方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: audited_views

# 需要導入模塊: from auditcare.models import AccessAudit [as 別名]
# 或者: from auditcare.models.AccessAudit import get_db [as 別名]
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))
開發者ID:dimagi,項目名稱:auditcare,代碼行數:9,代碼來源:views.py

示例2: single_model_history

# 需要導入模塊: from auditcare.models import AccessAudit [as 別名]
# 或者: from auditcare.models.AccessAudit import get_db [as 別名]
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)
開發者ID:dimagi,項目名稱:auditcare,代碼行數:11,代碼來源:views.py

示例3: model_histories

# 需要導入模塊: from auditcare.models import AccessAudit [as 別名]
# 或者: from auditcare.models.AccessAudit import get_db [as 別名]
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)
開發者ID:kkrampa,項目名稱:commcare-hq,代碼行數:12,代碼來源:views.py

示例4: model_instance_history

# 需要導入模塊: from auditcare.models import AccessAudit [as 別名]
# 或者: from auditcare.models.AccessAudit import get_db [as 別名]
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)
開發者ID:dimagi,項目名稱:auditcare,代碼行數:17,代碼來源:views.py

示例5: model_instance_history

# 需要導入模塊: from auditcare.models import AccessAudit [as 別名]
# 或者: from auditcare.models.AccessAudit import get_db [as 別名]
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)
開發者ID:unicefuganda,項目名稱:auditcare,代碼行數:19,代碼來源:views.py

示例6: handle

# 需要導入模塊: from auditcare.models import AccessAudit [as 別名]
# 或者: from auditcare.models.AccessAudit import get_db [as 別名]
    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)
開發者ID:dimagi,項目名稱:auditcare,代碼行數:70,代碼來源:compute_diffs.py

示例7: audited_views

# 需要導入模塊: from auditcare.models import AccessAudit [as 別名]
# 或者: from auditcare.models.AccessAudit import get_db [as 別名]
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)
開發者ID:kkrampa,項目名稱:commcare-hq,代碼行數:8,代碼來源:views.py


注:本文中的auditcare.models.AccessAudit.get_db方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。