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


Python DBSession.delete方法代码示例

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


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

示例1: delete_department

# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import delete [as 别名]
def delete_department(request):
    """deletes the department with the given id
    """
    department_id = request.matchdict.get('id')
    department = Department.query.get(department_id)
    name = department.name

    if not department:
        transaction.abort()
        return Response(
            'Can not find a Department with id: %s' % department_id, 500
        )

    try:
        DBSession.delete(department)
        transaction.commit()
    except Exception as e:
        transaction.abort()
        c = StdErrToHTMLConverter(e)
        transaction.abort()
        return Response(c.html(), 500)

    request.session.flash(
        'success: <strong>%s Department</strong> is deleted '
        'successfully' % name
    )

    return Response('Successfully deleted department: %s' % department_id)
开发者ID:Dr-Rakcha,项目名称:stalker-pyramid,代码行数:30,代码来源:department.py

示例2: delete_group

# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import delete [as 别名]
def delete_group(request):
    """deletes the group with the given id
    """
    group_id = request.matchdict.get('id')
    group = Group.query.get(group_id)
    name = group.name

    if not group:
        transaction.abort()
        return Response('Can not find a Group with id: %s' % group_id, 500)

    try:
        DBSession.delete(group)
        transaction.commit()
    except Exception as e:
        transaction.abort()
        c = StdErrToHTMLConverter(e)
        transaction.abort()
        return Response(c.html(), 500)

    request.session.flash(
        'success:<strong>%s Group</strong> is deleted successfully' % name
    )

    return Response('Successfully deleted group: %s' % group_id)
开发者ID:Dr-Rakcha,项目名称:stalker-pyramid,代码行数:27,代码来源:group.py

示例3: delete_user

# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import delete [as 别名]
def delete_user(request):
    """deletes the user with the given id
    """
    user_id = request.matchdict.get('id')
    user = User.query.get(user_id)

    if not user:
        transaction.abort()
        return Response('Can not find a User with id: %s' % user_id, 500)

    try:
        DBSession.delete(user)

        transaction.commit()
        request.session.flash(
            'success: %s is deleted' % user.name
        )
    except Exception as e:
        transaction.abort()
        c = StdErrToHTMLConverter(e)
        transaction.abort()
        request.session.flash(
            c.html()
        )
        return Response(c.html(), 500)

    return Response('Successfully deleted user: %s' % user_id)
开发者ID:Dr-Rakcha,项目名称:stalker-pyramid,代码行数:29,代码来源:auth.py

示例4: assign_reference

# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import delete [as 别名]
def assign_reference(request):
    """assigns the link to the given entity as a new reference
    """
    link_ids = get_multi_integer(request, 'link_ids[]')
    removed_link_ids = get_multi_integer(request, 'removed_link_ids[]')
    entity_id = request.params.get('entity_id', -1)

    entity = Entity.query.filter_by(id=entity_id).first()
    links = Link.query.filter(Link.id.in_(link_ids)).all()
    removed_links = Link.query.filter(Link.id.in_(removed_link_ids)).all()

    # Tags
    tags = get_tags(request)

    logged_in_user = get_logged_in_user(request)

    logger.debug('link_ids      : %s' % link_ids)
    logger.debug('links         : %s' % links)
    logger.debug('entity_id     : %s' % entity_id)
    logger.debug('entity        : %s' % entity)
    logger.debug('tags          : %s' % tags)
    logger.debug('removed_links : %s' % removed_links)

    # remove all the removed links
    for removed_link in removed_links:
        # no need to search for any linked tasks here
        DBSession.delete(removed_link)

    if entity and links:
        entity.references.extend(links)

        # assign all the tags to the links
        for link in links:
            link.tags.extend(tags)
            # generate thumbnail
            thumbnail = generate_thumbnail(link)
            link.thumbnail = thumbnail
            thumbnail.created_by = logged_in_user
            DBSession.add(thumbnail)

        DBSession.add(entity)
        DBSession.add_all(links)

    # return new links as json data
    # in response text
    return [
        {
            'id': link.id,
            'full_path': link.full_path,
            'original_filename': link.original_filename,
            'thumbnail': link.thumbnail.full_path
            if link.thumbnail else link.full_path,
            'tags': [tag.name for tag in link.tags]
        } for link in links
    ]
开发者ID:Dr-Rakcha,项目名称:stalker-pyramid,代码行数:57,代码来源:link.py

示例5: delete_reference

# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import delete [as 别名]
def delete_reference(request):
    """deletes the reference with the given ID
    """
    ref_id = request.matchdict.get('id')
    ref = Link.query.get(ref_id)

    files_to_remove = []
    if ref:
        original_filename = ref.original_filename
        # check if it has a thumbnail
        if ref.thumbnail:
            # remove the file first
            files_to_remove.append(ref.thumbnail.full_path)

            # delete the thumbnail Link from the database
            DBSession.delete(ref.thumbnail)
        # remove the reference itself
        files_to_remove.append(ref.full_path)

        # delete the ref Link from the database
        # IMPORTANT: Because there is no link from Link -> Task deleting a Link
        #            directly will raise an IntegrityError, so remove the Link
        #            from the associated Task before deleting it
        from stalker import Task
        for task in Task.query.filter(Task.references.contains(ref)).all():
            logger.debug('%s is referencing %s, '
                         'breaking this relation' % (task, ref))
            task.references.remove(ref)
        DBSession.delete(ref)

        # now delete files
        for f in files_to_remove:
            # convert the paths to system path
            f_system = convert_file_link_to_full_path(f)
            try:
                os.remove(f_system)
            except OSError:
                pass

        response = Response('%s removed successfully' % original_filename)
        response.status_int = 200
        return response
    else:
        response = Response('No ref with id : %i' % ref_id)
        response.status_int = 500
        transaction.abort()
        return response
