当前位置: 首页>>代码示例>>Python>>正文


Python model.get_available_slug函数代码示例

本文整理汇总了Python中mediacore.model.get_available_slug函数的典型用法代码示例。如果您正苦于以下问题:Python get_available_slug函数的具体用法?Python get_available_slug怎么用?Python get_available_slug使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_available_slug函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _import_video

 def _import_video(self, entry):
     player_url = self._player_url_from_entry(entry)
     if not player_url:
         log.debug('Video Feed Error: No player URL? %s' % entry)
         return None
     if self._has_media_file_for(player_url):
         return None
     
     media = fetch_row(Media, u'new')
     media.author = Author(self.user.display_name, self.user.email_address)
     media.reviewed = True
     media.title = unicode(entry.media.title.text, "utf-8")
     if entry.media.description.text:
         encoded_description = unicode(entry.media.description.text, "utf-8")
         media.description = clean_xhtml(encoded_description)
     media.slug = get_available_slug(Media, media.title, media)
     
     if self.tags:
         media.set_tags(unicode(self.tags))
     if self.categories:
         media.set_categories(self.categories)
     try:
         media_file = add_new_media_file(media, url=player_url)
     except StorageError, e:
         log.debug('Video Feed Error: Error storing video: %s at %s' \
             % (e.message, player_url))
         return None
开发者ID:mediadrop,项目名称:youtube-import-plugin,代码行数:27,代码来源:core.py

示例2: save

    def save(self, id, delete, category='topics', **kwargs):
        """Save changes or create a topic or tag.

        See :class:`~mediacore.forms.categories.EditCategoryForm` for POST vars.

        :param id: Topic or tag ID
        :param category: ``topics`` or ``tags``
        :param delete: If true the category is deleted rather than saved.
        :type delete: bool
        :rtype: JSON dict
        :returns:
            success
                bool
            category
                ``topics`` or ``tags``

        """
        model = self.select_model(category)
        item = fetch_row(model, id)

        if delete:
            DBSession.delete(item)
            item = None
        else:
            item.name = kwargs['name']
            item.slug = get_available_slug(model, kwargs['slug'], item)

            DBSession.add(item)

        if request.is_xhr:
            return dict(success=True, category=item)
        else:
            redirect(action='index', category=category)
开发者ID:SergeyLashin,项目名称:mediacore,代码行数:33,代码来源:categoryadmin.py

示例3: 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:AshKash,项目名称:mediacore-community,代码行数:26,代码来源:upload.py

示例4: save

    def save(self, id, delete=None, **kwargs):
        """Save changes or create a category.

        See :class:`~mediacore.forms.admin.settings.categories.CategoryForm` for POST vars.

        :param id: Category ID
        :param delete: If true the category is to be deleted rather than saved.
        :type delete: bool
        :rtype: JSON dict
        :returns:
            success
                bool

        """
        if tmpl_context.form_errors:
            if request.is_xhr:
                return dict(success=False, errors=tmpl_context.form_errors)
            else:
                # TODO: Add error reporting for users with JS disabled?
                return redirect(action="edit")

        cat = fetch_row(Category, id)

        if delete:
            DBSession.delete(cat)
            data = dict(success=True, id=cat.id, parent_options=unicode(category_form.c["parent_id"].display()))
        else:
            cat.name = kwargs["name"]
            cat.slug = get_available_slug(Category, kwargs["slug"], cat)

            if kwargs["parent_id"]:
                parent = fetch_row(Category, kwargs["parent_id"])
                if parent is not cat and cat not in parent.ancestors():
                    cat.parent = parent
            else:
                cat.parent = None

            DBSession.add(cat)
            DBSession.flush()

            data = dict(
                success=True,
                id=cat.id,
                name=cat.name,
                slug=cat.slug,
                parent_id=cat.parent_id,
                parent_options=unicode(category_form.c["parent_id"].display()),
                depth=cat.depth(),
                row=unicode(
                    category_row_form.display(
                        action=url_for(id=cat.id), category=cat, depth=cat.depth(), first_child=True
                    )
                ),
            )

        if request.is_xhr:
            return data
        else:
            redirect(action="index", id=None)
开发者ID:kiberpipa,项目名称:mediacore,代码行数:59,代码来源:categories.py

示例5: podcast_from_feed

