Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WCM-614: Support manually creating video objects #985

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions core/docs/changelog/WCM-614.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WCM-614: Support manually creating video objects
3 changes: 1 addition & 2 deletions core/src/zeit/brightcove/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def __init__(self, base_url, policy_key, timeout):
self.timeout = timeout

def get_video(self, id):
data = {'renditions': (), 'video_still': None}
data = {'renditions': []}
try:
data.update(self._request('GET /videos/%s' % id))
except requests.exceptions.RequestException as e:
Expand All @@ -185,7 +185,6 @@ def get_video(self, id):
)
return data

data['video_still'] = data.get('poster')
data['renditions'] = []
for item in data.get('sources', ()):
vr = zeit.content.video.video.VideoRendition()
Expand Down
8 changes: 2 additions & 6 deletions core/src/zeit/brightcove/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def from_cms(cls, cmsobj):
custom['premoderate_comments'] = cls.bc_bool(cmsobj.commentsPremoderate)
custom['banner'] = cls.bc_bool(cmsobj.banner)
custom['banner_id'] = cmsobj.banner_id
custom['recensions'] = cls.bc_bool(cmsobj.has_recensions)
custom['produkt-id'] = cmsobj.product.id if cmsobj.product else None
custom['cmskeywords'] = ';'.join(x.code for x in cmsobj.keywords)
custom['ressort'] = cmsobj.ressort
Expand All @@ -115,7 +114,7 @@ def from_cms(cls, cmsobj):
)
custom['supertitle'] = cmsobj.supertitle
custom['credit'] = cmsobj.video_still_copyright
custom['type'] = cmsobj.type
custom['type'] = cmsobj.kind

related = zeit.cms.related.interfaces.IRelatedContent(cmsobj).related
for i in range(1, 6):
Expand Down Expand Up @@ -165,15 +164,12 @@ def apply_to_cms(self, cmsobj):
cmsobj.banner = self._default_if_missing(custom, 'banner', IVideo['banner'], self.cms_bool)
cmsobj.banner_id = custom.get('banner_id')
cmsobj.expires = self.cms_date((data.get('schedule') or {}).get('ends_at'))
cmsobj.has_recensions = self._default_if_missing(
custom, 'recensions', IVideo['has_recensions'], self.cms_bool
)
cmsobj.has_advertisement = data.get('economics') == 'AD_SUPPORTED'
cmsobj.ressort = custom.get('ressort')
cmsobj.serie = IVideo['serie'].source(None).find(custom.get('serie'))
cmsobj.supertitle = custom.get('supertitle')
cmsobj.video_still_copyright = custom.get('credit')
cmsobj.type = custom.get('type')
cmsobj.kind = custom.get('type')

product_source = IVideo['product'].source(cmsobj)
if not custom.get('produkt-id') and data.get('reference_id'):
Expand Down
2 changes: 0 additions & 2 deletions core/src/zeit/brightcove/tests/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,12 @@ def test_new_video_should_be_added_to_cms(self):

def test_new_video_should_create_still_image_group(self):
import_video(create_video())
assert self.repository['video']['2017-05']['myvid'].video_still is None
assert self.repository['video']['2017-05']['myvid-still'] is not None

def test_should_not_create_still_image_group_for_missing_src(self):
video = create_video()
del video.data['images']
import_video(video)
assert self.repository['video']['2017-05']['myvid'].video_still is None
assert self.repository['video']['2017-05'].get('myvid-still') is None

def test_changed_video_should_be_written_to_cms(self):
Expand Down
2 changes: 2 additions & 0 deletions core/src/zeit/brightcove/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,7 @@ def import_video_async(video_id):
def export_video(context, event):
if event.publishing or FEATURE_TOGGLES.find('video_disable_export_on_checkin'):
return
if context.type != 'brightcove':
return
session = zeit.brightcove.session.get()
session.update_video(zeit.brightcove.convert.Video.from_cms(context))
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""create index for video_type

Revision ID: 239e72a15c2c
Revises: b6c4f9badee3
Create Date: 2025-01-20 11:09:46.675290

