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


Python misc.encode_response函数代码示例

本文整理汇总了Python中sagenb.notebook.misc.encode_response函数的典型用法代码示例。如果您正苦于以下问题:Python encode_response函数的具体用法?Python encode_response怎么用?Python encode_response使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: worksheet_cell_list

def worksheet_cell_list(worksheet):
    """
    Return a list of cells in JSON format.
    """
    r = {}
    r["state_number"] = worksheet.state_number()
    r["cell_list"] = [c.basic() for c in worksheet.cell_list()]
    return encode_response(r)
开发者ID:lukas-lansky,项目名称:sagenb,代码行数:8,代码来源:worksheet.py

示例2: worksheet_delete_cell_output

def worksheet_delete_cell_output(worksheet):
    """Delete's a cell's output."""
    r = {}
    r["id"] = id = get_cell_id()
    worksheet.get_cell_with_id(id).delete_output()
    r["command"] = "delete_output"

    return encode_response(r)
开发者ID:lukas-lansky,项目名称:sagenb,代码行数:8,代码来源:worksheet.py

示例3: worksheet_delete_cell_output

def worksheet_delete_cell_output(worksheet):
    """Delete's a cell's output."""
    r = {}
    r['id'] = id = get_cell_id()
    worksheet.get_cell_with_id(id).delete_output()
    r['command'] = 'delete_output'

    from sagenb.notebook.misc import encode_response
    return encode_response(r)
开发者ID:philbrks,项目名称:sagenb,代码行数:9,代码来源:worksheet.py

示例4: worksheet_introspect

def worksheet_introspect(worksheet):
    """
    Cell introspection. This is called when the user presses the tab
    key in the browser in order to introspect.
    """
    r = {}
    r['id'] = id = get_cell_id()

    if worksheet.tags().get('_pub_', [False])[0]: #tags set in pub_worksheet
        r['command'] = 'error'
        r['message'] = 'Cannot evaluate public cell introspection.'
        return encode_response(r)

    before_cursor = request.values.get('before_cursor', '')
    after_cursor = request.values.get('after_cursor', '')
    cell = worksheet.get_cell_with_id(id)
    cell.evaluate(introspect=[before_cursor, after_cursor])

    r['command'] = 'introspect'
    return encode_response(r)
开发者ID:SnarkBoojum,项目名称:sagenb,代码行数:20,代码来源:worksheet.py

示例5: suspend_user

def suspend_user():
    user = request.values['username']
    try:
        U = g.notebook.user_manager().user(user)
        U.set_suspension()
    except KeyError:
        pass

    return encode_response({
        'message': _('User <strong>%(username)s</strong> has been suspended/unsuspended.', username=user)
    })
开发者ID:Darot,项目名称:sagenb,代码行数:11,代码来源:admin.py

示例6: worksheet_introspect

def worksheet_introspect(worksheet):
    """
    Cell introspection. This is called when the user presses the tab
    key in the browser in order to introspect.
    """
    r = {}
    r["id"] = id = get_cell_id()

    if worksheet.tags().get("_pub_", [False])[0]:  # tags set in pub_worksheet
        r["command"] = "error"
        r["message"] = "Cannot evaluate public cell introspection."
        return encode_response(r)

    before_cursor = request.values.get("before_cursor", "")
    after_cursor = request.values.get("after_cursor", "")
    cell = worksheet.get_cell_with_id(id)
    cell.evaluate(introspect=[before_cursor, after_cursor])

    r["command"] = "introspect"
    return encode_response(r)
开发者ID:lukas-lansky,项目名称:sagenb,代码行数:20,代码来源:worksheet.py

示例7: worksheet_cell_list

def worksheet_cell_list(worksheet):
    """
    Return the state number and the HTML for the main body of the
    worksheet, which consists of a list of cells.
    """
    r = {}
    r['state_number'] = worksheet.state_number()
    # TODO: Send and actually use the body's HTML.
    r['html_cell_list'] = ''
    #r['html_cell_list'] = W.html_cell_list()

    return encode_response(r)
开发者ID:SnarkBoojum,项目名称:sagenb,代码行数:12,代码来源:worksheet.py

示例8: worksheet_new_cell_after

def worksheet_new_cell_after(worksheet):
    """Add a new cell after a given cell."""
    r = {}
    r['id'] = id = get_cell_id()
    input = unicode_str(request.values.get('input', ''))
    cell = worksheet.new_cell_after(id, input=input)
    worksheet.increase_state_number()

    r['new_id'] = cell.id()
    r['new_html'] = cell.html(div_wrap=True)

    return encode_response(r)
开发者ID:SnarkBoojum,项目名称:sagenb,代码行数:12,代码来源:worksheet.py

示例9: add_user

def add_user():
    from sagenb.notebook.misc import is_valid_username

    username = request.values['username']
    password = random_password()

    if not is_valid_username(username):
        return encode_response({
            'error': _('<strong>Invalid username!</strong>')
        })

    if username in g.notebook.user_manager().usernames():
        return encode_response({
            'error': _('The username <strong>%(username)s</strong> is already taken!', username=username)
        })

    g.notebook.user_manager().add_user(username, password, '', force=True)
    return encode_response({
        'message': _('The temporary password for the new user <strong>%(username)s</strong> is <strong>%(password)s</strong>',
                      username=username, password=password)
    })
