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


Python AttributeDict.get方法代碼示例

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


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

示例1: render

# 需要導入模塊: from django_tables2.utils import AttributeDict [as 別名]
# 或者: from django_tables2.utils.AttributeDict import get [as 別名]
    def render(self, record, value):
        storage = getattr(value, 'storage', None)
        exists = None
        url = None
        if storage:
            # we'll assume value is a `django.db.models.fields.files.FieldFile`
            if self.verify_exists:
                exists = storage.exists(value.name)
            url = storage.url(value.name)

        else:
            if self.verify_exists and hasattr(value, 'name'):
                # ignore negatives, perhaps the file has a name but it doesn't
                # represent a local path... better to stay neutral than give a
                # false negative.
                exists = os.path.exists(value.name) or exists

        tag = 'a' if url else 'span'
        attrs = AttributeDict(self.attrs.get(tag, {}))
        attrs['title'] = value.name

        classes = [c for c in attrs.get('class', '').split(' ') if c]
        if exists is not None:
            classes.append('exists' if exists else 'missing')
        attrs['class'] = ' '.join(classes)

        if url:
            return self.render_link(url, record=record, value=value, attrs=attrs)
        else:
            return format_html(
                '<span {attrs}>{text}</span>',
                attrs=attrs.as_html(),
                text=self.text_value(record, value)
            )
開發者ID:Debetux,項目名稱:django-tables2,代碼行數:36,代碼來源:filecolumn.py

示例2: render

# 需要導入模塊: from django_tables2.utils import AttributeDict [as 別名]
# 或者: from django_tables2.utils.AttributeDict import get [as 別名]
    def render(self, record, value):
        attrs = AttributeDict(self.attrs.get("span", {}))
        classes = [c for c in attrs.get("class", "").split(" ") if c]

        exists = None
        storage = getattr(value, "storage", None)
        if storage:
            # we'll assume value is a `django.db.models.fields.files.FieldFile`
            if self.verify_exists:
                exists = storage.exists(value.name)
        else:
            if self.verify_exists and hasattr(value, "name"):
                # ignore negatives, perhaps the file has a name but it doesn't
                # represent a local path... better to stay neutral than give a
                # false negative.
                exists = os.path.exists(value.name) or exists

        if exists is not None:
            classes.append("exists" if exists else "missing")

        attrs["title"] = value.name
        attrs["class"] = " ".join(classes)

        return format_html(
            "<span {attrs}>{text}</span>",
            attrs=attrs.as_html(),
            text=self.text_value(record, value),
        )
開發者ID:bradleyayers,項目名稱:django-tables2,代碼行數:30,代碼來源:filecolumn.py

示例3: render

# 需要導入模塊: from django_tables2.utils import AttributeDict [as 別名]
# 或者: from django_tables2.utils.AttributeDict import get [as 別名]
    def render(self, value):
        storage = getattr(value, "storage", None)
        exists = None
        url = None
        if storage:
            # we'll assume value is a `django.db.models.fields.files.FieldFile`
            if self.verify_exists:
                exists = storage.exists(value.name)
            url = storage.url(value.name)

        else:
            if self.verify_exists and hasattr(value, "name"):
                # ignore negatives, perhaps the file has a name but it doesn't
                # represent a local path... better to stay neutral than give a
                # false negative.
                exists = os.path.exists(value.name) or exists

        tag = 'a' if url else 'span'
        attrs = AttributeDict(self.attrs.get(tag, {}))
        attrs['title'] = value.name
        if url:
            attrs['href'] = url

        # add "exists" or "missing" to the class list
        classes = [c for c in attrs.get('class', '').split(' ') if c]
        if exists is True:
            classes.append("exists")
        elif exists is False:
            classes.append("missing")
        attrs['class'] = " ".join(classes)

        html = '<{tag} {attrs}>{text}</{tag}>'.format(
            tag=tag,
            attrs=attrs.as_html(),
            text=os.path.basename(value.name))
        return mark_safe(html)
開發者ID:PGower,項目名稱:django-tables2,代碼行數:38,代碼來源:filecolumn.py


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