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


Python Comment.code方法代码示例

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


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

示例1: handle

# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import code [as 别名]
def handle(changeset):
    print ('Received ' + str(changeset))
    # Fetch project and pad ids.
    project_id = changeset['projectId']
    pad_id = changeset['padId']
    # Fetch project lock or create it, if not exists already.
    if project_id not in update_locks:
        update_locks[project_id] = Lock()
    update_lock = update_locks[project_id]
    with update_lock:
        # Fetch next revision number.
        if project_id not in revisions:
            revisions[project_id] = {}
        if pad_id not in revisions[project_id]:
            revisions[project_id][pad_id] = [Revision('0', None)]
        
        # Follow the changeset by all revisions not known by that user.
        revs = revisions[project_id][pad_id]
        apply_from = len(revs)
        for i in range(len(revs), 0, -1):
            if changeset['baseRev'] == revs[i - 1].id:
                apply_from = i
                break
        for i in range(apply_from, len(revs)):
            if changeset['baseLen'] == revs[i].changeset['newLen']:
                apply_from = i + 1
                break
        # Fetch current revision.
        crtRev, baseRev = changeset['revId'], changeset['baseRev']
        for i in range(apply_from, len(revs)):
            changeset = follow(revs[i].changeset, changeset)
        # Update base rev.
        changeset['baseRev'] = baseRev
        # Create new revision out of this changeset.
        revisions[project_id][pad_id].append(Revision(crtRev, changeset))
        # Update current pad in db.
        changeset['projectId'], changeset['padId'] = project_id, pad_id
        changeset['revId'] = crtRev
        updateDBPad(changeset, crtRev)
        # Add the new comments to DB.
        if 'comments' in changeset:
            for code, comment in changeset['comments'].items():
                newComment = Comment(comment['author'], comment['text'])
                newComment.pad_id = comment['padId']
                newComment.code = comment['code']
                db.session.add(newComment)
            db.session.commit()
        # Include the id of the client that generated the changeset.
        changeset['clientId'] = request.sid
        # Broadcast to all clients.
        emit('server_client_changeset', changeset, room=changeset['projectId'])
    # Send ACK to the client.
    emit('server_client_ack', changeset['padId'], room=request.sid)
开发者ID:JCGrant,项目名称:ColDE,代码行数:55,代码来源:socketio_server.py


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