"""

from typing import Sequence, Union

from alembic import op


# revision identifiers, used by Alembic.
revision: str = '239e72a15c2c'
down_revision: Union[str, None] = 'b6c4f9badee3'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
with op.get_context().autocommit_block():
op.create_index(
op.f('ix_properties_video_type'),
'properties',
['video_type'],
postgresql_concurrently=True,
if_not_exists=True,
)


def downgrade() -> None:
with op.get_context().autocommit_block():
op.drop_index(
op.f('ix_properties_video_type'),
'properties',
['video_type'],
postgresql_concurrently=True,
if_exists=True,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""add video_type column

Revision ID: f7f17b16292c
Revises: 0d681d9ffda0
Create Date: 2025-01-20 11:06:16.852051

"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = 'f7f17b16292c'
down_revision: Union[str, None] = '0d681d9ffda0'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
op.add_column('properties', sa.Column('video_type', sa.Unicode(), nullable=True))


def downgrade() -> None:
op.drop_column('properties', 'video_type')
4 changes: 4 additions & 0 deletions core/src/zeit/connector/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ class ContentTypes:
gallery_type = mapped_column(
Unicode, info={'namespace': 'zeit.content.gallery', 'name': 'type', 'migration': 'wcm_471'}
)
video_type = mapped_column(
Unicode, info={'namespace': 'video', 'name': 'type', 'migration': 'always'}
)


class Timestamps:
Expand Down Expand Up @@ -197,6 +200,7 @@ def __table_args__(cls):
'ressort',
'series',
'sub_ressort',
'video_type',
'volume_number',
'volume_year',
]
Expand Down
2 changes: 1 addition & 1 deletion core/src/zeit/content/article/edit/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Factory(zeit.content.article.edit.reference.ReferenceFactory):

@grok.adapter(
zeit.content.article.edit.interfaces.IArticleArea,
zeit.content.video.interfaces.IVideoContent,
zeit.content.video.interfaces.IVideo,
int,
)
@grok.implementer(zeit.edit.interfaces.IElement)
Expand Down
29 changes: 10 additions & 19 deletions core/src/zeit/content/video/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@
xmlns:browser="http://namespaces.zope.org/browser"
i18n_domain="zeit.cms">

<!-- video -->
<browser:page
for="zeit.cms.repository.interfaces.IFolder"
name="zeit.content.video.Add"
permission="zeit.AddContent"
class=".video.Add"
menu="zeit-add-menu" title="Video"
/>

<browser:page
for="..interfaces.IVideo"
layer="zeit.cms.browser.interfaces.ICMSLayer"
Expand All @@ -29,28 +36,12 @@
file="../resources/video_icon.gif"
/>

<browser:page
for="..interfaces.IVideo"
layer="zeit.cms.browser.interfaces.ICMSLayer"
name="preview"
class=".video.Still"
permission="zope.View"
/>

<adapter
for=".video.Still
zeit.cms.browser.interfaces.ICMSLayer"
provides="zope.traversing.browser.interfaces.IAbsoluteURL"
factory=".video.StillURL"
/>

<!-- common views -->

<browser:page
for="..interfaces.IVideo"
layer="zeit.cms.browser.interfaces.ICMSLayer"
name="object-details-body"
class=".details.Details"
class="zeit.cms.browser.objectdetails.Details"
template="object-details-body.pt"
permission="zope.View"
/>

Expand Down
20 changes: 0 additions & 20 deletions core/src/zeit/content/video/browser/details.py

This file was deleted.

1 change: 1 addition & 0 deletions core/src/zeit/content/video/browser/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# python package
47 changes: 47 additions & 0 deletions core/src/zeit/content/video/browser/tests/test_form.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import zeit.cms.testing
import zeit.content.video.testing
import zeit.content.video.video


class VideoFormTest(zeit.content.video.testing.BrowserTestCase):
def test_edit_video(self):
with zeit.cms.testing.site(self.getRootFolder()):
video = zeit.content.video.video.Video()
video.external_id = '1234'
self.repository['video'] = video

b = self.browser
b.open('http://localhost/repository/video')
b.getLink('Checkout').click()

b.getControl('Title').value = 'Video title'
b.getControl('Product').displayValue = ['Die Zeit']
b.getControl('Ressort').displayValue = ['Deutschland']
b.getControl(
name='form.keywords'
).value = '[{"code": "tag://test\\\\u2603Testtag", "pinned": false}]'
b.getControl('Apply').click()
self.assertEllipsis('...Updated on...', b.contents)

b.getLink('Checkin').click()
self.assertEllipsis('..."video" has been checked in...', b.contents)

def test_add_video(self):
b = self.browser
b.open('http://localhost/repository')
menu = b.getControl(name='add_menu')
menu.displayValue = ['Video']
b.open(menu.value[0])
self.assertEllipsis('...Add Video...', b.contents)
b.getControl('File name').value = 'myvideo'
b.getControl('Type').displayValue = ['Youtube']
b.getControl('Title').value = 'myvid'
b.getControl('External ID').value = '1234'
b.getControl('Ressort').displayValue = ['Deutschland']
b.getControl('Markdown content').value = '# my title'
b.getControl(name='form.actions.add').click()
self.assertEllipsis('...Edit Video...', b.contents)
b.getLink('Checkin').click()
self.assertEllipsis('..."myvideo" has been checked in...', b.contents)
self.assertEllipsis('...External ID...1234...', b.contents)
self.assertEllipsis('...<h1>my title</h1>...', b.contents)
Loading