Skip to content

Commit d65bf1c

Browse files
committed
add featured button
1 parent cd8be69 commit d65bf1c

File tree

7 files changed

+59
-33
lines changed

7 files changed

+59
-33
lines changed

src/cs_dynamicpages/content/dynamic_page_row.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class IDynamicPageRow(model.Schema):
3333
class DynamicPageRow(Container):
3434
"""Content-type class for IPortadakoLerroa"""
3535

36+
def row_template(self):
37+
return self.row_type.replace("cs_dynamicpages-", "")
38+
3639
def review_state(self):
3740
return api.content.get_state(obj=self)
3841

@@ -47,6 +50,20 @@ def featured_list(self):
4750
depth=1,
4851
)
4952

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
66+
5067
def render(self, request):
5168
if self.row_type:
5269
try:

src/cs_dynamicpages/views/configure.zcml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
<!-- -*- extra stuff goes here -*- -->
99

1010
<browser:page
11-
name="dynamic-page-row-featured-view"
12-
for="*"
11+
name="view"
12+
for="cs_dynamicpages.content.dynamic_page_row_featured.IDynamicPageRowFeatured"
1313
class=".dynamic_page_row_featured_view.DynamicPageRowFeaturedView"
1414
template="dynamic_page_row_featured_view.pt"
1515
permission="zope2.View"
16-
layer="cs_dynamicpages.interfaces.ICsDynamicpagesLayer"
16+
layer="cs_dynamicpages.interfaces.IBrowserLayer"
1717
/>
1818

1919
<browser:page

src/cs_dynamicpages/views/dynamic_page_folder_view.pt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,6 @@
66

77
<metal:custom_title fill-slot="content-title">
88
<h1 tal:replace="structure context/@@title" />
9-
10-
<!-- @@title view template: -->
11-
<!--
12-
<h1 tal:define="title context/Title" tal:condition="title" tal:content="title">
13-
Title or id
14-
</h1>
15-
-->
16-
179
</metal:custom_title>
1810

1911
<metal:custom_description fill-slot="content-description">
Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
1-
<html xmlns="http://www.w3.org/1999/xhtml"
2-
xmlns:metal="http://xml.zope.org/namespaces/metal"
3-
xmlns:tal="http://xml.zope.org/namespaces/tal"
4-
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
5-
i18n:domain="cs_dynamicpages"
6-
metal:use-macro="context/main_template/macros/master">
1+
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:metal="http://xml.zope.org/namespaces/metal"
2+
xmlns:tal="http://xml.zope.org/namespaces/tal" xmlns:i18n="http://xml.zope.org/namespaces/i18n"
3+
i18n:domain="cs_dynamicpages" metal:use-macro="context/main_template/macros/master">
4+
75
<body>
86

97
<metal:custom_title fill-slot="content-title">
108
<h1 tal:replace="structure context/@@title" />
11-
12-
<!-- @@title view template: -->
13-
<!--
14-
<h1 tal:define="title context/Title" tal:condition="title" tal:content="title">
15-
Title or id
16-
</h1>
17-
-->
18-
199
</metal:custom_title>
2010

2111
<metal:custom_description fill-slot="content-description">
2212
<p tal:replace="structure context/@@description" />
2313
</metal:custom_description>
2414

2515
<metal:content-core fill-slot="content-core">
26-
<metal:block define-macro="content-core">
16+
<metal:block define-macro="content-core">
2717

28-
<h2>Main content</h2>
29-
<!--<div tal:replace="view/my_custom_view_method" />-->
30-
<!--<div tal:replace="context/my_custom_field" />-->
18+
<tal:define tal:define="
19+
isAnon context/@@plone_portal_state/anonymous;
20+
">
21+
<tal:condition tal:condition="isAnon">
22+
<tal:replace tal:replace="python:context.REQUEST.RESPONSE.redirect(context.aq_parent.absolute_url(),301)">
23+
</tal:replace>
24+
</tal:condition>
25+
<tal:conditionisanon tal:condition="not:isAnon">
26+
<a class="btn btn-primary btn-lg" href="${context/aq_parent/absolute_url}">View dynamic page row</a>
27+
</tal:conditionisanon>
28+
</tal:define>
3129

32-
</metal:block>
30+
</metal:block>
3331
</metal:content-core>
3432
</body>
35-
</html>
33+
34+
</html>

