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


Python Session.delete方法代码示例

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


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

示例1: take_punitive_actions

# 需要导入模块: from mediagoblin.db.base import Session [as 别名]
# 或者: from mediagoblin.db.base.Session import delete [as 别名]
def take_punitive_actions(request, form, report, user):
    message_body = ""

    # The bulk of this action is running through all of the different
    # punitive actions that a moderator could take.
    if u"takeaway" in form.action_to_resolve.data:
        for privilege_name in form.take_away_privileges.data:
            take_away_privileges(user.username, privilege_name)
            form.resolution_content.data += _(u"\n{mod} took away {user}'s {privilege} privileges.").format(
                mod=request.user.username, user=user.username, privilege=privilege_name
            )

    # If the moderator elects to ban the user, a new instance of user_ban
    # will be created.
    if u"userban" in form.action_to_resolve.data:
        user_ban = ban_user(
            form.targeted_user.data, expiration_date=form.user_banned_until.data, reason=form.why_user_was_banned.data
        )
        Session.add(user_ban)
        form.resolution_content.data += _(u"\n{mod} banned user {user} {expiration_date}.").format(
            mod=request.user.username,
            user=user.username,
            expiration_date=(
                _("until {date}").format(date=form.user_banned_until.data)
                if form.user_banned_until.data
                else _("indefinitely")
            ),
        )

    # If the moderator elects to send a warning message. An email will be
    # sent to the email address given at sign up
    if u"sendmessage" in form.action_to_resolve.data:
        message_body = form.message_to_user.data
        form.resolution_content.data += _(u"\n{mod} sent a warning email to the {user}.").format(
            mod=request.user.username, user=user.username
        )

    if u"delete" in form.action_to_resolve.data and report.is_comment_report():
        deleted_comment = report.obj()
        Session.delete(deleted_comment)
        form.resolution_content.data += _(u"\n{mod} deleted the comment.").format(mod=request.user.username)
    elif u"delete" in form.action_to_resolve.data and report.is_media_entry_report():
        deleted_media = report.obj()
        deleted_media.delete()
        form.resolution_content.data += _(u"\n{mod} deleted the media entry.").format(mod=request.user.username)
    report.archive(resolver_id=request.user.id, resolved=datetime.now(), result=form.resolution_content.data)

    Session.add(report)
    Session.commit()
    if message_body:
        send_email(
            mg_globals.app_config["email_sender_address"],
            [user.email],
            _("Warning from") + "- {moderator} ".format(moderator=request.user.username),
            message_body,
        )

    return redirect(request, "mediagoblin.moderation.users_detail", user=user.username)
开发者ID:tofay,项目名称:mediagoblin,代码行数:60,代码来源:tools.py

示例2: clean_orphan_tags

# 需要导入模块: from mediagoblin.db.base import Session [as 别名]
# 或者: from mediagoblin.db.base.Session import delete [as 别名]
def clean_orphan_tags(commit=True):
    """Search for unused MediaTags and delete them"""
    q1 = Session.query(Tag).outerjoin(MediaTag).filter(MediaTag.id==None)
    for t in q1:
        Session.delete(t)
    # The "let the db do all the work" version:
    # q1 = Session.query(Tag.id).outerjoin(MediaTag).filter(MediaTag.id==None)
    # q2 = Session.query(Tag).filter(Tag.id.in_(q1))
    # q2.delete(synchronize_session = False)
    if commit:
        Session.commit()
开发者ID:praveen97uma,项目名称:goblin,代码行数:13,代码来源:util.py

示例3: remove_collection_item

# 需要导入模块: from mediagoblin.db.base import Session [as 别名]
# 或者: from mediagoblin.db.base.Session import delete [as 别名]
def remove_collection_item(collection_item, commit=True):
    collection = collection_item.in_collection

    collection.items = collection.items - 1
    Session.delete(collection_item)
    Session.add(collection)

    hook_runall('collection_remove_media', collection_item=collection_item)

    if commit:
        Session.commit()
开发者ID:vasilenkomike,项目名称:mediagoblin,代码行数:13,代码来源:lib.py

示例4: featured_media_panel

# 需要导入模块: from mediagoblin.db.base import Session [as 别名]
# 或者: from mediagoblin.db.base.Session import delete [as 别名]
def featured_media_panel(request):
    """
    This is a new administrator panel to manage featured media. This is an
    entirely optional panel, as there are other ways to manage it, but this way
    gives the admin more control.
    """
    form = archivalook_forms.FeaturedMediaList(request.form)

    if request.method == 'POST' and form.validate():
        featured_media = split_featured_media_list(form.box_content.data)
        previous_features = FeaturedMedia.query.all()
        for index, (media_entry, display_type) in enumerate(featured_media):
            target = FeaturedMedia.query.filter(
                FeaturedMedia.media_entry == media_entry).first()
            # If this media was already featured, we don't have to create a new
            # feature, we just have to edit the old one's values
            if target is not None:
                target.order = index
                target.display_type = display_type
                previous_features.remove(target)
                Session.add(target)
            else:
                new_feature = FeaturedMedia(
                    media_entry=media_entry,
                    display_type=display_type,
                    order=index)
                Session.add(new_feature)
        [Session.delete(feature) for feature in previous_features]

        Session.commit()

    form.box_content.data = create_featured_media_textbox()
    return render_to_response(
        request, 'archivalook/feature.html',
       {'form' : form})
开发者ID:ausbin,项目名称:mediagoblin,代码行数:37,代码来源:views.py


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