开发者ID:Dr-Rakcha,项目名称:stalker-pyramid,代码行数:49,代码来源:link.py

示例6: delete_time_log

# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import delete [as 别名]
def delete_time_log(request):
    """deletes the time_log with the given id
    """
    time_log_id = request.matchdict.get('id')
    time_log = TimeLog.query.get(time_log_id)

    logger.debug('delete_time_log: %s' % time_log_id)

    if not time_log:
        transaction.abort()
        return Response(
            'Can not find a Time_log with id: %s' % time_log_id, 500
        )

    status_cmpl = Status.query.filter(Status.code == 'CMPL').first()

    if time_log.task.status in [status_cmpl]:
        transaction.abort()
        return Response(
            'Error: You can not delete a TimeLog of a Task with status CMPL',
            500
        )

    task_id = time_log.task.id

    try:
        DBSession.delete(time_log)
        transaction.commit()
    except Exception as e:
        transaction.abort()
        c = StdErrToHTMLConverter(e)
        transaction.abort()
        return Response(c.html(), 500)
    else:
        # update the status of the task if there is no time log any more
        task = Task.query.get(task_id)
        assert isinstance(task, Task)
        if not task.time_logs:
            status_new = Status.query.filter(Status.code == 'NEW').first()
            task.status = status_new

    return Response('Successfully deleted time_log: %s' % time_log_id)
开发者ID:Dr-Rakcha,项目名称:stalker-pyramid,代码行数:44,代码来源:time_log.py

示例7: delete_note

# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import delete [as 别名]
def delete_note(request):
    """deletes the task with the given id
    """

    logger.debug('delete_note is starts')

    note_id = request.matchdict.get('id')
    note = Note.query.filter_by(id=note_id).first()

    if not note:
        transaction.abort()
        return Response('Can not find an Note with id: %s' % note_id, 500)

    try:

        DBSession.delete(note)
        transaction.commit()
    except Exception as e:
        transaction.abort()
        c = StdErrToHTMLConverter(e)
        transaction.abort()
        return Response(c.html(), 500)

    return Response('Successfully deleted note')
开发者ID:Dr-Rakcha,项目名称:stalker-pyramid,代码行数:26,代码来源:note.py

示例8: delete_entity

# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import delete [as 别名]
def delete_entity(request):
    """deletes the task with the given id
    """

    logger.debug('delete_entity is starts')

    entity_id = request.matchdict.get('id')
    entity = Entity.query.filter_by(id=entity_id).first()

    if not entity:
        transaction.abort()
        return Response('Can not find an Entity with id: %s' % entity_id, 500)

    try:

        DBSession.delete(entity)
        transaction.commit()
    except Exception as e:
        transaction.abort()
        c = StdErrToHTMLConverter(e)
        transaction.abort()
        return Response(c.html(), 500)

    return Response('Successfully deleted %s: %s' % (entity.entity_type,entity.name))
开发者ID:Dr-Rakcha,项目名称:stalker-pyramid,代码行数:26,代码来源:entity.py

示例9: assign_version

# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import delete [as 别名]
def assign_version(request):
    """assigns the version to the given entity
    """
    logged_in_user = get_logged_in_user(request)

    # TODO: this should be renamed to create version
    # collect data
    link_ids = get_multi_integer(request, 'link_ids')
    task_id = request.params.get('task_id', -1)

    link = Link.query.filter(Link.id.in_(link_ids)).first()
    task = Task.query.filter_by(id=task_id).first()

    logger.debug('link_ids  : %s' % link_ids)
    logger.debug('link      : %s' % link)
    logger.debug('task_id   : %s' % task_id)
    logger.debug('task      : %s' % task)

    if task and link:
        # delete the link and create a version instead
        full_path = convert_file_link_to_full_path(link.full_path)
        take_name = request.params.get('take_name', defaults.version_take_name)
        publish = bool(request.params.get('publish'))

        logger.debug('publish : %s' % publish)

        path_and_filename, extension = os.path.splitext(full_path)

        version = Version(task=task, take_name=take_name,
                          created_by=logged_in_user)
        version.is_published = publish

        # generate path values
        version.update_paths()
        version.extension = extension

        # specify that this version is created with Stalker Pyramid
        version.created_with = 'StalkerPyramid'  # TODO: that should also be a
                                                 #       config value

        # now move the link file to the version.absolute_full_path
        try:
            os.makedirs(
                os.path.dirname(version.absolute_full_path)
            )
        except OSError:
            # dir exists
            pass

        logger.debug('full_path : %s' % full_path)
        logger.debug('version.absolute_full_path : %s' %
                     version.absolute_full_path)

        shutil.copyfile(full_path, version.absolute_full_path)
        os.remove(full_path)

        # it is now safe to delete the link
        DBSession.add(task)
        DBSession.delete(link)
        DBSession.add(version)

    return HTTPOk()
开发者ID:Dr-Rakcha,项目名称:stalker-pyramid,代码行数:64,代码来源:version.py


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