本文整理汇总了Python中django_tables2.utils.AttributeDict类的典型用法代码示例。如果您正苦于以下问题:Python AttributeDict类的具体用法?Python AttributeDict怎么用?Python AttributeDict使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AttributeDict类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
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)
)
示例2: render
def render(self, value, record, bound_column):
if not self.links:
raise NotImplementedError('Links not assigned.')
if not isinstance(self.links, (list, tuple,dict)):
raise NotImplementedError('Links must be an iterable.')
links = []
for link in self.links:
title = link['title']
url = link['url']
attrs = link['attrs'] if 'attrs' in link else None
if 'args' in link:
args = [a.resolve(record) if isinstance(a, A) else a for a in link['args']]
else:
args = None
attrs = AttributeDict(attrs if attrs is not None else self.attrs.get('a', {}))
try:
attrs['href'] = urlresolvers.reverse(url, args=args)
except urlresolvers.NoReverseMatch:
attrs['href'] = url
links.append('<a {attrs}>{text}</a>'.format(
attrs=attrs.as_html(),
text=mark_safe(title)
))
return mark_safe(self.delimiter.join(links))
示例3: render_attrs
def render_attrs(attrs, **kwargs):
ret = AttributeDict(kwargs)
if attrs is not None:
ret.update(attrs)
return ret.as_html()
示例4: render
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),
)
示例5: header
def header(self):
default = {"type": "checkbox",
"class": "toggle-all",
}
general = self.attrs.get('input')
specific = self.attrs.get('th__input')
attrs = AttributeDict(default, **(specific or general or {}))
return mark_safe('<input %s /> ' % attrs.as_html())
示例6: header
def header(self):
if self.header_check:
default = {'type': 'checkbox'}
general = self.attrs.get('input')
specific = self.attrs.get('th__input')
attrs = AttributeDict(default, **(specific or general or {}))
return mark_safe('<input %s/>' % attrs.as_html())
else:
return super(CheckBoxColumn, self).header
示例7: render
def render(self, value, bound_column, record):
default = {"type": "checkbox", "name": bound_column.name, "value": value}
if self.is_checked(value, record):
default.update({"checked": "checked"})
general = self.attrs.get("input")
specific = self.attrs.get("td__input")
attrs = AttributeDict(default, **(specific or general or {}))
return mark_safe("<input %s/>" % attrs.as_html())
示例8: render
def render(self, value, bound_column): # pylint: disable=W0221
default = {
'type': 'text',
'name': bound_column.name,
}
general = self.attrs.get('input')
specific = self.attrs.get('td__input')
attrs = AttributeDict(default, **(specific or general or {}))
return mark_safe('<input %s/>' % attrs.as_html())
示例9: render_link
def render_link(self, uri, text, attrs=None):
attrs = AttributeDict(attrs if attrs is not None else
self.attrs.get('a', {}))
attrs['href'] = uri
html = '<a {attrs}>{text}</a>'.format(
attrs=attrs.as_html(),
text=text.encode('utf-8')
)
return mark_safe(html)
示例10: render
def render(self, value, bound_column):
default = {
'type': 'checkbox',
'name': bound_column.name,
'value': value
}
general = self.attrs.get('input')
specific = self.attrs.get('td__input')
attrs = AttributeDict(default, **(specific or general or {}))
return mark_safe('<input %s/>' % attrs.as_html())
示例11: render
def render(self, value, bound_column): # pylint: disable=W0221
default = {
'type': 'checkbox',
'name': bound_column.name,
'value': value
}
general = self.attrs.get('input')
specific = self.attrs.get('td__input')
attrs = AttributeDict(default, **(specific or general or {}))
return mark_safe('<label><input %s/><span class="lbl"></span></label>' % attrs.as_html())
示例12: render_link
def render_link(self, uri, text, attrs=None):
"""
Render a hyperlink.
:param uri: URI for the hyperlink
:param text: value wrapped in ``<a></a>``
:param attrs: ``<a>`` tag attributes
"""
attrs = AttributeDict(attrs if attrs is not None else self.attrs.get("a", {}))
attrs["href"] = uri
html = "<a {attrs}>{text}</a>".format(attrs=attrs.as_html(), text=escape(text))
return mark_safe(html)
示例13: __init__
def __init__(self, id, source=None, params=(), sortable=None,
empty_text=None, attrs=None, template=None, data=None):
"""Initialize the table.
Options that Table supports that affect the data presented are not
supported in this subclass. Extra paramters are:
:param id: The id of the table in the resulting HTML. You just need
to provide something that will be unique in the generated page.
:param source: The URL to get json data from.
:param params: A tuple of arguments to pass to the get_queryset()
method.
:param data: The data to base the table on, if any.
"""
if data is not None:
if source is not None or self.source is not None:
raise AssertionError(
"Do not specify both data and source when building a "
"DataTablesTable")
self.params = params
data_backed_table = True
else:
data_backed_table = False
data = []
if source is not None:
self.source = source
if template is None:
template = 'ajax_table.html'
# Even if this is an ajax backed table, we pass data here and patch
# the queryset in below because of a bootstrapping issue: we want to
# sort the initial queryset, and this is much cleaner if the table has
# has its .columns set up which is only done in Table.__init__...
super(DataTablesTable, self).__init__(
data=data, sortable=sortable, empty_text=empty_text, attrs=attrs,
template=template)
self._full_length = None
if not data_backed_table:
self._compute_queryset(params)
# We are careful about modifying the attrs here -- if it comes from
# class Meta:-type options, we don't want to modify the original
# value!
if self.attrs:
attrs = AttributeDict(self.attrs)
else:
attrs = AttributeDict()
attrs.update({
'id': id,
# Forcing class to display here is a bit specific really.
'class': 'display',
})
self.attrs = attrs
示例14: render
def render(self, value, bound_column, record): # pylint: disable=W0221
default = {
'type': 'checkbox',
'name': bound_column.name,
'value': value
}
if self.is_checked(value, record):
default.update({
'checked': 'checked',
})
general = self.attrs.get('input')
specific = self.attrs.get('td__input')
attrs = AttributeDict(default, **(specific or general or {}))
return mark_safe('<input %s/>' % attrs.as_html())
示例15: render_link
def render_link(self, uri, text, attrs=None):
"""
Render a hyperlink.
:param uri: URI for the hyperlink
:param text: value wrapped in ``<a></a>``
:param attrs: ``<a>`` tag attributes
"""
attrs = AttributeDict(attrs if attrs is not None else
self.attrs.get('a', {}))
attrs['href'] = uri
return format_html('<a {attrs}>{text}</a>',
attrs=attrs.as_html(),
text=text)