Merge branch 'develop-2.9' into 2006-scripts-reports-background

This commit is contained in:
John Anderson
2020-07-06 02:06:53 -04:00
31 changed files with 1135 additions and 1101 deletions

View File

@@ -130,25 +130,28 @@ class ButtonsColumn(tables.TemplateColumn):
:param model: Model class to use for calculating URL view names
:param prepend_content: Additional template content to render in the column (optional)
"""
buttons = ('changelog', 'edit', 'delete')
attrs = {'td': {'class': 'text-right text-nowrap noprint'}}
# Note that braces are escaped to allow for string formatting prior to template rendering
template_code = """
<a href="{{% url '{app_label}:{model_name}_changelog' {pk_field}=record.{pk_field} %}}" class="btn btn-default btn-xs" title="Change log">
<i class="fa fa-history"></i>
</a>
{{% if perms.{app_label}.change_{model_name} %}}
{{% if "changelog" in buttons %}}
<a href="{{% url '{app_label}:{model_name}_changelog' {pk_field}=record.{pk_field} %}}" class="btn btn-default btn-xs" title="Change log">
<i class="fa fa-history"></i>
</a>
{{% endif %}}
{{% if "edit" in buttons and perms.{app_label}.change_{model_name} %}}
<a href="{{% url '{app_label}:{model_name}_edit' {pk_field}=record.{pk_field} %}}?return_url={{{{ request.path }}}}" class="btn btn-xs btn-warning" title="Edit">
<i class="fa fa-pencil"></i>
</a>
{{% endif %}}
{{% if perms.{app_label}.delete_{model_name} %}}
{{% if "delete" in buttons and perms.{app_label}.delete_{model_name} %}}
<a href="{{% url '{app_label}:{model_name}_delete' {pk_field}=record.{pk_field} %}}?return_url={{{{ request.path }}}}" class="btn btn-xs btn-danger" title="Delete">
<i class="fa fa-trash"></i>
</a>
{{% endif %}}
"""
def __init__(self, model, *args, pk_field='pk', prepend_template=None, **kwargs):
def __init__(self, model, *args, pk_field='pk', buttons=None, prepend_template=None, **kwargs):
if prepend_template:
prepend_template = prepend_template.replace('{', '{{')
prepend_template = prepend_template.replace('}', '}}')
@@ -157,11 +160,16 @@ class ButtonsColumn(tables.TemplateColumn):
template_code = self.template_code.format(
app_label=model._meta.app_label,
model_name=model._meta.model_name,
pk_field=pk_field
pk_field=pk_field,
buttons=buttons
)
super().__init__(template_code=template_code, *args, **kwargs)
self.extra_context.update({
'buttons': buttons or self.buttons,
})
def header(self):
return ''

View File

@@ -242,3 +242,14 @@ def tag(tag, url_name=None):
'tag': tag,
'url_name': url_name,
}
@register.inclusion_tag('utilities/templatetags/badge.html')
def badge(value, show_empty=False):
"""
Display the specified number as a badge.
"""
return {
'value': value,
'show_empty': show_empty,
}

View File

@@ -217,7 +217,7 @@ def prepare_cloned_fields(instance):
# Copy tags
if is_taggable(instance):
params['tags'] = ','.join([t.name for t in instance.tags.all()])
params['tags'] = ','.join([t.name for t in instance.tags.all().unrestricted()])
# Concatenate parameters into a URL query string
param_string = '&'.join(