<commit_before>===========
Syndication
===========

If objects which are adaptable to IImages are syndicated, the first image will
be added to the feed[#functional]_.

Get a content from the repository:

>>> import zope.component
>>> import zeit.cms.repository.interfaces
>>> repository = zope.component.getUtility(
...     zeit.cms.repository.interfaces.IRepository)
>>> content = repository['testcontent']

Also create a feed:

>>> import zeit.cms.syndication.feed
>>> feed = zeit.cms.syndication.feed.Feed()

Insert content to the feed:

>>> feed.insert(0, content)

We have not added any image, so no image is referenced:

>>> print feed.xml_source
<channel xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:py="http://codespeak.net/lxml/objectify/pytype">
  <title/>
  <container>
    <block href="http://xml.zeit.de/testcontent"...>
      ...
      <title xsi:nil="true"/>
      ...
    </block>
  </container>
  <object_limit>50</object_limit>
</channel>


We will mostly want to reference image groups, so create one first:

>>> import zeit.content.image.testing
>>> group = zeit.content.image.testing.create_image_group()

Reference the image group[#needsinteraction]_:

>>> import zeit.cms.content.interfaces
>>> import zeit.cms.checkout.interfaces
>>> import zeit.content.image.interfaces
>>> checked_out = zeit.cms.checkout.interfaces.ICheckoutManager(
...     content).checkout()
>>> images = zeit.content.image.interfaces.IImages(checked_out)
>>> images.image = group
>>> content = zeit.cms.checkout.interfaces.ICheckinManager(
...     checked_out).checkin()

Update the metadata of the feed. The image is now referenced:

>>> feed.updateMetadata(content)
>>> print feed.xml_source
<channel xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:py="http://codespeak.net/lxml/objectify/pytype">
  <title/>
  <container>
    <block href="http://xml.zeit.de/testcontent"...>
     ...
      <image base-id="http://xml.zeit.de/image-group/" type="jpg"...>
        <bu xsi:nil="true"/>
        <copyright py:pytype="str">&#169;</copyright>
      </image>
    </block>
  </container>
  <object_limit>50</object_limit>
</channel>


When we have no image referenced it is also removed from the channel:

>>> checked_out = zeit.cms.checkout.interfaces.ICheckoutManager(
...     content).checkout()
>>> images = zeit.content.image.interfaces.IImages(checked_out)
>>> images.image = None
>>> content = zeit.cms.checkout.interfaces.ICheckinManager(
...     checked_out).checkin()
>>> feed.updateMetadata(content)
>>> print feed.xml_source,
<channel xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:py="http://codespeak.net/lxml/objectify/pytype">
  <title/>
  <container>
    <block href="http://xml.zeit.de/testcontent"...>
      ...
    </block>
  </container>
  <object_limit>50</object_limit>
</channel>


When we change the metadata of the imagegroup the content is updated on
checkin of the imagegroup. Change the metadata of the group.

Before:

>>> checked_out = zeit.cms.checkout.interfaces.ICheckoutManager(
...     content).checkout()
>>> images = zeit.content.image.interfaces.IImages(checked_out)
>>> images.image = group
>>> content = zeit.cms.checkout.interfaces.ICheckinManager(
...     checked_out).checkin()
>>> import lxml.etree
>>> print lxml.etree.tostring(repository['testcontent'].xml, pretty_print=True)
<testtype>
  <head>
    <image ...base-id="http://xml.zeit.de/image-group/"
        type="jpg"...>
      <bu xsi:nil="true"/>
      <copyright py:pytype="str">&#169;</copyright>
    </image>
    ...
  </head>
  <body/>
</testtype>

Now check out, change title and check in:

>>> checked_out = zeit.cms.checkout.interfaces.ICheckoutManager(
...     group).checkout()
>>> metadata = zeit.content.image.interfaces.IImageMetadata(checked_out)
>>> metadata.title = u"Image title"
>>> group = zeit.cms.checkout.interfaces.ICheckinManager(checked_out).checkin()
>>> import transaction
>>> transaction.commit()

The content has changed automatically:

>>> print lxml.etree.tostring(
...     repository['testcontent'].xml, pretty_print=True),
<testtype>
  <head>
    <image ...base-id="http://xml.zeit.de/image-group/" type="jpg"...
        title="Image title"...>
      <bu xsi:nil="true"/>
      <copyright py:pytype="str">&#169;</copyright>
    </image>
    ...
  </head>
  <body/>
</testtype>


When a referenfced image group looses its type, the updater doesn't puke:

>>> import zeit.connector.interfaces
>>> connector = zope.component.getUtility(zeit.connector.interfaces.IConnector)
>>> connector.changeProperties(
...     'http://xml.zeit.de/image-group', {
...     zeit.connector.interfaces.RESOURCE_TYPE_PROPERTY: 'folder'})
>>> feed.updateMetadata(repository['testcontent'])
Traceback (most recent call last):
    ...
ValueError: Could not create xml reference 'image'
    for http://xml.zeit.de/image-group/
    which is referenced in http://xml.zeit.de/testcontent.


Reference index
===============

When an image is related to another object this is indexed. We can find this
out via the relations utility:

>>> import zeit.cms.relation.interfaces<commit_msg>ZON-2855: Remove test after metadata update on checkin has been removed in zeit.cms 1dd17e4<commit_after>===========
Syndication
===========

If objects which are adaptable to IImages are syndicated, the first image will
be added to the feed[#functional]_.

Get a content from the repository:

>>> import zope.component
>>> import zeit.cms.repository.interfaces
>>> repository = zope.component.getUtility(
...     zeit.cms.repository.interfaces.IRepository)
>>> content = repository['testcontent']

Also create a feed:

>>> import zeit.cms.syndication.feed
>>> feed = zeit.cms.syndication.feed.Feed()

Insert content to the feed:

>>> feed.insert(0, content)

We have not added any image, so no image is referenced:

>>> print feed.xml_source
<channel xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:py="http://codespeak.net/lxml/objectify/pytype">
  <title/>
  <container>
    <block href="http://xml.zeit.de/testcontent"...>
      ...
      <title xsi:nil="true"/>
      ...
    </block>
  </container>
  <object_limit>50</object_limit>
</channel>


We will mostly want to reference image groups, so create one first:

>>> import zeit.content.image.testing
>>> group = zeit.content.image.testing.create_image_group()

Reference the image group[#needsinteraction]_:

>>> import zeit.cms.content.interfaces
>>> import zeit.cms.checkout.interfaces
>>> import zeit.content.image.interfaces
>>> checked_out = zeit.cms.checkout.interfaces.ICheckoutManager(
...     content).checkout()
>>> images = zeit.content.image.interfaces.IImages(checked_out)
>>> images.image = group
>>> content = zeit.cms.checkout.interfaces.ICheckinManager(
...     checked_out).checkin()

Update the metadata of the feed. The image is now referenced:

>>> feed.updateMetadata(content)
>>> print feed.xml_source
<channel xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:py="http://codespeak.net/lxml/objectify/pytype">
  <title/>
  <container>
    <block href="http://xml.zeit.de/testcontent"...>
     ...
      <image base-id="http://xml.zeit.de/image-group/" type="jpg"...>
        <bu xsi:nil="true"/>
        <copyright py:pytype="str">&#169;</copyright>
      </image>
    </block>
  </container>
  <object_limit>50</object_limit>
</channel>


When we have no image referenced it is also removed from the channel:

>>> checked_out = zeit.cms.checkout.interfaces.ICheckoutManager(
...     content).checkout()
>>> images = zeit.content.image.interfaces.IImages(checked_out)
>>> images.image = None
>>> content = zeit.cms.checkout.interfaces.ICheckinManager(
...     checked_out).checkin()
>>> feed.updateMetadata(content)
>>> print feed.xml_source,
<channel xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:py="http://codespeak.net/lxml/objectify/pytype">
  <title/>
  <container>
    <block href="http://xml.zeit.de/testcontent"...>
      ...
    </block>
  </container>
  <object_limit>50</object_limit>
</channel>


When a referenfced image group looses its type, the updater doesn't puke:

>>> checked_out = zeit.cms.checkout.interfaces.ICheckoutManager(
...     content).checkout()
>>> images = zeit.content.image.interfaces.IImages(checked_out)
>>> images.image = group
>>> content = zeit.cms.checkout.interfaces.ICheckinManager(
...     checked_out).checkin()
>>> import transaction
>>> transaction.commit()
>>> import zeit.connector.interfaces
>>> connector = zope.component.getUtility(zeit.connector.interfaces.IConnector)
>>> connector.changeProperties(
...     'http://xml.zeit.de/image-group', {
...     zeit.connector.interfaces.RESOURCE_TYPE_PROPERTY: 'folder'})
>>> feed.updateMetadata(repository['testcontent'])
Traceback (most recent call last):
    ...
ValueError: Could not create xml reference 'image'
    for http://xml.zeit.de/image-group/
    which is referenced in http://xml.zeit.de/testcontent.


Reference index
===============

When an image is related to another object this is indexed. We can find this
out via the relations utility:

>>> import zeit.cms.relation.interfaces
{'fraction_non_alphanumeric': 0.16852737905369483, 'fraction_numerical': 0.009994683678894205, 'mean_word_length': 4.067887931034483, 'pattern_counts': {'":': 0, '<': 89, '<?xml version=': 0, '>': 326, 'https://': 0, 'lorem ipsum': 0, 'www.': 12, 'xml': 53}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4924288', 'n_tokens_mistral': 3138, 'n_tokens_neox': 2995, 'n_words': 620}