Added method to link a model with it's column list to display on the generic list template, this way the same column layout is displayed regarless of the view that generates it.
This commit is contained in:
@@ -2,6 +2,7 @@ import copy
|
|||||||
|
|
||||||
object_navigation = {}
|
object_navigation = {}
|
||||||
menu_links = []
|
menu_links = []
|
||||||
|
model_list_columns = {}
|
||||||
|
|
||||||
def register_links(src, links, menu_name=None):
|
def register_links(src, links, menu_name=None):
|
||||||
if menu_name in object_navigation:
|
if menu_name in object_navigation:
|
||||||
@@ -30,3 +31,10 @@ def register_menu(links):
|
|||||||
menu_links.append(link)
|
menu_links.append(link)
|
||||||
|
|
||||||
menu_links.sort(lambda x,y: 1 if x>y else -1, lambda x:x['position'] if 'position' in x else 1)
|
menu_links.sort(lambda x,y: 1 if x>y else -1, lambda x:x['position'] if 'position' in x else 1)
|
||||||
|
|
||||||
|
|
||||||
|
def register_model_list_columns(model, columns):
|
||||||
|
if model in model_list_columns:
|
||||||
|
model_list_columns[model].extend(columns)
|
||||||
|
else:
|
||||||
|
model_list_columns[model] = copy.copy(columns)
|
||||||
|
|||||||
@@ -32,6 +32,9 @@
|
|||||||
{% if not hide_object %}
|
{% if not hide_object %}
|
||||||
<th>{% trans 'Identifier' %}</th>
|
<th>{% trans 'Identifier' %}</th>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% for column in object_list.0|get_model_list_columns %}
|
||||||
|
<th>{{ column.name|capfirst }}</th>
|
||||||
|
{% endfor %}
|
||||||
{% for column in extra_columns %}
|
{% for column in extra_columns %}
|
||||||
<th>{{ column.name|capfirst }}</th>
|
<th>{{ column.name|capfirst }}</th>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@@ -51,6 +54,10 @@
|
|||||||
<td>{% if not hide_link %}<a href="{{ object.get_absolute_url }}">{{ object }}</a>{% else %}{{ object }}{% endif %}</td>
|
<td>{% if not hide_link %}<a href="{{ object.get_absolute_url }}">{{ object }}</a>{% else %}{{ object }}{% endif %}</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% for column in object|get_model_list_columns %}
|
||||||
|
<td>{{ object|object_property:column.attribute|safe }}</td>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
{% for column in extra_columns %}
|
{% for column in extra_columns %}
|
||||||
<td>{{ object|object_property:column.attribute|safe }}</td>
|
<td>{{ object|object_property:column.attribute|safe }}</td>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
@@ -3,9 +3,14 @@ from django.template.defaultfilters import stringfilter
|
|||||||
from django.template import Library, Node, Variable, VariableDoesNotExist
|
from django.template import Library, Node, Variable, VariableDoesNotExist
|
||||||
|
|
||||||
from common.utils import return_attrib
|
from common.utils import return_attrib
|
||||||
|
from common.api import model_list_columns
|
||||||
|
|
||||||
register = Library()
|
register = Library()
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def object_property(value, arg):
|
def object_property(value, arg):
|
||||||
return return_attrib(value, arg)
|
return return_attrib(value, arg)
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def get_model_list_columns(value):
|
||||||
|
return model_list_columns.get(type(value), [])
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
from django.core.urlresolvers import reverse
|
||||||
|
|
||||||
from common.api import register_links, register_menu
|
from common.api import register_links, register_menu, register_model_list_columns
|
||||||
|
from common.utils import pretty_size
|
||||||
|
|
||||||
from models import Document
|
from models import Document
|
||||||
from staging import StagingFile
|
from staging import StagingFile
|
||||||
@@ -23,12 +25,21 @@ document_download = {'text':_('download'), 'view':'document_download', 'args':'o
|
|||||||
|
|
||||||
staging_file_preview = {'text':_('preview'), 'class':'fancybox', 'view':'staging_file_preview', 'args':'object.id', 'famfam':'drive_magnify'}
|
staging_file_preview = {'text':_('preview'), 'class':'fancybox', 'view':'staging_file_preview', 'args':'object.id', 'famfam':'drive_magnify'}
|
||||||
|
|
||||||
register_links(Document, [document_edit, document_edit_metadata, document_delete, document_preview, document_download])
|
register_links(Document, [document_edit, document_edit_metadata, document_delete, document_download])
|
||||||
register_links(Document, [document_list, document_create, document_create_multiple, document_create_sibling, document_view], menu_name='sidebar')
|
register_links(Document, [document_list, document_create, document_create_multiple, document_create_sibling, document_view, document_preview], menu_name='sidebar')
|
||||||
register_links(['document_list', 'document_create', 'document_create_multiple', 'upload_document_with_type', 'upload_multiple_documents_with_type'], [document_list, document_create, document_create_multiple], menu_name='sidebar')
|
register_links(['document_list', 'document_create', 'document_create_multiple', 'upload_document_with_type', 'upload_multiple_documents_with_type'], [document_list, document_create, document_create_multiple], menu_name='sidebar')
|
||||||
|
|
||||||
register_links(StagingFile, [staging_file_preview])
|
register_links(StagingFile, [staging_file_preview])
|
||||||
|
|
||||||
|
register_model_list_columns(Document, [
|
||||||
|
{'name':_(u'mimetype'), 'attribute':'file_mimetype'},
|
||||||
|
{'name':_(u'added'), 'attribute':lambda x: x.date_added.date()},
|
||||||
|
{'name':_(u'file size'), 'attribute':lambda x: pretty_size(x.file.storage.size(x.file.path)) if x.exists() else '-'},
|
||||||
|
{'name':_(u'thumbnail'), 'attribute':
|
||||||
|
lambda x: '<a class="fancybox" href="%s"><img src="%s" /></a>' % (reverse('document_preview', args=[x.id]),
|
||||||
|
reverse('document_thumbnail', args=[x.id]))
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
register_menu([
|
register_menu([
|
||||||
{'text':_('documents'), 'view':'document_list', 'links':[
|
{'text':_('documents'), 'view':'document_list', 'links':[
|
||||||
|
|||||||
Reference in New Issue
Block a user