(obj, cache=None)
return doc_info
Return DocInfo objects for SQL models
Return DocInfo objects for SQL models
Return DocInfo objects for SQL models
def get_doc_info_sql(obj, cache=None):
    """
    Return DocInfo objects for SQL models
    """
    class_name = obj.__class__.__name__
    cache_key = '%s-%s' % (class_name, obj.pk)
    if cache and cache_key in cache:
        return cache[cache_key]

    from corehq.apps.locations.models import SQLLocation
    from corehq.form_processor.models import CommCareCaseSQL
    if isinstance(obj, SQLLocation):
        from corehq.apps.locations.views import EditLocationView
        doc_info = DocInfo(
            id=obj.location_id,
            type="Location",
            type_display=_('Location'),
            display=obj.name,
            link=reverse(
                EditLocationView.urlname,
                args=[obj.domain, obj.location_id],
            ),
            is_deleted=False,
        )
    elif isinstance(obj, CommCareCaseSQL):
        doc_info = case_docinfo(obj.domain, obj.case_id, obj.name, obj.is_deleted)
    elif isinstance(obj, XFormInstanceSQL):
        doc_info = form_docinfo(obj.domain, obj.form_id, obj.is_deleted)
    else:
        doc_info = DocInfo(
            is_deleted=False,
        )

    doc_info.id = doc_info.id or str(obj.pk)
    doc_info.domain = obj.domain if hasattr(obj, 'domain') else None
    doc_info.type = doc_info.type or class_name

    if cache:
        cache[cache_key] = doc_info

    return doc_info
def get_doc_info_sql ( obj , cache = None ) : class_name = obj . __class__ . __name__ cache_key = '%s-%s' % ( class_name , obj . pk ) if cache and cache_key in cache : return cache [ cache_key ] from corehq . apps . locations . models import SQLLocation from corehq . form_processor . models import CommCareCaseSQL if isinstance ( obj , SQLLocation ) : from corehq . apps . locations . views import EditLocationView doc_info = DocInfo ( id = obj . location_id , type = "Location" , type_display = _ ( 'Location' ) , display = obj . name , link = reverse ( EditLocationView . urlname , args = [ obj . domain , obj . location_id ] , ) , is_deleted = False , ) elif isinstance ( obj , CommCareCaseSQL ) : doc_info = case_docinfo ( obj . domain , obj . case_id , obj . name , obj . is_deleted ) elif isinstance ( obj , XFormInstanceSQL ) : doc_info = form_docinfo ( obj . domain , obj . form_id , obj . is_deleted ) else : doc_info = DocInfo ( is_deleted = False , ) doc_info . id = doc_info . id or str ( obj . pk ) doc_info . domain = obj . domain if hasattr ( obj , 'domain' ) else None doc_info . type = doc_info . type or class_name if cache : cache [ cache_key ] = doc_info return doc_info