开发者ID:Darot,项目名称:sagenb,代码行数:21,代码来源:admin.py

示例10: worksheet_new_cell_before

    def worksheet_new_cell_before(self, worksheet):
        """Add a new cell before a given cell."""
        r = {}
        r['id'] =  id = self.get_cell_id()
        input = unicode_str(self.request_values.get('input', ''))
        cell = worksheet.new_cell_before(id, input=input)
        worksheet.increase_state_number()

        r['new_id'] = cell.id()
        #r['new_html'] = cell.html(div_wrap=False)

        return encode_response(r)
开发者ID:rljacobson,项目名称:Guru-NB,代码行数:12,代码来源:WorksheetController.py

示例11: worksheet_new_cell_before

def worksheet_new_cell_before(worksheet):
    """Add a new cell before a given cell."""
    r = {}
    r["id"] = id = get_cell_id()
    input = unicode_str(request.values.get("input", ""))
    cell = worksheet.new_cell_before(id, input=input)
    worksheet.increase_state_number()

    r["new_id"] = cell.id()
    # r['new_html'] = cell.html(div_wrap=False)

    return encode_response(r)
开发者ID:lukas-lansky,项目名称:sagenb,代码行数:12,代码来源:worksheet.py

示例12: worksheet_new_cell_before

def worksheet_new_cell_before(worksheet):
    """Add a new cell before a given cell."""
    r = {}
    r['id'] =  id = get_cell_id()
    input = unicode_str(request.values.get('input', ''))
    cell = worksheet.new_cell_before(id, input=input)
    worksheet.increase_state_number()
    
    r['new_id'] = cell.id()
    r['new_html'] = cell.html(div_wrap=False)

    from sagenb.notebook.misc import encode_response
    return encode_response(r)
开发者ID:philbrks,项目名称:sagenb,代码行数:13,代码来源:worksheet.py

示例13: reset_user_password

def reset_user_password():
    user = request.values['username']
    password = random_password()
    try:
        # U = g.notebook.user_manager().user(user)
        g.notebook.user_manager().set_password(user, password)
    except KeyError:
        pass

    return encode_response({
        'message': _('The temporary password for the new user <strong>%(username)s</strong> is <strong>%(password)s</strong>',
                          username=user, password=password)
    })
开发者ID:Darot,项目名称:sagenb,代码行数:13,代码来源:admin.py

示例14: worksheet_list

def worksheet_list():
    """
    Returns a worksheet listing.

    INPUT:

    -  ``args`` - ctx.args where ctx is the dict passed
       into a resource's render method

    -  ``pub`` - boolean, True if this is a listing of
       public worksheets

    -  ``username`` - the user whose worksheets we are
       listing

    OUTPUT:

    a string
    """
    
    from sagenb.notebook.notebook import sort_worksheet_list
    from sagenb.misc.misc import unicode_str, SAGE_VERSION
    from sagenb.notebook.misc import encode_response
    
    r = {}

    pub = 'pub' in request.args    
    readonly = g.notebook.readonly_user(g.username)
    typ = request.args['type'] if 'type' in request.args else 'active'
    search = unicode_str(request.args['search']) if 'search' in request.args else None
    sort = request.args['sort'] if 'sort' in request.args else 'last_edited'
    reverse = (request.args['reverse'] == 'True') if 'reverse' in request.args else False
    try:
        if not pub:
            r['worksheets'] = [x.basic() for x in g.notebook.worksheet_list_for_user(g.username, typ=typ, sort=sort, search=search, reverse=reverse)]
        else:
            r['worksheets'] = [x.basic() for x in g.notebook.worksheet_list_for_public(g.username, sort=sort, search=search, reverse=reverse)]

    except ValueError as E:
        # for example, the sort key was not valid
        print "Error displaying worksheet listing: ", E
        return current_app.message(_("Error displaying worksheet listing."))

    #if pub and (not g.username or g.username == tuple([])):
    #    r['username'] = 'pub'

    r['accounts'] = g.notebook.user_manager().get_accounts()
    r['sage_version'] = SAGE_VERSION
    # r['pub'] = pub
    
    return encode_response(r)
开发者ID:rljacobson,项目名称:Guru-NB,代码行数:51,代码来源:worksheet_listing.py

示例15: worksheet_new_text_cell_after

def worksheet_new_text_cell_after(worksheet):
    """Add a new text cell after a given cell."""
    r = {}
    r['id'] = id = get_cell_id()
    input = unicode_str(request.values.get('input', ''))
    cell = worksheet.new_text_cell_after(id, input=input)
    worksheet.increase_state_number()

    r['new_id'] = cell.id()
    r['new_html'] = cell.html(editing=True)

    # XXX: Does editing correspond to TinyMCE?  If so, we should try
    # to centralize that code.
    return encode_response(r)
开发者ID:SnarkBoojum,项目名称:sagenb,代码行数:14,代码来源:worksheet.py


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