Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions news/3953.breaking
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Move plone.app.contenttypes views to plone.app.layout
[frapell]
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"Products.MimetypesRegistry",
"Products.PortalTransforms",
"Products.statusmessages",
"plone.app.layout",
"plone.app.textfield",
"plone.app.uuid",
"plone.autoform",
Expand Down
88 changes: 6 additions & 82 deletions src/plone/app/contenttypes/browser/collection.py
Original file line number Diff line number Diff line change
@@ -1,85 +1,9 @@
from Acquisition import aq_inner
from plone.app.contenttypes import _
from plone.app.contenttypes.behaviors.collection import ICollection
from plone.app.contenttypes.behaviors.leadimage import ILeadImage
from plone.app.contenttypes.browser.folder import FolderView
from plone.app.contenttypes.interfaces import IFolder
from plone.app.contenttypes.interfaces import IImage
from plone.memoize.view import memoize
import zope.deferredimport


class CollectionView(FolderView):
@property
def collection_behavior(self):
return ICollection(aq_inner(self.context))
zope.deferredimport.initialize()

@property
def b_size(self):
return getattr(self, "_b_size", self.collection_behavior.item_count)

def results(self, **kwargs):
"""Return a content listing based result set with results from the
collection query.

:param **kwargs: Any keyword argument, which can be used for catalog
queries.
:type **kwargs: keyword argument

:returns: plone.app.contentlisting based result set.
:rtype: ``plone.app.contentlisting.interfaces.IContentListing`` based
sequence.
"""
# Extra filter
contentFilter = dict(self.request.get("contentFilter", {}))
contentFilter.update(kwargs.get("contentFilter", {}))
kwargs.setdefault("custom_query", contentFilter)
kwargs.setdefault("batch", True)
kwargs.setdefault("b_size", self.b_size)
kwargs.setdefault("b_start", self.b_start)

results = self.collection_behavior.results(**kwargs)
return results

def batch(self):
# collection is already batched.
return self.results()

@property
@memoize
def _album_results(self):
"""Get results to display an album with subalbums."""
results = self.results()
images = []
folders = []
for it in results:
# TODO: potentially expensive!
ob = it.getObject()
if IFolder.providedBy(ob):
folders.append(it)
elif IImage.providedBy(ob) or ILeadImage.providedBy(ob):
images.append(it)
return {"images": images, "folders": folders}

@property
def album_images(self):
"""Get all images within this collection."""
return self._album_results["images"]

@property
def album_folders(self):
"""Get all folders within this collection."""
return self._album_results["folders"]

def tabular_fields(self):
"""Return a list of all metadata fields from the catalog that were
selected.
"""
context = aq_inner(self.context)
wrapped = ICollection(context)
fields = wrapped.selectedViewFields()
fields = [field[0] for field in fields]
return fields

@property
def no_items_message(self):
return _("description_no_results_found", default="No results were found.")
zope.deferredimport.deprecated(
"Please use from plone.app.layout.contenttypes.collection import CollectionView instead.",
CollectionView="plone.app.layout.contenttypes.collection:CollectionView",
)
16 changes: 16 additions & 0 deletions src/plone/app/contenttypes/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@

<include package="plone.app.contentmenu" />

<!-- The views below have been moved to
plone.app.layout.contenttypes (see
plone/app/layout/contenttypes/configure.zcml). They are kept here
commented out for reference; the Python classes remain importable
from this package via zope.deferredimport shims. -->

<!-- VIEWS FOR PLONE SITE ROOT -->
<!--
<browser:pages
for="plone.base.interfaces.IPloneSiteRoot"
class=".folder.FolderView"
Expand Down Expand Up @@ -45,9 +52,11 @@
title="Album view"
/>
</browser:pages>
-->


<!-- VIEWS FOR FOLDERS -->
<!--
<browser:pages
for="plone.dexterity.interfaces.IDexterityContainer"
class=".folder.FolderView"
Expand Down Expand Up @@ -84,21 +93,25 @@
title="Album view"
/>
</browser:pages>
-->


<!-- VIEWS FOR COLLECTION ITEM -->
<!--
<browser:page
name="listing_view"
for="plone.app.contenttypes.interfaces.ICollection"
class=".collection.CollectionView"
template="templates/listing.pt"
permission="zope2.View"
/>
-->

<!-- VIEWS FOR ANYTHING WITH THE COLLECTION BEHAVIOR.
Note that these ignore other fields, but integrators should
create other templates if they want that. Or improve the
query view widget. -->
<!--
<browser:pages
for="plone.app.contenttypes.behaviors.collection.ISyndicatableCollection"
class=".collection.CollectionView"
Expand Down Expand Up @@ -135,9 +148,11 @@
title="Album view"
/>
</browser:pages>
-->


<!-- OTHER VIEWS -->
<!--
<browser:page
name="full_view_item"
for="*"
Expand Down Expand Up @@ -222,5 +237,6 @@
provides="zope.schema.interfaces.IVocabularyFactory"
name="plone.app.contenttypes.migration.changed_base_classes"
/>
-->

</configure>
36 changes: 6 additions & 30 deletions src/plone/app/contenttypes/browser/file.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,9 @@
from plone.app.contenttypes.browser.utils import Utils
from plone.base.utils import human_readable_size
import zope.deferredimport

import re

zope.deferredimport.initialize()

class FileView(Utils):
def is_videotype(self):
ct = self.context.file.contentType
return "video/" in ct

def is_audiotype(self):
ct = self.context.file.contentType
return "audio/" in ct

def human_readable_size(self):
return human_readable_size(self.context.file.getSize())

def icon(self):
if "text" in self.context.file.contentType:
return "contenttype-text"
if "html" in self.context.file.contentType:
return "contenttype-text"
if re.search(r"(archive|zip|compressed)", self.context.file.contentType):
return "contenttype-archive"
if "audio" in self.context.file.contentType:
return "contenttype-audio"
if "video" in self.context.file.contentType:
return "contenttype-video"
if "pdf" in self.context.file.contentType:
return "contenttype-pdf"
else:
return "contenttype-file"
zope.deferredimport.deprecated(
"Please use from plone.app.layout.contenttypes.file import FileView instead.",
FileView="plone.app.layout.contenttypes.file:FileView",
)
Loading
Loading