Skip to content

Commit

Permalink
Merge 6b65a43 into dc7f73f
Browse files Browse the repository at this point in the history
  • Loading branch information
gbastien committed Aug 3, 2023
2 parents dc7f73f + 6b65a43 commit 8db1d3f
Show file tree
Hide file tree
Showing 16 changed files with 319 additions and 114 deletions.
6 changes: 4 additions & 2 deletions CHANGES.rst
Expand Up @@ -4,8 +4,10 @@ Changelog
0.58 (unreleased)
-----------------

- Nothing changed yet.

- Added new field `ICategorize.show_preview` to turn link to element to a
`collective.documentviewer` preview instead download.
Fixed icon displayed when preview computation in progress.
[gbastien]

0.57 (2023-03-30)
-----------------
Expand Down
6 changes: 5 additions & 1 deletion src/collective/iconifiedcategory/adapter.py
Expand Up @@ -53,6 +53,7 @@ def _get_basic_infos(self, category):
'to_sign': self._to_sign,
'signed': self._signed,
'publishable': self._publishable,
'show_preview': self._show_preview(category),
}
# update subcategory infos if any
if ISubcategory.providedBy(category):
Expand Down Expand Up @@ -149,6 +150,9 @@ def _publishable_activated(self, category):
def _publishable(self):
return getattr(self.obj, 'publishable', False)

def _show_preview(self, category):
return category.show_preview

@property
def _preview_status(self):
return IIconifiedPreview(self.obj).status
Expand Down Expand Up @@ -221,7 +225,7 @@ def status(self):
# under conversion?
ann = IAnnotations(self.context)['collective.documentviewer']
if 'successfully_converted' not in ann:
if 'filehash' in ann:
if 'filehash' in ann or ann.get('converting', False) is True:
return 'in_progress'
return 'not_converted'

Expand Down
Expand Up @@ -9,8 +9,10 @@
<ul tal:define="number_of_columns python: view.number_of_columns(infos[view.category_uid])"
tal:attributes="class python: 'many_elements_%d_columns' % view.number_of_columns(infos[view.category_uid])">
<li tal:repeat="element python: infos[view.category_uid]">
<tal:block define="element_url python: element['download_url'] and element['download_url'] or element['relative_url']">
<tal:block define="element_url python: element['download_url'] and element['download_url'] or element['relative_url'];
show_preview python: view.show_preview(element)">
<a class="categorized-element-title"
tal:condition="not: show_preview"
tal:attributes="href string:${portal_url}/${element_url}">
<span>
<img src="" alt="" tal:attributes="src string:${portal_url}/${element/icon_url};
Expand All @@ -19,10 +21,46 @@
<span tal:content="element/title"
tal:attributes="title element/description"></span>
</span>
<tal:filesize tal:condition="element/warn_filesize">
(<span tal:replace="structure python: view.render_filesize(size=element['filesize'])">File size warning</span>)
</tal:filesize>
</a>

<tal:show_preview condition="show_preview">
<span class="help"
title="The document is currently under conversion, please refresh the page in a few minutes"
i18n:attributes="title"
tal:condition="python: element['preview_status'] == 'in_progress'">
<img src=""
width="16px"
height="16px"
tal:attributes="src string:${portal_url}/spinner_small.gif" />
</span>
<span class="help"
title="The document conversion failed"
i18n:attributes="title"
tal:condition="python: element['preview_status'] == 'conversion_error'">
<img src=""
tal:attributes="src string:${portal_url}/error_icon.png" />
</span>
<a href=""
title="Preview"
i18n:attributes="title"
target="_blank"
tal:attributes="href string:${portal_url}/${element/relative_url}/documentviewer#document/p1">
<span>
<img src="" alt="" tal:attributes="src string:${portal_url}/${element/icon_url};
alt element/category_title;
title element/category_title" />
<img src=""
tal:attributes="src string:${portal_url}/file_icon.png" />
<span tal:content="element/title"
tal:attributes="title element/description"></span>
</span>
</a>
</tal:show_preview>

