(doc, domain_hint=None, cache=None)
return doc_info
Return DocInfo objects for Couch doc dicts
Return DocInfo objects for Couch doc dicts
Return DocInfo objects for Couch doc dicts
def get_doc_info_couch(doc, domain_hint=None, cache=None):
    """Return DocInfo objects for Couch doc dicts"""
    domain = doc.get('domain') or domain_hint
    doc_type = doc.get('doc_type')
    doc_id = doc.get('_id')
    generic_delete = doc_type.endswith(DELETED_SUFFIX)

    def has_doc_type(doc_type, expected_doc_type):
        return (doc_type == expected_doc_type
            or doc_type == ('%s%s' % (expected_doc_type, DELETED_SUFFIX)))

    if cache and doc_id in cache:
        return cache[doc_id]

    if (
        has_doc_type(doc_type, 'Application')
        or has_doc_type(doc_type, 'LinkedApplication')
        or has_doc_type(doc_type, 'RemoteApp')
    ):
        if doc.get('copy_of'):
            doc_info = DocInfo(
                display='%s (#%s)' % (doc['name'], doc['version']),
                type_display=_('Application Build'),
                link=reverse(
                    'download_index',
                    args=[domain, doc_id],
                ),
                is_deleted=generic_delete,
            )
        else:
            doc_info = DocInfo(
                display=doc['name'],
                type_display=_('Application'),
                link=reverse(
                    'view_app',
                    args=[domain, doc_id],
                ),
                is_deleted=generic_delete,
            )
    elif has_doc_type(doc_type, 'CommCareCaseGroup'):
        from corehq.apps.data_interfaces.views import CaseGroupCaseManagementView
        doc_info = DocInfo(
            type_display=_('Case Group'),
            display=doc['name'],
            link=reverse(
                CaseGroupCaseManagementView.urlname,
                args=[domain, doc_id],
            ),
            is_deleted=generic_delete,
        )
    elif has_doc_type(doc_type, 'CommCareCase'):
        doc_info = case_docinfo(domain, doc_id, doc['name'], generic_delete)
    elif any([has_doc_type(doc_type, d) for d in XFormInstanceSQL.DOC_TYPE_TO_STATE]):
        doc_info = form_docinfo(domain, doc_id, generic_delete)
    elif doc_type in ('CommCareUser',):
        doc_info = DocInfo(
            display=raw_username(doc['username']),
            type_display=_('Mobile Worker'),
            link=get_commcareuser_url(domain, doc_id),
            is_deleted=doc.get('base_doc', '').endswith(DELETED_SUFFIX),
        )
    elif doc_type in ('WebUser',):
        doc_info = DocInfo(
            type_display=_('Web User'),
            display=doc['username'],
            link=get_webuser_url(domain, doc_id),
            is_deleted=doc.get('base_doc', '').endswith(DELETED_SUFFIX),
        )
    elif has_doc_type(doc_type, 'Group'):
        from corehq.apps.users.views.mobile import EditGroupMembersView
        doc_info = DocInfo(
            type_display=_('Group'),
            display=doc['name'],
            link=reverse(
                EditGroupMembersView.urlname,
                args=[domain, doc_id],
            ),
            is_deleted=generic_delete,
        )
    elif has_doc_type(doc_type, 'Domain'):
        if doc['is_snapshot'] and doc['published']:
            urlname = 'project_info'
        else:
            urlname = 'domain_basic_info'
        doc_info = DocInfo(
            type_display=_('Domain'),
            display=doc['name'],
            link=reverse(
                urlname,
                kwargs={'domain': doc['name']}
            ),
            is_deleted=generic_delete,
        )
    elif has_doc_type(doc_type, 'Location'):
        from corehq.apps.locations.views import EditLocationView
        doc_info = DocInfo(
            type_display=_('Location'),
            display=doc['name'],
            link=reverse(
                EditLocationView.urlname,
                args=[domain, doc_id],
            ),
            is_deleted=generic_delete,
        )
    else:
        doc_info = DocInfo(
            is_deleted=generic_delete,
        )

    doc_info.id = doc_id
    doc_info.domain = domain
    doc_info.type = doc_type

    if cache:
        cache[doc_id] = doc_info

    return doc_info
