-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Problem: customizing tabular view is hard
Solution: use views for table cells such that they can be overridden
- Loading branch information
Showing
7 changed files
with
177 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Enable customization of tabular_view via views for fields of contentlisting items. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from Products.Five import BrowserView | ||
|
||
# BEWARE: the cell views are registered for ContentListingObject | ||
# which are not acquisition aware. | ||
# That precludes using Products.Five.ViewPageTemplateFile | ||
# and imposes to use zope.browserpage.viewpagetemplatefile. | ||
from zope.browserpage.viewpagetemplatefile import ViewPageTemplateFile | ||
# BEWARE | ||
|
||
class TitleCell(BrowserView): | ||
__call__ = ViewPageTemplateFile("templates/titlecell.pt") | ||
|
||
@property | ||
def title(self): | ||
return self.context.Title() or self.context.getId() | ||
|
||
@property | ||
def link(self): | ||
suffix = ( | ||
"/view" | ||
if self.context.PortalType in self.table_view.use_view_action | ||
else "" | ||
) | ||
return self.context.getURL() + suffix | ||
|
||
@property | ||
def type_class(self): | ||
return ("contenttype-" + | ||
self.table_view.normalizeString(self.context.PortalType()) | ||
if self.table_view.show_icons else '') | ||
|
||
@property | ||
def wf_state_class(self): | ||
return ("state-" + | ||
self.table_view.normalizeString(self.context.review_state())) | ||
|
||
def render_image(self): | ||
thumb_scale_table = self.table_view.get_thumb_scale_table() | ||
img_class = self.table_view.img_class | ||
return self.table_view.image_scale.tag( | ||
self.context, "image", | ||
scale=thumb_scale_table, css_class=img_class | ||
) | ||
|
||
|
||
class CreatorCell(BrowserView): | ||
__call__ = ViewPageTemplateFile("templates/creatorcell.pt") | ||
|
||
@property | ||
def author(self): | ||
return self.table_view.pas_member.info(self.context.Creator) | ||
|
||
@property | ||
def author_name(self): | ||
return self.author["fullname"] or self.author["username"] | ||
|
||
|
||
class IconCell(BrowserView): | ||
def __call__(self): | ||
item = self.context | ||
item_type = item.PortalType() | ||
if item_type == "File": | ||
icon_type = "mimetype-" + item.mime_type | ||
elif self.table_view.show_icons: | ||
icon_type = ("contenttype/" | ||
+ self.table_view.normalizeString(item_type)) | ||
else: | ||
icon_type = "" | ||
icon = self.table_view.iconresolver.tag(icon_type).decode("utf8") | ||
return "<td>" + icon + "</td>" | ||
|
||
def normalizeString(self, string): | ||
return self.table_view.normalizeString(string) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<td> | ||
<a tal:condition="view/author" | ||
tal:attributes="href string:${view/table_view/navigation_root_url}/author/${context/Creator}" | ||
tal:content="view/author_name">Jos Henken</a> | ||
</td> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<td tal:define="table_view nocall:view/table_view; | ||
thumb_scale_table view/table_view/get_thumb_scale_table;"> | ||
<a tal:condition="python:context.PortalType == 'File' and table_view.show_icons()" | ||
tal:attributes="href view/link; | ||
class string:${view/type_class} ${view/wf_state_class} url; | ||
title context/PortalType"> | ||
<img class="mime-icon" | ||
tal:attributes="src context/MimeTypeIcon"> | ||
</a> | ||
<a tal:attributes="href view/link; | ||
class string:${view/type_class} ${view/wf_state_class} url; | ||
title context/PortalType" | ||
tal:content="view/title">Item Title | ||
</a> | ||
<a tal:condition="python:context.getIcon and thumb_scale_table"> | ||
<img tal:attributes="href view/link" | ||
tal:replace="structure view/render_image" /> | ||
</a> | ||
</td> |