Skip to content

Commit 7ce9a23

Browse files
committed
add featured button
1 parent 87c53ab commit 7ce9a23

File tree

4 files changed

+68
-57
lines changed

4 files changed

+68
-57
lines changed

src/cs_dynamicpages/content/dynamic_page_row.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,13 @@ def featured_list(self):
5050
depth=1,
5151
)
5252

53-
def show_featured_add_button(self, request):
54-
try:
55-
view = api.content.get_view(
56-
name=self.row_type,
57-
context=self,
58-
request=request,
59-
)
60-
if view and hasattr(view, "featured_add_button"):
61-
return view.featured_add_button
62-
return False
63-
except Exception as e:
64-
log.error(e)
65-
return False
53+
def show_featured_add_button(self):
54+
row_type = self.row_type
55+
row_type_fields = api.portal.get_registry_record('cs_dynamicpages.dynamica_pages_control_panel.row_type_fields')
56+
for row_type_field in row_type_fields:
57+
if row_type_field['row_type'] == row_type:
58+
return row_type_field['row_type_has_featured_add_button']
59+
return False
6660

6761
def render(self, request):
6862
if self.row_type:

src/cs_dynamicpages/controlpanels/dynamica_pages_control_panel/controlpanel.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ class IRowTypeFieldsSchema(Interface):
2525
default=[],
2626
)
2727

28+
row_type_has_featured_add_button = schema.Bool(
29+
title="Has featured add button",
30+
required=True,
31+
default=False,
32+
)
33+
2834

2935
class IDynamicaPagesControlPanel(Interface):
3036
widget(row_type_fields=DataGridFieldFactory)
@@ -36,34 +42,42 @@ class IDynamicaPagesControlPanel(Interface):
3642
{
3743
"row_type": "cs_dynamicpages-featured-view",
3844
"each_row_type_fields": ["IBasic.title", "IBasic.description", "IRelatedImage.related_image", "IRelatedImage.image_position", "ILinkInfo.link_text", "ILinkInfo.link_url"],
45+
"row_type_has_featured_add_button": False,
3946
},
4047
{
4148
"row_type": "cs_dynamicpages-featured-overlay-view",
4249
"each_row_type_fields": ["IBasic.title", "IBasic.description", "IRelatedImage.related_image", "ILinkInfo.link_text", "ILinkInfo.link_url"],
50+
"row_type_has_featured_add_button": False,
4351
},
4452
{
4553
"row_type": "cs_dynamicpages-horizontal-rule-view",
4654
"each_row_type_fields": ["IBasic.title"],
55+
"row_type_has_featured_add_button": False,
4756
},
4857
{
4958
"row_type": "cs_dynamicpages-spacer-view",
5059
"each_row_type_fields": ["IBasic.title"],
60+
"row_type_has_featured_add_button": False,
5161
},
5262
{
5363
"row_type": "cs_dynamicpages-slider-view",
5464
"each_row_type_fields": ["IBasic.title"],
65+
"row_type_has_featured_add_button": True,
5566
},
5667
{
5768
"row_type": "cs_dynamicpages-accordion-view",
5869
"each_row_type_fields": ["IBasic.title"],
70+
"row_type_has_featured_add_button": True,
5971
},
6072
{
6173
"row_type": "cs_dynamicpages-query-three-columns-view",
6274
"each_row_type_fields": ["IBasic.title", "ICollection.query", "ICollection.sort_on", "ICollection.sort_order", "ICollection.betweeen", "ICollection.limit"],
75+
"row_type_has_featured_add_button": False,
6376
},
6477
{
6578
"row_type": "cs_dynamicpages-text-view",
6679
"each_row_type_fields": ["IBasic.title", "IRichTextBehavior-text"],
80+
"row_type_has_featured_add_button": False,
6781
},
6882
],
6983
)