src/cs_dynamicpages/views/dynamic_page_row_view.pt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
<tal:conditionisanon tal:condition="not:isAnon">
1717
<section class="dynamic-row state-${context/review_state}">
1818
<div class="edit-buttons d-flex gap-2" tal:condition="context/can_edit">
19+
<small
20+
class="d-inline-flex mb-3 px-2 py-1 fw-semibold text-warning-emphasis bg-warning-subtle border border-warning-subtle rounded-2 position-relative">
21+
Template: ${context/row_template}
22+
</small>
1923
<a class="btn btn-outline-primary btn-sm align-self-start" href="${context/absolute_url}/edit">Edit</a>
2024
<div class="ms-auto d-flex gap-2 align-items-start">
2125
<a class="btn btn-outline-primary btn-sm align-self-start"
@@ -33,14 +37,19 @@
3337
</div>
3438
<tal:condition tal:condition="context/can_edit">
3539
<div class="features-list d-flex gap-2 align-items-start mb-3"
36-
tal:define="features_list context/featured_list" tal:condition="features_list">
40+
tal:define="features_list context/featured_list">
3741
<tal:featured repeat="featured_brain features_list">
3842
<div tal:define="featured_obj featured_brain/getObject;">
3943
<a tal:attributes="class python:featured_obj.review_state() == 'published' and 'btn btn-outline-success btn-sm bg-success-subtle' or 'btn btn-outline-danger btn-sm bg-danger-subtle'"
4044
href="${featured_obj/absolute_url}">${featured_obj/Title}</a>
4145
</div>
4246
</tal:featured>
47+
<tal:featured_add_button tal:condition="python:context.show_featured_add_button(request)">
48+
<a class="btn btn-outline-primary btn-sm align-self-start"
49+
href="${context/absolute_url}/++add++DynamicPageRowFeatured">Add new featured</a>
50+
</tal:featured_add_button>
4351
</div>
52+
4453
</tal:condition>
4554

4655
<div class="content">

src/cs_dynamicpages/views/dynamic_view.pt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
<section class="dynamic-row state-${row/review_state}" data-rowid="${row/id}"
1515
data-rowurl="${row/aq_parent/absolute_url}">
1616
<div class="edit-buttons d-flex gap-2" tal:condition="row/can_edit">
17+
<small
18+
class="d-inline-flex mb-3 px-2 py-1 fw-semibold text-warning-emphasis bg-warning-subtle border border-warning-subtle rounded-2 position-relative">
19+
Template: ${row/row_template}
20+
</small>
1721
<a class="btn btn-outline-primary btn-sm align-self-start" href="${row/absolute_url}">View</a>
1822
<a class="btn btn-outline-primary btn-sm align-self-start" href="${row/absolute_url}/edit">Edit</a>
1923

@@ -24,7 +28,7 @@
2428
class="btn btn-outline-primary btn-sm align-self-start" href="#" data-action="move-down">Move
2529
down</a>
2630
<small
27-
class="d-inline-flex ms-auto mb-3 px-2 py-1 fw-semibold text-warning-emphasis bg-warning-subtle border border-warning-subtle rounded-2 position-relative">
31+
class="d-inline-flex mb-3 px-2 py-1 fw-semibold text-warning-emphasis bg-warning-subtle border border-warning-subtle rounded-2 position-relative">
2832
Review state: ${row/review_state}
2933
<span
3034
tal:attributes="class python:row.review_state() == 'published' and 'position-absolute top-0 start-100 translate-middle p-2 bg-success border border-light rounded-circle' or 'position-absolute top-0 start-100 translate-middle p-2 bg-danger border border-light rounded-circle'">
@@ -42,6 +46,10 @@
4246
href="${featured_obj/absolute_url}">${featured_obj/Title}</a>
4347
</div>
4448
</tal:featured>
49+
<tal:featured_add_button tal:condition="python:row.show_featured_add_button(request)">
50+
<a class="btn btn-outline-primary btn-sm align-self-start"
51+
href="${context/absolute_url}/++add++DynamicPageRowFeatured">Add new featured</a>
52+
</tal:featured_add_button>
4553
</div>
4654
</tal:condition>
4755
<div class="content">

src/cs_dynamicpages/views/slider_view.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ 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
1718

1819
def elements(self):
1920
# Implement your own actions:

0 commit comments

Comments
 (0)