本文整理汇总了Python中mediadrop.model.Media类的典型用法代码示例。如果您正苦于以下问题:Python Media类的具体用法?Python Media怎么用?Python Media使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Media类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: save_media_obj
def save_media_obj(self, name, email, title, description, tags, uploaded_file, url):
# create our media object as a status-less placeholder initially
media_obj = Media()
media_obj.author = Author(name, email)
media_obj.title = title
media_obj.slug = get_available_slug(Media, title)
media_obj.description = description
if request.settings['wording_display_administrative_notes']:
media_obj.notes = request.settings['wording_administrative_notes']
media_obj.set_tags(tags)
# Give the Media object an ID.
DBSession.add(media_obj)
DBSession.flush()
# Create a MediaFile object, add it to the media_obj, and store the file permanently.
media_file = add_new_media_file(media_obj, file=uploaded_file, url=url)
# The thumbs may have been created already by add_new_media_file
if not has_thumbs(media_obj):
create_default_thumbs_for(media_obj)
media_obj.update_status()
DBSession.flush()
return media_obj
开发者ID:anitahitouch,项目名称:mediadrop,代码行数:26,代码来源:upload.py
示例2: setUp
def setUp(self):
super(FilteringRestrictedItemsTest, self).setUp()
# without explicit re-registration of the default policy unit tests
# failed when running 'python setup.py test'
self._register_default_policy()
# get rid of default media
Media.query.delete()
self.private_media = Media.example(slug=u"private")
self.public_media = Media.example(slug=u"public")
self.permission_system = MediaDropPermissionSystem(self.pylons_config)
self.media_query = Media.query
user = self._create_user_without_groups()
self.perm = UserPermissions(user, self.permission_system)
开发者ID:njZhuMin,项目名称:mediacore-community,代码行数:14,代码来源:filtering_restricted_items_test.py
示例3: test_sets_video_type_if_media_contains_audio_and_video_files
def test_sets_video_type_if_media_contains_audio_and_video_files(self):
media = Media.example()
assert_none(media.type)
self.add_external_file(media, 'mp4')
self.add_external_file(media, 'mp3')
media.update_status()
assert_equals(VIDEO, media.type, message='did not detect mixed video/audio media as VIDEO type')
开发者ID:SmallsLIVE,项目名称:mediadrop,代码行数:7,代码来源:media_status_test.py
示例4: test_does_not_set_type_if_only_audio_description_files_are_attached
def test_does_not_set_type_if_only_audio_description_files_are_attached(self, suffix):
media = Media.example()
assert_none(media.type)
media_file = self.add_external_file(media, suffix)
media_file.type = AUDIO_DESC
media.update_status()
assert_none(media.type, message='did detect media with audio description file as %s' % media.type)
开发者ID:SmallsLIVE,项目名称:mediadrop,代码行数:7,代码来源:media_status_test.py
示例5: save_thumb
def save_thumb(self, id, thumb, **kwargs):
"""Save a thumbnail uploaded with :class:`~mediadrop.forms.admin.ThumbForm`.
:param id: Media ID. If ``"new"`` a new Media stub is created.
:type id: ``int`` or ``"new"``
:param file: The uploaded file
:type file: :class:`cgi.FieldStorage` or ``None``
:rtype: JSON dict
:returns:
success
bool
message
Error message, if unsuccessful
id
The :attr:`~mediadrop.model.media.Media.id` which is
important if a new media has just been created.
"""
if id == 'new':
media = Media()
user = request.perm.user
media.author = Author(user.display_name, user.email_address)
media.title = os.path.basename(thumb.filename)
media.slug = get_available_slug(Media, '_stub_' + media.title)
DBSession.add(media)
DBSession.flush()
else:
media = fetch_row(Media, id)
try:
# Create JPEG thumbs
create_thumbs_for(media, thumb.file, thumb.filename)
success = True
message = None
except IOError, e:
success = False
if id == 'new':
DBSession.delete(media)
if e.errno == 13:
message = _('Permission denied, cannot write file')
elif e.message == 'cannot identify image file':
message = _('Unsupported image type: %s') \
% os.path.splitext(thumb.filename)[1].lstrip('.')
elif e.message == 'cannot read interlaced PNG files':
message = _('Interlaced PNGs are not supported.')
else:
raise
开发者ID:knyar,项目名称:mediadrop,代码行数:47,代码来源:media.py
示例6: setUp
def setUp(self):
super(MediaStatusUpdatesTypeTest, self).setUp()
# prevent warning about missing handlers for logger
# "mediadrop.model.players" ("fetch_enabled_players()")
self.init_flowplayer()
# required because "media.update_status()" will query
# "registered_media_types()" which in turn calls "register_default_types()"
# and then we need a translator (e.g. "_('Video')").
paste_registry = self.pylons_config['paste.registry']
setup_global_translator(registry=paste_registry)
self.media = Media.example()
开发者ID:MatrixFrog,项目名称:mediadrop,代码行数:11,代码来源:media_status_test.py
示例7: test_can_create_example_media
def test_can_create_example_media(self):
media = Media.example()
assert_not_none(media.id)
assert_equals(u'Foo Media', media.title)
assert_equals(u'foo-media', media.slug)
assert_equals(Author(u'Joe', u'[email protected]'), media.author)
assert_length(0, media.files)
assert_none(media.type)
assert_none(media.podcast_id)
assert_false(media.publishable)
assert_false(media.reviewed)
assert_false(media.encoded)
assert_none(media.publish_on)
assert_none(media.publish_until)
assert_false(media.is_published)
开发者ID:SmallsLIVE,项目名称:mediadrop,代码行数:18,代码来源:media_example_test.py
示例8: add_file
def add_file(self, id, file=None, url=None, **kwargs):
"""Save action for the :class:`~mediadrop.forms.admin.media.AddFileForm`.
Creates a new :class:`~mediadrop.model.media.MediaFile` from the
uploaded file or the local or remote URL.
:param id: Media ID. If ``"new"`` a new Media stub is created.
:type id: :class:`int` or ``"new"``
:param file: The uploaded file
:type file: :class:`cgi.FieldStorage` or ``None``
:param url: A URL to a recognizable audio or video file
:type url: :class:`unicode` or ``None``
:rtype: JSON dict
:returns:
success
bool
message
Error message, if unsuccessful
media_id
The :attr:`~mediadrop.model.media.Media.id` which is
important if new media has just been created.
file_id
The :attr:`~mediadrop.model.media.MediaFile.id` for the newly
created file.
edit_form
The rendered XHTML :class:`~mediadrop.forms.admin.media.EditFileForm`
for this file.
status_form
The rendered XHTML :class:`~mediadrop.forms.admin.media.UpdateStatusForm`
"""
if id == 'new':
media = Media()
user = request.perm.user
media.author = Author(user.display_name, user.email_address)
# Create a temp stub until we can set it to something meaningful
timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
media.title = u'Temporary stub %s' % timestamp
media.slug = get_available_slug(Media, '_stub_' + timestamp)
media.reviewed = True
DBSession.add(media)
DBSession.flush()
else:
media = fetch_row(Media, id)
try:
media_file = add_new_media_file(media, file, url)
except UserStorageError as e:
return dict(success=False, message=e.message)
if media.slug.startswith('_stub_'):
media.title = media_file.display_name
media.slug = get_available_slug(Media, '_stub_' + media.title)
# The thumbs may have been created already by add_new_media_file
if id == 'new' and not has_thumbs(media):
create_default_thumbs_for(media)
media.update_status()
# Render some widgets so the XHTML can be injected into the page
edit_form_xhtml = unicode(edit_file_form.display(
action=url_for(action='edit_file', id=media.id),
file=media_file))
status_form_xhtml = unicode(update_status_form.display(
action=url_for(action='update_status', id=media.id),
media=media))
data = dict(
success = True,
media_id = media.id,
file_id = media_file.id,
file_type = media_file.type,
edit_form = edit_form_xhtml,
status_form = status_form_xhtml,
title = media.title,
slug = media.slug,
description = media.description,
link = url_for(action='edit', id=media.id),
duration = helpers.duration_from_seconds(media.duration),
)
return data
开发者ID:knyar,项目名称:mediadrop,代码行数:82,代码来源:media.py
示例9: add_default_data
def add_default_data():
log.info('Adding default data')
settings = [
(u'email_media_uploaded', None),
(u'email_comment_posted', None),
(u'email_support_requests', None),
(u'email_send_from', u'[email protected]'),
(u'wording_user_uploads', N_(u"Upload your media using the form below. We'll review it and get back to you.")),
(u'wording_administrative_notes', None),
(u'wording_display_administrative_notes', u''),
(u'popularity_decay_exponent', u'4'),
(u'popularity_decay_lifetime', u'36'),
(u'rich_text_editor', u'tinymce'),
(u'google_analytics_uacct', u''),
(u'featured_category', u'1'),
(u'max_upload_size', u'314572800'),
(u'ftp_storage', u'false'),
(u'ftp_server', u'ftp.someserver.com'),
(u'ftp_user', u'username'),
(u'ftp_password', u'password'),
(u'ftp_upload_directory', u'media'),
(u'ftp_download_url', u'http://www.someserver.com/web/accessible/media/'),
(u'ftp_upload_integrity_retries', u'10'),
(u'akismet_key', u''),
(u'akismet_url', u''),
(u'req_comment_approval', u''),
(u'use_embed_thumbnails', u'true'),
(u'api_secret_key_required', u'true'),
(u'api_secret_key', random_string(20)),
(u'api_media_max_results', u'50'),
(u'api_tree_max_depth', u'10'),
(u'general_site_name', u'MediaDrop'),
(u'general_site_title_display_order', u'prepend'),
(u'sitemaps_display', u'True'),
(u'rss_display', u'True'),
(u'vulgarity_filtered_words', u''),
(u'primary_language', u'en'),
(u'advertising_banner_html', u''),
(u'advertising_sidebar_html', u''),
(u'comments_engine', u'builtin'),
(u'facebook_appid', u''),
(u'youtube_apikey', u''),
]
settings.extend(appearance_settings)
for key, value in settings:
s = Setting()
s.key = key
s.value = value
DBSession.add(s)
admin_user = User()
admin_user.user_name = u'admin'
admin_user.display_name = u'Admin'
admin_user.email_address = u'[email protected]'
admin_user.password = u'admin'
DBSession.add(admin_user)
admin_group = Group(name=u'admins', display_name=u'Admins')
admin_group.users.append(admin_user)
DBSession.add(admin_group)
editor_group = Group(name=u'editors', display_name=u'Editors')
DBSession.add(editor_group)
anonymous_group = Group(name=u'anonymous', display_name=u'Everyone (including guests)')
DBSession.add(anonymous_group)
authenticated_group = Group(name=u'authenticated', display_name=u'Logged in users')
DBSession.add(authenticated_group)
admin_perm = Permission(name=u'admin', groups=[admin_group],
description=u'Grants access to the admin panel')
DBSession.add(admin_perm)
edit_perm = Permission(name=u'edit', groups=[admin_group, editor_group],
description=u'Grants access to edit site content')
DBSession.add(edit_perm)
view_perm = Permission(name=u'view',
groups=[admin_group, anonymous_group, editor_group],
description=u'View published media')
DBSession.add(view_perm)
upload_perm = Permission(name=u'upload',
groups=[admin_group, anonymous_group, editor_group],
description=u'Can upload new media')
DBSession.add(upload_perm)
media_upload_perm = Permission()
media_upload_perm.permission_name = u'MEDIA_UPLOAD'
media_upload_perm.description = u'Grants the ability to upload new media'
media_upload_perm.groups.append(admin_group)
media_upload_perm.groups.append(editor_group)
media_upload_perm.groups.append(anonymous_group)
DBSession.add(edit_perm)
category = Category(name=u'Featured', slug=u'featured')
DBSession.add(category)
#.........这里部分代码省略.........
开发者ID:mkrysiak,项目名称:mediadrop,代码行数:101,代码来源:websetup.py
示例10: setUp
def setUp(self):
super(MediaTest, self).setUp()
setup_global_translator(registry=self.paste_registry)
self.init_flowplayer()
self.media = Media.example()
self.encoding_event = self.create_spy_on_event(events.Media.encoding_done)
开发者ID:hotbaby,项目名称:mediadrop,代码行数:6,代码来源:media_test.py
示例11: test_does_not_set_type_if_only_caption_files_are_attached
def test_does_not_set_type_if_only_caption_files_are_attached(self, suffix):
media = Media.example()
assert_none(media.type)
self.add_external_file(media, suffix)
media.update_status()
assert_none(media.type, message='did detect media with caption file as %s' % media.type)
开发者ID:SmallsLIVE,项目名称:mediadrop,代码行数:6,代码来源:media_status_test.py
示例12: test_can_detect_audio_files
def test_can_detect_audio_files(self, suffix):
media = Media.example()
assert_not_equals(AUDIO, media.type)
self.add_external_file(media, suffix)
media.update_status()
assert_equals(AUDIO, media.type, message='did not detect %s as AUDIO type' % suffix)
开发者ID:SmallsLIVE,项目名称:mediadrop,代码行数:6,代码来源:media_status_test.py
示例13: setUp
def setUp(self):
super(MediaStatusUpdatesTypeTest, self).setUp()
# prevent warning about missing handlers for logger
# "mediadrop.model.players" ("fetch_enabled_players()")
self.init_flowplayer()
self.media = Media.example()
开发者ID:SmallsLIVE,项目名称:mediadrop,代码行数:6,代码来源:media_status_test.py
示例14: setUp
def setUp(self):
super(MediaTest, self).setUp()
self.init_flowplayer()
self.media = Media.example()
self.encoding_event = self.create_spy_on_event(events.Media.encoding_done)
开发者ID:SmallsLIVE,项目名称:mediadrop,代码行数:5,代码来源:media_test.py
示例15: _new_publishable_media
def _new_publishable_media(self, slug, name):
from datetime import datetime
from mediadrop.model import Author, Media
media = Media()
media.slug = slug
media.title = name
media.subtitle = None
media.description = u"""<p>Description</p>"""
media.description_plain = u"""Description"""
media.author = Author(u'fake name', u'[email protected]')
media.publish_on = datetime.now()
media.publishable = True
media.reviewed = True
media.encoded = False
media.type = None
return media
开发者ID:FelixSchwarz,项目名称:mediadrop-test-renames,代码行数:16,代码来源:__init__.py
示例16: test_can_override_example_data
def test_can_override_example_data(self):
media = Media.example(title=u'Bar Foo')
assert_equals(u'Bar Foo', media.title)
assert_equals(u'bar-foo', media.slug)
开发者ID:SmallsLIVE,项目名称:mediadrop,代码行数:5,代码来源:media_example_test.py
注:本文中的mediadrop.model.Media类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论