<tal:filesize tal:condition="element/warn_filesize">
(<span tal:replace="structure python: view.render_filesize(size=element['filesize'])">File size warning</span>)
</tal:filesize>

<div class="categorized_elements_details" tal:condition="python: view.show_details(number_of_columns)">
<tal:show_to_print_icon condition="python: view.show(element, 'to_be_printed')">
<span class=""
Expand Down Expand Up @@ -56,32 +94,16 @@
title python: view.get_tag_title_for('publishable', element)">
</span>
</tal:show_publishable_icon>

<tal:show_download_icon condition="python: view.show_download(element)">
<a tal:attributes="href string:${portal_url}/${element_url}">
<img i18n:attributes="title"
title="Download"
tal:attributes="src string:${portal_url}/download_icon.png;" />
</a>
</tal:show_download_icon>
</div>
<tal:show_preview_link condition="view/show_preview_link">
<a href=""
title="Preview"
i18n:attributes="title"
target="_blank"
tal:condition="python: element['preview_status'] == 'converted'"
tal:attributes="href string:${portal_url}/${element/relative_url}/documentviewer#document/p1">
<img src=""
tal:attributes="src string:${portal_url}/file_icon.png" />
</a>
<span class="help"
title="The document is currently under conversion, please refresh the page in a few minutes"
i18n:attributes="title"
tal:condition="python: element['preview_status'] == 'in_progress'">
<img src=""
tal:attributes="src string:${portal_url}/spinner.gif" />
</span>
<span class="help"
title="The document conversion failed"
i18n:attributes="title"
tal:condition="python: element['preview_status'] == 'conversion_error'">
<img src=""
tal:attributes="src string:${portal_url}/error_icon.png" />
</span>
</tal:show_preview_link>

