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


Python DBSession.commit方法代码示例

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


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

示例1: bulk

# 需要导入模块: from mediadrop.model.meta import DBSession [as 别名]
# 或者: from mediadrop.model.meta.DBSession import commit [as 别名]
    def bulk(self, type=None, ids=None, **kwargs):
        """Perform bulk operations on media items

        :param type: The type of bulk action to perform (delete)
        :param ids: A list of IDs.

        """
        if not ids:
            ids = []
        elif not isinstance(ids, list):
            ids = [ids]


        if type == 'delete':
            Category.query.filter(Category.id.in_(ids)).delete(False)
            DBSession.commit()
            success = True
        else:
            success = False

        return dict(
            success = success,
            ids = ids,
            parent_options = unicode(category_form.c['parent_id'].display()),
        )
开发者ID:FelixSchwarz,项目名称:mediadrop-test-renames,代码行数:27,代码来源:categories.py

示例2: _autocommit_commit

# 需要导入模块: from mediadrop.model.meta import DBSession [as 别名]
# 或者: from mediadrop.model.meta.DBSession import commit [as 别名]
def _autocommit_commit(req):
    from mediadrop.model.meta import DBSession
    try:
        DBSession.commit()
    except:
        _autocommit_rollback(req)
        raise
    else:
        _autocommit_fire_callbacks(req, req.commit_callbacks)
开发者ID:FelixSchwarz,项目名称:mediadrop-test-renames,代码行数:11,代码来源:decorators.py

示例3: setUp

# 需要导入模块: from mediadrop.model.meta import DBSession [as 别名]
# 或者: from mediadrop.model.meta.DBSession import commit [as 别名]
 def setUp(self):
     super(DBTestCase, self).setUp()
     self.env_dir = self._create_environment_folders()
     self.pylons_config = setup_environment_and_database(self.env_dir, 
         enabled_plugins=self.enabled_plugins)
     add_default_data()
     DBSession.commit()
     
     config.push_process_config(self.pylons_config)
开发者ID:GitReadysoft,项目名称:mediadrop,代码行数:11,代码来源:db_testcase.py

示例4: save

# 需要导入模块: from mediadrop.model.meta import DBSession [as 别名]
# 或者: from mediadrop.model.meta.DBSession import commit [as 别名]
    def save(self, id, email_address, display_name, login_details,
             delete=None, **kwargs):
        """Save changes or create a new :class:`~mediadrop.model.auth.User` instance.

        :param id: User ID. If ``"new"`` a new user is created.
        :type id: ``int`` or ``"new"``
        :returns: Redirect back to :meth:`index` after successful save.

        """
        user = fetch_row(User, id)

        if delete:
            DBSession.delete(user)
            redirect(action='index', id=None)

        user.display_name = display_name
        user.email_address = email_address
        user.user_name = login_details['user_name']

        password = login_details['password']
        if password is not None and password != '':
            user.password = password

        if login_details['groups']:
            query = DBSession.query(Group).filter(Group.group_id.in_(login_details['groups']))
            user.groups = list(query.all())
        else:
            user.groups = []

        DBSession.add(user)

        # Check if we're changing the logged in user's own password
        if user.id == request.perm.user.id \
        and password is not None and password != '':
            DBSession.commit()
            # repoze.who sees the Unauthorized response and clears the cookie,
            # forcing a fresh login with the new password
            raise webob.exc.HTTPUnauthorized().exception

        redirect(action='index', id=None)
开发者ID:GitReadysoft,项目名称:mediadrop,代码行数:42,代码来源:users.py

示例5: save

# 需要导入模块: from mediadrop.model.meta import DBSession [as 别名]
# 或者: from mediadrop.model.meta.DBSession import commit [as 别名]
    def save(
        self, id, slug, title, subtitle, author_name, author_email, description, details, feed, delete=None, **kwargs
    ):
        """Save changes or create a new :class:`~mediadrop.model.podcasts.Podcast` instance.

        Form handler the :meth:`edit` action and the
        :class:`~mediadrop.forms.admin.podcasts.PodcastForm`.

        Redirects back to :meth:`edit` after successful editing
        and :meth:`index` after successful deletion.

        """
        podcast = fetch_row(Podcast, id)

        if delete:
            DBSession.delete(podcast)
            DBSession.commit()
            delete_thumbs(podcast)
            redirect(action="index", id=None)

        if not slug:
            slug = title
        if slug != podcast.slug:
            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.copyright = details["copyright"]
        podcast.category = details["category"]
        podcast.itunes_url = feed["itunes_url"]
        podcast.feedburner_url = feed["feedburner_url"]
        podcast.explicit = {"yes": True, "clean": False}.get(details["explicit"], None)

        if id == "new":
            DBSession.add(podcast)
            DBSession.flush()
            create_default_thumbs_for(podcast)

        redirect(action="edit", id=podcast.id)
开发者ID:micheg,项目名称:mediadrop,代码行数:42,代码来源:podcasts.py

示例6: insert_settings

# 需要导入模块: from mediadrop.model.meta import DBSession [as 别名]
# 或者: from mediadrop.model.meta.DBSession import commit [as 别名]
def insert_settings(defaults):
    """Insert the given setting if they don't exist yet.

    XXX: Does not include any support for MultiSetting. This approach
         won't work for that. We'll need to use a migration script.

    :type defaults: list
    :param defaults: Key and value pairs
    :rtype: list
    :returns: Any settings that have just been created.
    """
    inserted = []
    try:
        settings_query = DBSession.query(Setting.key)\
            .filter(Setting.key.in_([key for key, value in defaults]))
        existing_settings = set(x[0] for x in settings_query)
    except ProgrammingError:
        # If we are running paster setup-app on a fresh database with a
        # plugin which tries to use this function every time the
        # Environment.loaded event fires, the settings table will not
        # exist and this exception will be thrown, but its safe to ignore.
        # The settings will be created the next time the event fires,
        # which will likely be the first time the app server starts up.
        return inserted
    for key, value in defaults:
        if key in existing_settings:
            continue
        transaction = DBSession.begin_nested()
        try:
            s = Setting(key, value)
            DBSession.add(s)
            transaction.commit()
            inserted.append(s)
        except IntegrityError:
            transaction.rollback()
    if inserted:
        DBSession.commit()
    return inserted
开发者ID:knyar,项目名称:mediadrop,代码行数:40,代码来源:settings.py


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