Repository: plone/plone.app.contenttypes (language: python)

Issue:
Folder listing template breaks when `IEvent` types do not have enabled `plone.eventlocation` behavior
Traceback: 

```
Traceback (innermost last):
  Module ZPublisher.WSGIPublisher, line 181, in transaction_pubevents
  Module ZPublisher.WSGIPublisher, line 391, in publish_module
  Module ZPublisher.WSGIPublisher, line 285, in publish
  Module ZPublisher.mapply, line 98, in mapply
  Module ZPublisher.WSGIPublisher, line 68, in call_object
  Module zope.browserpage.simpleviewclass, line 44, in __call__
  Module Products.Five.browser.pagetemplatefile, line 126, in __call__
  Module Products.Five.browser.pagetemplatefile, line 58, in __call__
  Module zope.pagetemplate.pagetemplate, line 134, in pt_render
  Module Products.PageTemplates.engine, line 365, in __call__
  Module z3c.pt.pagetemplate, line 174, in render
  Module chameleon.zpt.template, line 298, in render
  Module chameleon.template, line 214, in render
  Module chameleon.utils, line 20, in raise_with_traceback
  Module chameleon.template, line 190, in render
  Module 9edadc7782a902d9f652f1c6c7e286c8, line 685, in render
  Module 6ab735cd1c0818fcceb8ee219f65b652, line 930, in render_master
  Module 6ab735cd1c0818fcceb8ee219f65b652, line 1553, in render_content
  Module 9edadc7782a902d9f652f1c6c7e286c8, line 670, in __fill_content_core
  Module 9edadc7782a902d9f652f1c6c7e286c8, line 422, in render_content_core
  Module fa298f6a886a10422550b2a87f682427, line 121, in render_content_core
  Module fa298f6a886a10422550b2a87f682427, line 504, in render_listing
  Module 9edadc7782a902d9f652f1c6c7e286c8, line 395, in __fill_entries
  Module fa298f6a886a10422550b2a87f682427, line 980, in render_entries
  Module 9edadc7782a902d9f652f1c6c7e286c8, line 213, in __fill_entry
  Module fa298f6a886a10422550b2a87f682427, line 1418, in render_document_byline
  Module zope.tales.pythonexpr, line 73, in __call__
   - __traceback_info__: (obj.location)
  Module <string>, line 1, in <module>
AttributeError: 'RequestContainer' object has no attribute 'location'

 - Expression: "python:obj.location"
 - Filename:   ... ages/plone/app/contenttypes/browser/templates/listing.pt
 - Location:   (line 96: col 53)
 - Source:     <span tal:condition="python:obj.location"
                                    ^^^^^^^^^^^^^^^^^^^
 - Expression: "tem_type_class python:('contenttype-' + view.normalizeString(item_type)) if sh"
 - Filename:   ... ages/plone/app/contenttypes/browser/templates/listing.pt
 - Location:   (line 69: col 32)
 - Source:     ... tem_type_class python:('contenttype-' + view.normalizeString(item_type)) if sh ...
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 - Expression: "python:batch"
 - Filename:   ... ages/plone/app/contenttypes/browser/templates/listing.pt
 - Location:   (line 41: col 36)
 - Source:     <tal:listing condition="python:batch">
                                       ^^^^^^^^^^^^
 - Expression: "context/@@listing_view/macros/content-core"
 - Filename:   ... ne/app/contenttypes/browser/templates/listing_summary.pt
 - Location:   (line 15: col 32)
 - Source:     ... use-macro="context/@@listing_view/macros/content-core">
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 - Expression: "provider:plone.abovecontentbody"
 - Filename:   ... ges/Products/CMFPlone/browser/templates/main_template.pt
 - Location:   (line 107: col 74)
 - Source:     ... ontent="structure provider:plone.abovecontentbody" />
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 - Expression: "context/@@main_template/macros/master"
 - Filename:   ... ne/app/contenttypes/browser/templates/listing_summary.pt
 - Location:   (line 6: col 23)
 - Source:     ... tal:use-macro="context/@@main_template/macros/master"
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 - Arguments:  template: <Products.Five.browser.pagetemplatefile.ViewPageTemplateFile object at 0x7efeedc8ce10>
               options: {}
               args: ()
               nothing: None
               modules: <Products.PageTemplates.ZRPythonExpr._SecureModuleImporter object at 0x7efef1b2f2d0>
               request: <WSGIRequest, URL=https://classic.demo.plone.org/en/demo/summary_view>
               view: <Products.Five.browser.metaconfigure.SimpleViewClass from /app/lib/python3.11/site-packages/plone/app/contenttypes/browser/templates/listing_summary.pt object at 0x7efeee764050>
               context: <Folder at /Plone/en/demo>
               views: <Products.Five.browser.pagetemplatefile.ViewMapper object at 0x7efeed9bc850>
               here: <Folder at /Plone/en/demo>
               container: <Folder at /Plone/en/demo>
               root: <Application at >
               traverse_subpath: []
               user: <PropertiedUser 'admin'>
               default: <DEFAULT>
               repeat: <Products.PageTemplates.engine.RepeatDictWrapper object at 0x7efee954af30>
               loop: {'item': <Products.PageTemplates.engine.RepeatItem object at 0x7efee961d9d0>}
               target_language: None
               translate: <function BaseTemplate.render.<locals>.translate at 0x7efee9c19940>
               macroname: 'master'
               attrs: {}
```


