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


Python DBSession.commit方法代码示例

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


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

示例1: test_audiodesc_video_url_media

# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import commit [as 别名]
 def test_audiodesc_video_url_media(self):
     """Media with both Audio files and Video files attatched should be
     Video type."""
     try:
         # Create the media object
         media = self._new_publishable_media(u'description-video',
                 u'(Audio Description + Video)')
         DBSession.add(media)
         # Add an audio description
         media_file = add_new_media_file(media, None,
                 u'http://fakesite.com/fakefile.mp3')
         media_file.type = AUDIO_DESC
         media.update_status()
         # Add a video file
         media_file = add_new_media_file(media, None,
                 u'http://fakesite.com/fakefile.m4v')
         media.update_status()
         # Commit + test
         DBSession.commit()
         assert media.type == VIDEO, \
             "A Media object with a .m4v file and an Audio Description " \
             "was not labelled as a video type; it was labelled %s" % \
             (t, media.type)
     except SQLAlchemyError, e:
         DBSession.rollback()
         raise e
开发者ID:AshKash,项目名称:mediacore-community,代码行数:28,代码来源:test_models.py

示例2: main

# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import commit [as 别名]
def main(parser, options, args):
    app_globs = app_globals._current_obj()
    app_id = app_globals.settings['facebook_appid']
    if not app_id:
        print 'No Facebook app_id configured, exiting'
        sys.exit(3)
    
    app_secret = options.app_secret
    fb = FacebookAPI(app_id, app_secret)
    
    from mediacore.model import DBSession, Media
    # eager loading of 'meta' to speed up later check.
    all_media = Media.query.options(joinedload('_meta')).all()
    
    print 'Checking all media for existing Facebook comments'
    progress = ProgressBar(maxval=len(all_media)).start()
    for i, media in enumerate(all_media):
        progress.update(i+1)
        if 'facebook-comment-xid' not in media.meta:
            continue
        if not fb.has_xid_comments(media):
            continue
        media.meta[u'facebook-comment-xid'] = unicode(media.id)
        DBSession.add(media)
        DBSession.commit()

    progress.finish()
开发者ID:BlendedLearningCollaborative,项目名称:mediacore-community,代码行数:29,代码来源:upgrade_from_v09_preserve_facebook_xid_comments.py

示例3: view

# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import commit [as 别名]
    def view(self, slug, podcast_slug=None, **kwargs):
        """Display the media player, info and comments.

        :param slug: The :attr:`~mediacore.models.media.Media.slug` to lookup
        :param podcast_slug: The :attr:`~mediacore.models.podcasts.Podcast.slug`
            for podcast this media belongs to. Although not necessary for
            looking up the media, it tells us that the podcast slug was
            specified in the URL and therefore we reached this action by the
            preferred route.
        :rtype dict:
        :returns:
            media
                The :class:`~mediacore.model.media.Media` instance for display.
            related_media
                A list of :class:`~mediacore.model.media.Media` instances that
                rank as topically related to the given media item.
            comments
                A list of :class:`~mediacore.model.comments.Comment` instances
                associated with the selected media item.
            comment_form_action
                ``str`` comment form action
            comment_form_values
                ``dict`` form values
            next_episode
                The next episode in the podcast series, if this media belongs to
                a podcast, another :class:`~mediacore.model.media.Media`
                instance.

        """
        media = fetch_row(Media, slug=slug)
        request.perm.assert_permission(u'view', media.resource)

        if media.podcast_id is not None:
            # Always view podcast media from a URL that shows the context of the podcast
            if url_for() != url_for(podcast_slug=media.podcast.slug):
                redirect(podcast_slug=media.podcast.slug)

        try:
            media.increment_views()
            DBSession.commit()
        except OperationalError:
            DBSession.rollback()

        if request.settings['comments_engine'] == 'facebook':
            response.facebook = Facebook(request.settings['facebook_appid'])

        related_media = viewable_media(Media.query.related(media))[:6]
        # TODO: finish implementation of different 'likes' buttons
        #       e.g. the default one, plus a setting to use facebook.
        return dict(
            media = media,
            related_media = related_media,
            comments = media.comments.published().all(),
            comment_form_action = url_for(action='comment'),
            comment_form_values = kwargs,
        )