def get_doc_info_couch ( doc , domain_hint = None , cache = None ) : domain = doc . get ( 'domain' ) or domain_hint doc_type = doc . get ( 'doc_type' ) doc_id = doc . get ( '_id' ) generic_delete = doc_type . endswith ( DELETED_SUFFIX ) def has_doc_type ( doc_type , expected_doc_type ) : return ( doc_type == expected_doc_type or doc_type == ( '%s%s' % ( expected_doc_type , DELETED_SUFFIX ) ) ) if cache and doc_id in cache : return cache [ doc_id ] if ( has_doc_type ( doc_type , 'Application' ) or has_doc_type ( doc_type , 'LinkedApplication' ) or has_doc_type ( doc_type , 'RemoteApp' ) ) : if doc . get ( 'copy_of' ) : doc_info = DocInfo ( display = '%s (#%s)' % ( doc [ 'name' ] , doc [ 'version' ] ) , type_display = _ ( 'Application Build' ) , link = reverse ( 'download_index' , args = [ domain , doc_id ] , ) , is_deleted = generic_delete , ) else : doc_info = DocInfo ( display = doc [ 'name' ] , type_display = _ ( 'Application' ) , link = reverse ( 'view_app' , args = [ domain , doc_id ] , ) , is_deleted = generic_delete , ) elif has_doc_type ( doc_type , 'CommCareCaseGroup' ) : from corehq . apps . data_interfaces . views import CaseGroupCaseManagementView doc_info = DocInfo ( type_display = _ ( 'Case Group' ) , display = doc [ 'name' ] , link = reverse ( CaseGroupCaseManagementView . urlname , args = [ domain , doc_id ] , ) , is_deleted = generic_delete , ) elif has_doc_type ( doc_type , 'CommCareCase' ) : doc_info = case_docinfo ( domain , doc_id , doc [ 'name' ] , generic_delete ) elif any ( [ has_doc_type ( doc_type , d ) for d in XFormInstanceSQL . DOC_TYPE_TO_STATE ] ) : doc_info = form_docinfo ( domain , doc_id , generic_delete ) elif doc_type in ( 'CommCareUser' , ) : doc_info = DocInfo ( display = raw_username ( doc [ 'username' ] ) , type_display = _ ( 'Mobile Worker' ) , link = get_commcareuser_url ( domain , doc_id ) , is_deleted = doc . get ( 'base_doc' , '' ) . endswith ( DELETED_SUFFIX ) , ) elif doc_type in ( 'WebUser' , ) : doc_info = DocInfo ( type_display = _ ( 'Web User' ) , display = doc [ 'username' ] , link = get_webuser_url ( domain , doc_id ) , is_deleted = doc . get ( 'base_doc' , '' ) . endswith ( DELETED_SUFFIX ) , ) elif has_doc_type ( doc_type , 'Group' ) : from corehq . apps . users . views . mobile import EditGroupMembersView doc_info = DocInfo ( type_display = _ ( 'Group' ) , display = doc [ 'name' ] , link = reverse ( EditGroupMembersView . urlname , args = [ domain , doc_id ] , ) , is_deleted = generic_delete , ) elif has_doc_type ( doc_type , 'Domain' ) : if doc [ 'is_snapshot' ] and doc [ 'published' ] : urlname = 'project_info' else : urlname = 'domain_basic_info' doc_info = DocInfo ( type_display = _ ( 'Domain' ) , display = doc [ 'name' ] , link = reverse ( urlname , kwargs = { 'domain' : doc [ 'name' ] } ) , is_deleted = generic_delete , ) elif has_doc_type ( doc_type , 'Location' ) : from corehq . apps . locations . views import EditLocationView doc_info = DocInfo ( type_display = _ ( 'Location' ) , display = doc [ 'name' ] , link = reverse ( EditLocationView . urlname , args = [ domain , doc_id ] , ) , is_deleted = generic_delete , ) else : doc_info = DocInfo ( is_deleted = generic_delete , ) doc_info . id = doc_id doc_info . domain = domain doc_info . type = doc_type if cache : cache [ doc_id ] = doc_info return doc_info