</tal:block>
</li>
</ul>
Expand Down
22 changes: 20 additions & 2 deletions src/collective/iconifiedcategory/browser/views.py
Expand Up @@ -107,9 +107,10 @@ def show_details(self, number_of_columns):
in the tooltispter popup."""
return bool(number_of_columns < 3)

def show_preview_link(self):
def show_preview(self, element):
"""Made to be overrided."""
return True
return element["show_preview"] and \
element["preview_status"] in ('in_progress', 'converted')

@property
def categories_uids(self):
Expand Down Expand Up @@ -155,6 +156,16 @@ def show(self, element, attr_prefix):
show = element['{0}_activated'.format(attr_prefix)] and self._show_detail(attr_prefix)
return show

def show_download(self, element):
""" """
return not element["show_preview"] == 2 or \
(element["show_preview"] == 2 and self._show_protected_download(element))

def _show_protected_download(self, element):
"""When "show_preview" is "2", trigger advanced check.
Made to be overrided."""
return True

def _show_detail(self, detail_type):
"""Made to be overrided."""
return True
Expand Down Expand Up @@ -211,6 +222,13 @@ class CanViewAwareDownload(Download):
def __call__(self):
if not check_can_view(self.context, self.request):
raise Unauthorized
else:
# when using preview, check if downloadable
parent = self.context.aq_parent
element = parent.categorized_elements[self.context.UID()]
infos = parent.unrestrictedTraverse('@@categorized-childs-infos')
if not infos.show_download(element):
raise Unauthorized
# access is managed by can_view
with api.env.adopt_roles(['Manager']):
return super(CanViewAwareDownload, self).__call__()
Expand Down
31 changes: 14 additions & 17 deletions src/collective/iconifiedcategory/configure.zcml
Expand Up @@ -29,24 +29,22 @@
title="collective.iconifiedcategory"
directory="profiles/default"
description="Installs the collective.iconifiedcategory add-on."
provides="Products.GenericSetup.interfaces.EXTENSION"
/>
provides="Products.GenericSetup.interfaces.EXTENSION" />

<genericsetup:importStep
name="collective.iconifiedcategory:default-postInstall"
title="collective.iconifiedcategory post_install import step"
description="Post install import step from collective.iconifiedcategory"
handler=".setuphandlers.post_install">
<depends name="types"/>
<depends name="types" />
</genericsetup:importStep>

<genericsetup:registerProfile
name="testing"
title="collective.iconifiedcategory (testing)"
directory="profiles/testing"
description="Installs the collective.iconifiedcategory testing profile."
provides="Products.GenericSetup.interfaces.EXTENSION"
/>
provides="Products.GenericSetup.interfaces.EXTENSION" />

<genericsetup:importStep
name="collective.iconifiedcategory:testing-postInstall"
Expand All @@ -58,36 +56,35 @@
<utility
provides="zope.schema.interfaces.IVocabularyFactory"
name="collective.iconifiedcategory.categories"
factory=".vocabularies.CategoryVocabulary"
/>
factory=".vocabularies.CategoryVocabulary" />

<utility
provides="zope.schema.interfaces.IVocabularyFactory"
name="collective.iconifiedcategory.every_categories"
factory=".vocabularies.EveryCategoryVocabulary"
/>
factory=".vocabularies.EveryCategoryVocabulary" />

<utility
provides="zope.schema.interfaces.IVocabularyFactory"
name="collective.iconifiedcategory.category_titles"
factory=".vocabularies.CategoryTitleVocabulary"
/>
factory=".vocabularies.CategoryTitleVocabulary" />

<utility
provides="zope.schema.interfaces.IVocabularyFactory"
name="collective.iconifiedcategory.every_category_titles"
factory=".vocabularies.EveryCategoryTitleVocabulary"
/>
factory=".vocabularies.EveryCategoryTitleVocabulary" />

<utility
provides="zope.schema.interfaces.IVocabularyFactory"
name="collective.iconifiedcategory.show_preview_vocabulary"
factory=".vocabularies.ShowPreviewVocabulary" />

<!-- indexes -->
<adapter
name="enabled"
factory=".indexes.enabled"
/>
factory=".indexes.enabled" />

<adapter
name="content_category_uid"
factory=".indexes.content_category_uid"
/>
factory=".indexes.content_category_uid" />

</configure>
8 changes: 8 additions & 0 deletions src/collective/iconifiedcategory/content/base.py
Expand Up @@ -72,6 +72,14 @@ class ICategorize(Interface):
required=False,
)

show_preview = schema.Choice(
title=_(u'Show preview?'),
description=_(u'Show preview description.'),
vocabulary='collective.iconifiedcategory.show_preview_vocabulary',
default=0,
required=True,
)

@invariant
def signedInvariant(data):
"""'signed' may only be True if 'to_sign' is True."""
Expand Down
9 changes: 6 additions & 3 deletions src/collective/iconifiedcategory/content/events.py
Expand Up @@ -7,6 +7,7 @@
:license: GPL, see LICENCE.txt for more details.
"""

from collective.documentviewer.async import queueJob
from collective.iconifiedcategory import _
from collective.iconifiedcategory import utils
from collective.iconifiedcategory.content.category import ICategory
Expand Down Expand Up @@ -112,14 +113,16 @@ def categorized_content_updated(event, is_created=False):
obj = event.object

if hasattr(obj, 'content_category'):
target = utils.get_category_object(obj, obj.content_category)
category = utils.get_category_object(obj, obj.content_category)

if category.show_preview in (1, 2):
queueJob(obj)

if hasattr(obj, 'to_print'):
# if current 'to_print' is None, it means that current content
# could not be printable, but as it changed,
# in this case we use the default value
if obj.to_print is None:
category = utils.get_category_object(obj, obj.content_category)
category_group = category.get_category_group(category)
if category_group.to_be_printed_activated:
obj.to_print = category.to_print
Expand All @@ -140,7 +143,7 @@ def categorized_content_updated(event, is_created=False):
if obj.REQUEST.get('defer_update_categorized_elements', False):
return

utils.update_categorized_elements(obj.aq_parent, obj, target)
utils.update_categorized_elements(obj.aq_parent, obj, category)


def content_category_updated(event):
Expand Down

0 comments on commit 8db1d3f

Please sign in to comment.