开发者ID:wafe,项目名称:mediadrop,代码行数:58,代码来源:media.py

示例4: _create_user_with_admin_permission_only

# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import commit [as 别名]
 def _create_user_with_admin_permission_only(self):
     admin_perm = DBSession.query(Permission).filter(Permission.permission_name == u'admin').one()
     second_admin_group = Group.example(name=u'Second admin group')
     admin_perm.groups.append(second_admin_group)
     admin = User.example(groups=[second_admin_group])
     DBSession.commit()
     perm = MediaCorePermissionSystem.permissions_for_user(admin, config)
     assert_true(perm.contains_permission(u'admin'))
     assert_false(perm.contains_permission(u'edit'))
     return admin
开发者ID:dummyanni,项目名称:Bachelor-Thesis,代码行数:12,代码来源:login_test.py

示例5: save_media_obj

# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import commit [as 别名]
def save_media_obj(author_name, author_email, title, description, tags, file, url):
    media = Media()
    media.author = Author(author_name, author_email)
    media.title = title
    media.description = description
    media.tags = tags
    add_new_media_file(media, file=file, url=url)
    DBSession.add(media)
    DBSession.commit()
    return media
开发者ID:BlendedLearningCollaborative,项目名称:mediacore-community,代码行数:12,代码来源:test_helpers.py

示例6: test_add_file_url

# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import commit [as 别名]
    def test_add_file_url(self):
        slug = u'test-add-file-url'
        title = u'Test Adding File by URL on Media Edit Page.'

        try:
            media = self._new_publishable_media(slug, title)
            media.publishable = False
            media.reviewed = False
            DBSession.add(media)
            DBSession.commit()
            media_id = media.id
        except SQLAlchemyError, e:
            DBSession.rollback()
            raise e
开发者ID:dummyanni,项目名称:Bachelor-Thesis,代码行数:16,代码来源:test_admin_media.py

示例7: _get_media

# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import commit [as 别名]
    def _get_media(self, unique):
        """Return the media/mediafiles required for the Helpers tests"""
        try:
            media = self._new_publishable_media(u'media-selection-%s' % unique,
                    u'Media Selection Test (%s)' % unique)
            DBSession.add(media)

            media_files = {}
            for t in ['oga', 'ogv', 'm4a', 'm4v', 'flv', 'mp3', 'xml']:
                media_files[t] = add_new_media_file(media, None,
                    u'http://fakesite.com/fakefile.%s' % t)
            media_files['youtube'] = add_new_media_file(media, None,
                    u'http://www.youtube.com/watch?v=3RsbmjNLQkc')
            media.update_status()
            DBSession.commit()
        except SQLAlchemyError, e:
            DBSession.rollback()
            raise e
开发者ID:AshKash,项目名称:mediacore-community,代码行数:20,代码来源:test_helpers.py

示例8: test_captioned_url_media

# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import commit [as 别名]
 def test_captioned_url_media(self):
     """Media with only subtitles attatched should be None type."""
     try:
         for t in self.caption_types:
             media = self._new_publishable_media(u'caption-%s' % t,
                     u'%s (Captioned)' % t.upper())
             DBSession.add(media)
             media_file = add_new_media_file(media, None,
                     u'http://fakesite.com/fakefile.%s' % t)
             media.update_status()
             DBSession.commit()
             assert media.type == None, \
                 "A Media object with only an .%s file associated was " \
                 "not labelled as a 'None' type; it was labelled %s" % \
                 (t, media.type)
     except SQLAlchemyError, e:
         DBSession.rollback()
         raise e
开发者ID:AshKash,项目名称:mediacore-community,代码行数:20,代码来源:test_models.py

示例9: inject_in_db

# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import commit [as 别名]
 def inject_in_db(cls, enable_player=False):
     from mediacore.model import DBSession
     from mediacore.model.players import players as players_table, PlayerPrefs
     
     prefs = PlayerPrefs()
     prefs.name = cls.name
     prefs.enabled = enable_player
     # didn't get direct SQL expression to work with SQLAlchemy
     # player_table = sql.func.max(player_table.c.priority)
     query = sql.select([sql.func.max(players_table.c.priority)])
     max_priority = DBSession.execute(query).first()[0]
     if max_priority is None:
         max_priority = -1
     prefs.priority = max_priority + 1
     prefs.created_on = datetime.now()
     prefs.modified_on = datetime.now()
     prefs.data = cls.default_data
     DBSession.add(prefs)
     DBSession.commit()
