This commit is contained in:
Daniel Quinn
2016-02-21 00:14:50 +00:00
parent a5124cade6
commit 422ae9303a
13 changed files with 89 additions and 40 deletions

View File

@@ -56,26 +56,35 @@ class DocumentAdmin(admin.ModelAdmin):
def tags_(self, obj):
r = ""
for tag in obj.tags.all():
r += '<a class="tag" style="background-color: {};" href="{}">{}</a>'.format(
tag.get_colour_display(),
"{}?tags__id__exact={}".format(
reverse("admin:documents_document_changelist"),
tag.pk
),
tag.slug
colour = tag.get_colour_display()
r += html_tag(
"a",
tag.slug,
**{
"class": "tag",
"style": "background-color: {};".format(colour),
"href": "{}?tags__id__exact={}".format(
reverse("admin:documents_document_changelist"),
tag.pk
)
}
)
return r
tags_.allow_tags = True
def document(self, obj):
return '<a href="{}">' \
'<img src="{}" width="22" height="22" alt="{} icon" title="{}">' \
'</a>'.format(
obj.download_url,
static("documents/img/{}.png".format(obj.file_type)),
obj.file_type,
obj.file_name
)
return html_tag(
"a",
html_tag(
"img",
src=static("documents/img/{}.png".format(obj.file_type)),
width=22,
height=22,
alt=obj.file_type,
title=obj.file_name
),
href=obj.download_url
)
document.allow_tags = True
admin.site.register(Sender)
@@ -85,3 +94,16 @@ admin.site.register(Document, DocumentAdmin)
# Unless we implement multi-user, these default registrations don't make sense.
admin.site.unregister(Group)
admin.site.unregister(User)
def html_tag(kind, inside=None, **kwargs):
attributes = []
for lft, rgt in kwargs.items():
attributes.append('{}="{}"'.format(lft, rgt))
if inside is not None:
return "<{kind} {attributes}>{inside}</{kind}>".format(
kind=kind, attributes=" ".join(attributes), inside=inside)
return "<{} {}/>".format(kind, " ".join(attributes))