def podcast_from_feed(d, tags=False, save_files=False):
    # Assume not explicit
    explicit = False
    if 'itunes_explicit' in d['feed']:
        explicit = bool(d['feed']['itunes_explicit'])

    image = None
    if 'image' in d['feed']:
        image = d['feed']['image']['href']

    title = u''
    if 'title' in d['feed']:
        title = d['feed']['title']

    description = u''
    if 'summary' in d['feed']:
        description = d['feed']['summary']

    subtitle = u''
    if 'subtitle' in d['feed']:
        subtitle = d['feed']['subtitle']

    slug = slugify(title)
    author_name = u"PLACEHOLDER NAME"
    author_email = u"[email protected]"

    podcast = Podcast()
    podcast.slug = get_available_slug(Podcast, slug, podcast)
    podcast.title = title
    podcast.subtitle = subtitle
    podcast.author = Author(author_name, author_email)
    podcast.description = description
    podcast.explicit = explicit

    DBSession.add(podcast)
    DBSession.flush()

    # Create thumbs from image, or default thumbs
    created_images = False
    if image:
        temp_imagefile = tempfile.TemporaryFile()
        imagefile = urllib2.urlopen(image)
        temp_imagefile.write(imagefile.read())
        temp_imagefile.seek(0)
        filename = urlparse.urlparse(image)[2]
        create_thumbs_for(podcast, temp_imagefile, filename)
        created_images = True

    if not created_images:
        create_default_thumbs_for(podcast)

    # Now add all of the entries
    for entry in d['entries']:
        media = media_from_entry(entry, tags, save_files)
        media.podcast = podcast

    return podcast
开发者ID:MechanisM,项目名称:mediacore,代码行数:57,代码来源:rss_import.py

示例6: update_status

    def update_status(self, id, update_button=None, publish_on=None, **values):
        """Update the publish status for the given media.

        :param id: Media ID
        :type id: ``int``
        :param update_status: The text of the submit button which indicates
            that the :attr:`~mediacore.model.media.Media.status` should change.
        :type update_status: ``unicode`` or ``None``
        :param publish_on: A date to set to
            :attr:`~mediacore.model.media.Media.publish_on`
        :type publish_on: :class:`datetime.datetime` or ``None``
        :rtype: JSON dict
        :returns:
            success
                bool
            message
                Error message, if unsuccessful
            status_form
                Rendered XHTML for the status form, updated to reflect the
                changes made.

        """
        media = fetch_row(Media, id)
        new_slug = None

        # Make the requested change assuming it will be allowed
        if update_button == _('Review Complete'):
            media.reviewed = True
        elif update_button == _('Publish Now'):
            media.publishable = True
            media.publish_on = publish_on or datetime.now()
            media.update_popularity()
            # Remove the stub prefix if the user wants the default media title
            if media.slug.startswith('_stub_'):
                new_slug = get_available_slug(Media, media.slug[len('_stub_'):])
                media.slug = new_slug
        elif publish_on:
            media.publish_on = publish_on
            media.update_popularity()

        # Verify the change is valid by re-determining the status
        media.update_status()
        DBSession.flush()

        if request.is_xhr:
            # Return the rendered widget for injection
            status_form_xhtml = unicode(update_status_form.display(
                action=url_for(action='update_status'), media=media))
            return dict(
                success = True,
                status_form = status_form_xhtml,
                slug = new_slug,
            )
        else:
            redirect(action='edit')
开发者ID:RadioErewan,项目名称:mediacore,代码行数:55,代码来源:media.py

示例7: example

 def example(cls, **kwargs):
     media = Media()
     defaults = dict(title=u"Foo Media", author=Author(u"Joe", u"[email protected]"), type=VIDEO)
     defaults.update(kwargs)
     defaults.setdefault("slug", get_available_slug(Media, defaults["title"]))
     for key, value in defaults.items():
         assert hasattr(media, key)
         setattr(media, key, value)
     DBSession.add(media)
     DBSession.flush()
     return media
开发者ID:jamielkl,项目名称:mediacore-community,代码行数:11,代码来源:media.py