开发者ID:axxis7,项目名称:mediacore-community,代码行数:21,代码来源:players.py

示例10: test_audio_description_url_media

# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import commit [as 别名]
 def test_audio_description_url_media(self):
     """Media with only Audio Descriptions attatched should be None type."""
     try:
         for t in self.audio_types:
             media = self._new_publishable_media(u'description-%s' % t,
                     u'%s (Audio Description)' % t.upper())
             DBSession.add(media)
             media_file = add_new_media_file(media, None,
                     u'http://fakesite.com/fakefile.%s' % t)
             media_file.type = AUDIO_DESC
             media.update_status()
             DBSession.commit()
             assert media.type == None, \
                 "A Media object with only an Audio Description file " \
                 "associated was not labelled as a None type; it " \
                 "was labelled %s" % (t, media.type)
     except SQLAlchemyError, e:
         DBSession.rollback()
         raise e
开发者ID:AshKash,项目名称:mediacore-community,代码行数:21,代码来源:test_models.py

示例11: test_edit_media

# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import commit [as 别名]
    def test_edit_media(self):
        title = u'Edit Existing Media Test'
        slug = u'edit-existing-media-test' # this should be unique

        # Values that we will change during the edit process
        name = u'Frederick Awesomeson'
        email = u'[email protected]'
        description = u'This media item was created to test the "admin/media/edit/someID" method'
        htmlized_description = '<p>This media item was created to test the &quot;admin/media/edit/someID&quot; method</p>'
        notes = u'Some Notes!'

        try:
            media = self._new_publishable_media(slug, title)
            media.publishable = False
            media.reviewed = False
            DBSession.add(media)
            DBSession.commit()
            media_id = media.id
        except SQLAlchemyError, e:
            DBSession.rollback()
            raise e
开发者ID:dummyanni,项目名称:Bachelor-Thesis,代码行数:23,代码来源:test_admin_media.py

示例12: setup_app

# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import commit [as 别名]
def setup_app(command, conf, vars):
    """Called by ``paster setup-app``.

    This script is responsible for:

        * Creating the initial database schema and loading default data.
        * Executing any migrations necessary to bring an existing database
          up-to-date. Your data should be safe but, as always, be sure to
          make backups before using this.
        * Re-creating the default database for every run of the test suite.

    XXX: All your data will be lost IF you run the test suite with a
         config file named 'test.ini'. Make sure you have this configured
         to a different database than in your usual deployment.ini or
         development.ini file because all database tables are dropped a
         and recreated every time this script runs.

    XXX: If you are upgrading from MediaCore v0.7.2 or v0.8.0, run whichever
         one of these that applies:
           ``python batch-scripts/upgrade/upgrade_from_v072.py deployment.ini``
           ``python batch-scripts/upgrade/upgrade_from_v080.py deployment.ini``

    XXX: For search to work, we depend on a number of MySQL triggers which
         copy the data from our InnoDB tables to a MyISAM table for its
         fulltext indexing capability. Triggers can only be installed with
         a mysql superuser like root, so you must run the setup_triggers.sql
         script yourself.

    """
    if pylons.test.pylonsapp:
        # NOTE: This extra filename check may be unnecessary, the example it is
        # from did not check for pylons.test.pylonsapp. Leaving it in for now
        # to make it harder for someone to accidentally delete their database.
        filename = os.path.split(conf.filename)[-1]
        if filename == 'test.ini':
            log.info('Dropping existing tables...')
            metadata.drop_all(checkfirst=True)
            drop_version_control(conf.local_conf['sqlalchemy.url'],
                                 migrate_repository)
    else:
        # Don't reload the app if it was loaded under the testing environment
        config = load_environment(conf.global_conf, conf.local_conf)

    # Create the migrate_version table if it doesn't exist.
    # If the table doesn't exist, we assume the schema was just setup
    # by this script and therefore must be the latest version.
    latest_version = version(migrate_repository)
    try:
        version_control(conf.local_conf['sqlalchemy.url'],
                        migrate_repository,
                        version=latest_version)
    except DatabaseAlreadyControlledError:
        log.info('Running any new migrations, if there are any')
        upgrade(conf.local_conf['sqlalchemy.url'],
                migrate_repository,
                version=latest_version)
    else:
        log.info('Initializing new database with version %r' % latest_version)
        metadata.create_all(bind=DBSession.bind, checkfirst=True)
        add_default_data()

    cleanup_players_table(enabled=True)

    # Save everything, along with the dummy data if applicable
    DBSession.commit()

    log.info('Generating appearance.css from your current settings')
    settings = DBSession.query(Setting.key, Setting.value)
    generate_appearance_css(settings, cache_dir=conf['cache_dir'])

    log.info('Successfully setup')