src/cs_dynamicpages/views/dynamic_view.pt

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -64,52 +64,56 @@
6464
</div>
6565
<tal:condition tal:condition="row/can_edit">
6666
<div class="edit-options features-list d-flex gap-2 align-items-start mb-3"
67-
tal:define="features_list row/featured_list" tal:condition="features_list">
68-
<tal:featured repeat="featured_brain features_list">
69-
<div tal:define="featured_obj featured_brain/getObject;">
70-
<div class="btn-group" data-elementid="${featured_obj/id}" data-parenturl="${row/absolute_url}"
71-
data-elementurl="${featured_obj/absolute_url}" data-delete-target="true" data-move-target="true">
72-
<a tal:attributes="class python:featured_obj.review_state() == 'published' and
67+
tal:define="features_list row/featured_list">
68+
<tal:conditionfeatures tal:condition="features_list">
69+
<tal:featured repeat="featured_brain features_list">
70+
<div tal:define="featured_obj featured_brain/getObject;">
71+
<div class="btn-group" data-elementid="${featured_obj/id}" data-parenturl="${row/absolute_url}"
72+
data-elementurl="${featured_obj/absolute_url}" data-delete-target="true"
73+
data-move-target="true">
74+
<a tal:attributes="class python:featured_obj.review_state() == 'published' and
7375
'position-relative btn btn-outline-success btn-sm bg-success-subtle dropdown-toggle' or
7476
'position-relative btn btn-outline-danger btn-sm bg-danger-subtle dropdown-toggle'"
75-
type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown"
76-
data-bs-display="static" aria-expanded="false">
77-
${featured_obj/Title}
78-
<span
79-
tal:attributes="class python:featured_obj.review_state() == 'published' and 'text-white position-absolute top-0 start-100 translate-middle p-1 bg-success border border-light rounded-circle' or 'text-white position-absolute top-0 start-100 translate-middle p-1 bg-danger border border-light rounded-circle'">
80-
</span>
81-
</a>
82-
<ul class="dropdown-menu">
83-
<li><a class="dropdown-item" href="${featured_obj/absolute_url}/edit">Edit</a>
84-
</li>
85-
<li>
86-
<h5 class="dropdown-header">State</h5>
87-
</li>
88-
<tal:define
89-
tal:define="featured_transitions python:context.portal_workflow.getTransitionsFor(featured_obj)">
90-
<tal:featured_transitions repeat="featured_transition featured_transitions">
91-
<li><a class="dropdown-item"
92-
href="${featured_transition/url}&_authenticator=${context/@@authenticator/token}">${featured_transition/name}</a>
93-
</li>
94-
</tal:featured_transitions>
95-
</tal:define>
96-
<li>
97-
<h5 class="dropdown-header">Move actions</h5>
98-
</li>
99-
<li><a class="dropdown-item" href="#" data-action="move-up"
100-
tal:condition="python:not(repeat['featured_brain'].start)">Move up</a></li>
101-
<li><a class="dropdown-item" href="#" data-action="move-down"
102-
tal:condition="python:not(repeat['featured_brain'].end)">Move down</a></li>
103-
<li>
104-
<hr class="dropdown-divider">
105-
</li>
106-
<li><a class="ms-3 btn btn-sm btn-danger align-self-start btn-delete-element" href="#"
107-
data-bs-toggle="modal" data-bs-target="#deleteElementModal">Delete</a></li>
108-
</ul>
77+
type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown"
78+
data-bs-display="static" aria-expanded="false">
79+
${featured_obj/Title}
80+
<span
81+
tal:attributes="class python:featured_obj.review_state() == 'published' and 'text-white position-absolute top-0 start-100 translate-middle p-1 bg-success border border-light rounded-circle' or 'text-white position-absolute top-0 start-100 translate-middle p-1 bg-danger border border-light rounded-circle'">
82+
</span>
83+
</a>
84+
<ul class="dropdown-menu">
85+
<li><a class="dropdown-item" href="${featured_obj/absolute_url}/edit">Edit</a>
86+
</li>
87+
<li>
88+
<h5 class="dropdown-header">State</h5>
89+
</li>
90+
<tal:define
91+
tal:define="featured_transitions python:context.portal_workflow.getTransitionsFor(featured_obj)">
92+
<tal:featured_transitions repeat="featured_transition featured_transitions">
93+
<li><a class="dropdown-item"
94+
href="${featured_transition/url}&_authenticator=${context/@@authenticator/token}">${featured_transition/name}</a>
95+
</li>
96+
</tal:featured_transitions>
97+
</tal:define>
98+
<li>
99+
<h5 class="dropdown-header">Move actions</h5>
100+
</li>
101+
<li><a class="dropdown-item" href="#" data-action="move-up"
102+
tal:condition="python:not(repeat['featured_brain'].start)">Move up</a></li>
103+
<li><a class="dropdown-item" href="#" data-action="move-down"
104+
tal:condition="python:not(repeat['featured_brain'].end)">Move down</a></li>
105+
<li>
106+
<hr class="dropdown-divider">
107+
</li>
108+
<li><a class="ms-3 btn btn-sm btn-danger align-self-start btn-delete-element" href="#"
109+
data-bs-toggle="modal" data-bs-target="#deleteElementModal">Delete</a></li>
110+
</ul>
111+
</div>
109112
</div>
110-
</div>
111-
</tal:featured>
112-
<tal:featured_add_button tal:condition="python:row.show_featured_add_button(request)">
113+
</tal:featured>
114+
</tal:conditionfeatures>
115+
116+
<tal:featured_add_button tal:condition="row/show_featured_add_button">
113117
<a class="btn btn-outline-primary btn-sm align-self-start"
114118
href="${row/absolute_url}/++add++DynamicPageRowFeatured">Add new featured</a>
115119
</tal:featured_add_button>

src/cs_dynamicpages/views/slider_view.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class SliderView(DynamicPageRowView):
1414
# If you want to define a template here, please remove the template from
1515
# the configure.zcml registration of this view.
1616
# template = ViewPageTemplateFile('slider_view.pt')
17-
featured_add_button = True
1817

1918
def elements(self):
2019
# Implement your own actions:

0 commit comments

Comments
 (0)