-
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
1 parent
4e0aa66
commit db8e434
Showing
7 changed files
with
200 additions
and
115 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,80 @@ | ||
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.portal_type 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.portal_type) | ||
if self.table_view.show_icons | ||
else "" | ||
) | ||
|
||
@property | ||
def wf_state_class(self): | ||
return "state-" + self.table_view.normalizeString(self.context.review_state()) | ||
|
||
|
||
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.portal_type | ||
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>" | ||
|
||
|
||
class ImageCell(BrowserView): | ||
def render_image(self): | ||
thumb_scale_table = self.table_view.get_thumb_scale_table() | ||
if thumb_scale_table and self.context.getIcon: | ||
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 | ||
) | ||
else: | ||
return "" | ||
|
||
def __call__(self): | ||
image = self.render_image() | ||
return "<td>" + image + "</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<td class="text-nowrap"> | ||
<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,7 @@ | ||
<td class="text-nowrap"> | ||
<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> | ||
</td> |