开发者ID:BlendedLearningCollaborative,项目名称:mediacore-community,代码行数:73,代码来源:websetup.py

示例13: setup_app

# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import commit [as 别名]
def setup_app(command, conf, vars):
    """Called by ``paster setup-app``.

    This script is responsible for:

        * Creating the initial database schema and loading default data.
        * Executing any migrations necessary to bring an existing database
          up-to-date. Your data should be safe but, as always, be sure to
          make backups before using this.
        * Re-creating the default database for every run of the test suite.

    XXX: All your data will be lost IF you run the test suite with a
         config file named 'test.ini'. Make sure you have this configured
         to a different database than in your usual deployment.ini or
         development.ini file because all database tables are dropped a
         and recreated every time this script runs.

    XXX: If you are upgrading from MediaCore v0.7.2 or v0.8.0, run whichever
         one of these that applies:
           ``python batch-scripts/upgrade/upgrade_from_v072.py deployment.ini``
           ``python batch-scripts/upgrade/upgrade_from_v080.py deployment.ini``

    XXX: For search to work, we depend on a number of MySQL triggers which
         copy the data from our InnoDB tables to a MyISAM table for its
         fulltext indexing capability. Triggers can only be installed with
         a mysql superuser like root, so you must run the setup_triggers.sql
         script yourself.

    """
    config = load_environment(conf.global_conf, conf.local_conf)
    plugin_manager = config["pylons.app_globals"].plugin_mgr
    mediacore_migrator = MediaCoreMigrator.from_config(conf, log=log)

    engine = metadata.bind
    db_connection = engine.connect()
    # simplistic check to see if MediaCore tables are present, just check for
    # the media_files table and assume that all other tables are there as well
    from mediacore.model.media import media_files

    mediacore_tables_exist = engine.dialect.has_table(db_connection, media_files.name)

    run_migrations = True
    if not mediacore_tables_exist:
        head_revision = mediacore_migrator.head_revision()
        log.info("Initializing new database with version %r" % head_revision)
        metadata.create_all(bind=DBSession.bind, checkfirst=True)
        mediacore_migrator.init_db(revision=head_revision)
        run_migrations = False
        add_default_data()
        for migrator in plugin_manager.migrators():
            migrator.init_db()
        events.Environment.database_initialized()
    elif not mediacore_migrator.migrate_table_exists():
        log.error(
            "No migration table found, probably your MediaCore install "
            "is too old (< 0.9?). Please upgrade to MediaCore CE 0.9 first."
        )
        raise AssertionError("no migration table found")
    elif not mediacore_migrator.alembic_table_exists():
        alembic_revision = mediacore_migrator.map_migrate_version()
        mediacore_migrator.stamp(alembic_revision)
    if run_migrations:
        mediacore_migrator.migrate_db()
        for migrator in plugin_manager.migrators():
            migrator.migrate_db()
        events.Environment.database_migrated()

    cleanup_players_table(enabled=True)

    # Save everything, along with the dummy data if applicable
    DBSession.commit()
    events.Environment.database_ready()

    log.info("Generating appearance.css from your current settings")
    settings = DBSession.query(Setting.key, Setting.value)
    generate_appearance_css(settings, cache_dir=conf["cache_dir"])

    log.info("Successfully setup")
开发者ID:nti1094,项目名称:mediacore-community,代码行数:80,代码来源:websetup.py


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