示例8: add_file

    def add_file(self, id, file=None, url=None, **kwargs):
        """Save action for the :class:`~mediacore.forms.admin.media.AddFileForm`.

        Creates a new :class:`~mediacore.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:`~mediacore.model.media.Media.id` which is
                important if new media has just been created.
            file_id
                The :attr:`~mediacore.model.media.MediaFile.id` for the newly
                created file.
            edit_form
                The rendered XHTML :class:`~mediacore.forms.admin.media.EditFileForm`
                for this file.
            status_form
                The rendered XHTML :class:`~mediacore.forms.admin.media.UpdateStatusForm`

        """
        if id == 'new':
            media = Media()
            user = request.environ['repoze.who.identity']['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)
            DBSession.add(media)
            DBSession.flush()
        else:
            media = fetch_row(Media, id)

        try:
            media_file = add_new_media_file(media, file, url)
        except Invalid, e:
            DBSession.rollback()
            data = dict(
                success = False,
                message = e.message,
            )
开发者ID:RadioErewan,项目名称:mediacore,代码行数:52,代码来源:media.py

示例9: get_videos_from_feed

        def get_videos_from_feed(feed):
            for entry in feed.entry:
                # Occasionally, there are issues with a video in a feed
                # not being available (region restrictions, etc)
                # If this happens, just move along.
                if not entry.media.player:
                    log.debug('Video Feed Error: No player URL? %s' % entry)
                    continue
                video_url = unicode(entry.media.player.url, "utf-8")
                if video_already_has_media_file(video_url):
                    continue
                categories = kwargs.get('youtube.categories', None)
                tags = kwargs.get('youtube.tags', None)
                media = fetch_row(Media, u'new')
                user = request.environ['repoze.who.identity']['user']
                media.author = Author(user.display_name, user.email_address)
                media.reviewed = True
                media.title = unicode(entry.media.title.text, "utf-8")
                if entry.media.description.text:
                    encoded_description = unicode(entry.media.description.text,
                                                "utf-8")
                    media.description = clean_xhtml(encoded_description)
                media.slug = get_available_slug(Media, media.title, media)

                if tags:
                    media.set_tags(unicode(tags))
                if categories:
                    if not isinstance(categories, list):
                        categories = [categories]
                    media.set_categories(categories)
                try:
                    media_file = add_new_media_file(media,
                        url=video_url)
                except StorageError, e:
                    log.debug('Video Feed Error: Error storing video: %s at %s' \
                        % e.message, video_url)
                    continue
                if not has_thumbs(media):
                    create_default_thumbs_for(media)
                media.title = media_file.display_name
                media.update_status()
                if auto_publish:
                    media.reviewed = 1
                    media.encoded = 1
                    media.publishable = 1
                    media.created_on = datetime.now()
                    media.modified_on = datetime.now()
                    media.publish_on = datetime.now()
                DBSession.add(media)
                DBSession.flush()
开发者ID:AshKash,项目名称:mediacore-community,代码行数:50,代码来源:settings.py

示例10: create_podcast_stub

def create_podcast_stub():
    """Return a new :class:`Podcast` instance with helpful defaults.

    This is used any time we need a placeholder db record, such as when:

        * Some admin uploads a thumbnail *before* saving their new media

    """
    user = request.environ['repoze.who.identity']['user']
    timestamp = datetime.now().strftime('%b-%d-%Y')
    podcast = Podcast()
    podcast.slug = get_available_slug(Podcast, 'stub-%s' % timestamp)
    podcast.title = '(Stub %s created by %s)' % (timestamp, user.display_name)
    podcast.author = Author(user.display_name, user.email_address)
    return podcast
开发者ID:86me,项目名称:mediacore,代码行数:15,代码来源:podcasts.py

示例11: example

 def example(cls, **kwargs):
     media = Media()
     defaults = dict(
         title=u'Foo Media',
         author=Author(u'Joe', u'[email protected]'),
         
         type = None,
     )
     defaults.update(kwargs)
     defaults.setdefault('slug', get_available_slug(Media, defaults['title']))
     for key, value in defaults.items():
         assert hasattr(media, key)
         setattr(media, key, value)
     DBSession.add(media)
     DBSession.flush()
     return media
开发者ID:dummyanni,项目名称:Bachelor-Thesis,代码行数:16,代码来源:media.py

示例12: example

    def example(cls, **kwargs):
        category = Category()
        defaults = dict(
            name=u'Foo',
            parent_id=0
        )
        defaults.update(kwargs)
        defaults.setdefault('slug', get_available_slug(Category, defaults['name']))

        for key, value in defaults.items():
            assert hasattr(category, key)
            setattr(category, key, value)

        DBSession.add(category)
        DBSession.flush()
        return category
开发者ID:dummyanni,项目名称:Bachelor-Thesis,代码行数:16,代码来源:categories.py

示例13: createMediaItem

    def createMediaItem(
        self,
        title,
        author_email=None,
        author_name=None,
        slug=None,
        tags=None,
        podcast_id=None,
        category_ids=None,
        meta=None,
        **kwargs
    ):
        mediaItem = Media()
        log.info("createMediaItem({title})".format(title=title))

        if not slug:
            slug = title
        elif slug.startswith("_stub_"):
            slug = slug[len("_stub_") :]
        if slug != mediaItem.slug:
            mediaItem.slug = get_available_slug(Media, slug, mediaItem)

        if podcast_id:
            podcast_id = int(podcast_id)
        else:
            podcast_id = 0

        if not meta:
            meta = {}
        else:
            try:
                meta = json.loads(meta)
            except Exception as e:
                return {"success": False, "message": "Invalid JSON object given for `meta`"}

        mediaItem.title = title
        mediaItem.author = Author(author_name or "No Author", author_email or "No Email")
        mediaItem.podcast_id = podcast_id or None
        mediaItem.set_tags(tags)
        mediaItem.set_categories(category_ids)
        mediaItem.update_status()
        mediaItem.meta = meta

        DBSession.add(mediaItem)
        DBSession.flush()

        return {"success": True, "id": mediaItem.id}
开发者ID:catturavideo,项目名称:mediacore-ce-upload-plugin,代码行数:47,代码来源:uploader.py

示例14: create_media_stub

def create_media_stub():
    """Return a new :class:`Media` instance with helpful defaults.

    This is used any time we need a placeholder db record, such as when:

        * Some admin adds a file *before* saving their new media
        * Some admin uploads album art *before* saving their new media

    """
    user = request.environ['repoze.who.identity']['user']
    timestamp = datetime.now().strftime('%b-%d-%Y')
    m = Media()
    m.slug = get_available_slug(Media, 'stub-%s' % timestamp)
    m.title = '(Stub %s created by %s)' % (timestamp, user.display_name)
    m.author = Author(user.display_name, user.email_address)
    m.status = 'draft,unencoded,unreviewed'
    return m
开发者ID:SergeyLashin,项目名称:mediacore,代码行数:17,代码来源:media.py

示例15: add_new_media_file

def add_new_media_file(media, uploaded_file=None, url=None):
    """Create a new MediaFile for the provided Media object and File/URL
    and add it to that Media object's files list.

    Will also attempt to set up duration and thumbnails according to the
    'use_embed_thumbnails' setting.

    :param media: The Media object to append the file to
    :type media: :class:`~mediacore.model.media.Media` instance
    :param uploaded_file: An object with 'filename' and 'file' properties.
    :type uploaded_file: Formencode uploaded file object.
    :param url: The URL to represent, if no file is given.
    :type url: unicode
    :returns: The created MediaFile (or None)
    """
    if uploaded_file is not None:
        # Create a MediaFile object, add it to the video, and store the file permanently.
        media_file = media_file_from_filename(uploaded_file.filename)
        attach_and_store_media_file(media, media_file, uploaded_file.file)
    elif url is not None:
        # Looks like we were just given a URL. Create a MediaFile object with that URL.
        media_file, thumb_url, duration, title = media_file_from_url(url)
        media.files.append(media_file)

        if title and media.slug.startswith('_stub_'):
            media.title = title
            media.slug = get_available_slug(Media, title, media)

        # Do we have a useful duration?
        if duration and not media.duration:
            media.duration = duration

        # Do we need to create thumbs for an embedded media item?
        if thumb_url \
        and asbool(app_globals.settings['use_embed_thumbnails']) \
        and (not has_thumbs(media) or has_default_thumbs(media)):
            # Download the image into a buffer, wrap the buffer as a File-like
            # object, and create the thumbs.
            try:
                temp_img = urllib2.urlopen(thumb_url)
                file_like_img = StringIO(temp_img.read())
                temp_img.close()
                create_thumbs_for(media, file_like_img, thumb_url)
                file_like_img.close()
            except urllib2.URLError, e:
                log.exception(e)
开发者ID:RadioErewan,项目名称:mediacore,代码行数:46,代码来源:mediafiles.py


注:本文中的mediacore.model.get_available_slug函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。