Discussion / hints:

Fix patch:
diff --git a/news/679.bugfix b/news/679.bugfix
new file mode 100644
index 00000000..56ae4847
--- /dev/null
+++ b/news/679.bugfix
@@ -0,0 +1,2 @@
+Fix folder listing template when `plone.eventlocation` behavior is disabled for Events.
+[petschki]
diff --git a/plone/app/contenttypes/browser/templates/listing.pt b/plone/app/contenttypes/browser/templates/listing.pt
index 9e2d7553..9ad3df22 100644
--- a/plone/app/contenttypes/browser/templates/listing.pt
+++ b/plone/app/contenttypes/browser/templates/listing.pt
@@ -93,7 +93,7 @@
 
                               <tal:event condition="python:item_is_event">
                                 <tal:date tal:replace="structure python:view.formatted_date(obj)" />
-                                <span tal:condition="python:obj.location"
+                                <span tal:condition="python:getattr(obj.aq_base, 'location', None)"
                                       i18n:translate="label_event_byline_location"
                                 >
                             &mdash;


Test patch:
diff --git a/plone/app/contenttypes/tests/test_folder.py b/plone/app/contenttypes/tests/test_folder.py
index 440eb6c2..47c048f5 100644
--- a/plone/app/contenttypes/tests/test_folder.py
+++ b/plone/app/contenttypes/tests/test_folder.py
@@ -1,3 +1,5 @@
+from datetime import datetime
+from datetime import timedelta
 from plone.app.contenttypes.browser.folder import FolderView
 from plone.app.contenttypes.interfaces import IFolder
 from plone.app.contenttypes.testing import (  # noqa
@@ -232,3 +234,26 @@ def test_list_item_wout_title(self):
         # And also in tabular view
         self.browser.open(self.folder_url + "/tabular_view")
         self.assertIn("doc_wout_title", self.browser.contents)
+
+    def test_event_wout_location(self):
+        # deactivate "plone.eventlocation" from Event behaviors
+        event_fti = self.portal.portal_types.get("Event")
+        if not event_fti:
+            return
+        event_behaviors = list(event_fti.behaviors)
+        event_behaviors.remove("plone.eventlocation")
+        event_fti.behaviors = tuple(event_behaviors)
+
+        self.folder.invokeFactory(
+            "Event",
+            id="event_wout_location",
+            title="Event without location",
+            start=datetime.now() + timedelta(days=1),
+        )
+
+        import transaction
+
+        transaction.commit()
+
+        self.browser.open(self.folder_url + "/listing_view")
+        self.assertIn("Event without location", self.browser.contents)