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


Python helpers.render_json函数代码示例

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


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

示例1: remove_module

def remove_module(request, revision_id):
    """
    Remove module from PackageRevision
    """
    revision = get_object_with_related_or_404(PackageRevision, pk=revision_id)
    if request.user.pk != revision.author.pk:
        log_msg = ("[security] Attempt to remove a module from package (%s) "
                "by non-owner (%s)" % (revision_id, request.user))
        log.warning(log_msg)
        return HttpResponseForbidden('You are not the author of this Package')

    filenames = request.POST.get('filename').split(',')

    revision.add_commit_message('module removed')
    try:
        removed_modules, removed_dirs = revision.modules_remove_by_path(
                filenames)
    except Module.DoesNotExist:
        log_msg = 'Attempt to delete a non existing module(s) %s from %s.' % (
            str(filenames), revision_id)
        log.warning(log_msg)
        return HttpResponseForbidden(
            'There is no such module in %s' % escape(
                revision.package.full_name))

    return render_json(request,
            "json/module_removed.json",
            {'revision': revision,
            'removed_modules': simplejson.dumps(removed_modules),
            'removed_dirs': simplejson.dumps(removed_dirs)})
开发者ID:seanmonstar,项目名称:FlightDeck,代码行数:30,代码来源:views.py

示例2: remove_attachment

def remove_attachment(request, revision_id):
    """
    Remove attachment from PackageRevision
    """
    revision = get_object_with_related_or_404(PackageRevision, pk=revision_id)
    if request.user.pk != revision.author.pk:
        log_msg = ('[security] Attempt to remove attachment from revision '
                '(%s) by non-owner (%s)' % (revision_id, request.user))
        log.warning(log_msg)
        return HttpResponseForbidden('You are not the author of this Package')

    uid = request.POST.get('uid', '').strip()
    attachment = get_object_with_related_or_404(Attachment,
                                                pk=uid, revisions=revision)

    if not attachment:
        log_msg = ('Attempt to remove a non existing attachment. attachment: '
                   '%s, revision: %s.' % (uid, revision_id))
        log.warning(log_msg)
        return HttpResponseForbidden(
            'There is no such attachment in %s' % escape(
                revision.package.full_name))

    revision.attachment_remove(attachment)

    return render_json(request,
            "json/attachment_removed.json",
            {'revision': revision, 'attachment': attachment})
开发者ID:seanmonstar,项目名称:FlightDeck,代码行数:28,代码来源:views.py

示例3: rmdir

def rmdir(request, pk, target, path):
    """
    Remove attachment from PackageRevision
    """
    revision = get_object_or_404(PackageRevision, pk=pk)
    if target not in ["data", "lib"]:
        return HttpResponseForbidden
    if target == "lib":
        return HttpResponseForbidden("not supported yet")

    revision.attachment_rmdir(path) if target == "data" else revision.modules_rmdir(path)
    return render_json(request, "%s_rmdir.json" % target, {"revision": revision, "path": path})
开发者ID:zalun,项目名称:FlightDeck,代码行数:12,代码来源:views.py

示例4: disable

def disable(request, pk):
    """
    Disable Package and return confirmation
    """
    package = get_object_or_404(Package, pk=pk)
    if request.user.pk != package.author.pk:
        log_msg = "User %s wanted to disable not his own Package %s." % (request.user, pk)
        log.warning(log_msg)
        return HttpResponseForbidden("You are not the author of this %s" % escape(package.get_type_name()))

    package.disable()

    return render_json(request, "json/package_disabled.json", {"package": package})
开发者ID:zalun,项目名称:FlightDeck,代码行数:13,代码来源:views.py

示例5: delete

def delete(request, pk):
    """
    Delete Package and return confirmation
    """
    package = get_object_or_404(Package, pk=pk)
    if request.user.pk != package.author.pk:
        log_msg = "[security] Attempt to delete package (%s) by " "non-owner (%s)" % (pk, request.user)
        log.warning(log_msg)
        return HttpResponseForbidden("You are not the author of this %s" % escape(package.get_type_name()))

    package.delete()

    return render_json(request, "json/package_deleted.json")
开发者ID:zalun,项目名称:FlightDeck,代码行数:13,代码来源:views.py

示例6: remove_folder

def remove_folder(request, revision_id):
    " removes an EmptyDir from a revision "
    revision = get_object_with_related_or_404(PackageRevision, pk=revision_id)
    if request.user.pk != revision.author.pk:
        log_msg = ("[security] Attempt to remove a folder from revision (%s) "
                "by non-owner (%s)" % (revision_id, request.user))
        log.warning(log_msg)
        return HttpResponseForbidden('You are not the author of this Package')

    foldername, root = (
            pathify(request.POST.get('name', '')),
            request.POST.get('root_dir'))
    try:
        folder = revision.folders.get(name=foldername, root_dir=root)
    except EmptyDir.DoesNotExist:
        response = None
        if root == 'data':
            response = revision.attachment_rmdir(foldername)
        if not response:
            log_msg = 'Attempt to delete a non existing folder %s from %s.' % (
                foldername, revision_id)
            log.warning(log_msg)
            return HttpResponseForbidden(
                'There is no such folder in %s' % escape(
                    revision.package.full_name))
        revision, removed_attachments, removed_emptydirs = response
        return render_json(request,
                'json/%s_rmdir.json' % root, {
                'revision': revision, 'path': foldername,
                'removed_attachments': simplejson.dumps(removed_attachments),
                'removed_dirs': simplejson.dumps(removed_emptydirs),
                'foldername': foldername})
    else:
        revision.folder_remove(folder)

    return render_json(request,
            "json/folder_removed.json",
            {'revision': revision, 'folder': folder})
开发者ID:seanmonstar,项目名称:FlightDeck,代码行数:38,代码来源:views.py

示例7: remove_folder

def remove_folder(request, revision_id):
    " removes an EmptyDir from a revision "
    revision = get_object_with_related_or_404(PackageRevision, pk=revision_id)
    if request.user.pk != revision.author.pk:
        log_msg = "[security] Attempt to remove a folder from revision (%s) " "by non-owner (%s)" % (
            revision_id,
            request.user,
        )
        log.warning(log_msg)
        return HttpResponseForbidden("You are not the author of this Package")

    foldername, root = (pathify(request.POST.get("name", "")), request.POST.get("root_dir"))
    try:
        folder = revision.folders.get(name=foldername, root_dir=root)
    except EmptyDir.DoesNotExist:
        response = None
        if root == "data":
            response = revision.attachment_rmdir(foldername)
        if not response:
            log_msg = "Attempt to delete a non existing folder %s from %s." % (foldername, revision_id)
            log.warning(log_msg)
            return HttpResponseForbidden("There is no such folder in %s" % escape(revision.package.full_name))
        revision, removed_attachments, removed_emptydirs = response
        return render_json(
            request,
            "json/%s_rmdir.json" % root,
            {
                "revision": revision,
                "path": foldername,
                "removed_attachments": simplejson.dumps(removed_attachments),
                "removed_dirs": simplejson.dumps(removed_emptydirs),
                "foldername": foldername,
            },
        )
    else:
        revision.folder_remove(folder)

    return render_json(request, "json/folder_removed.json", {"revision": revision, "folder": folder})
开发者ID:zalun,项目名称:FlightDeck,代码行数:38,代码来源:views.py

示例8: rmdir

def rmdir(request, pk, target, path):
    """
    Remove attachment from PackageRevision
    """
    revision = get_object_or_404(PackageRevision, pk=pk)
    if target not in ['data', 'lib']:
        return HttpResponseForbidden
    if target == 'lib':
        return HttpResponseForbidden('not supported yet')

    revision.attachment_rmdir(path) if target == 'data' else \
            revision.modules_rmdir(path)
    return render_json(request,
            '%s_rmdir.json' % target, {'revision': revision, 'path': path})
开发者ID:seanmonstar,项目名称:FlightDeck,代码行数:14,代码来源:views.py

示例9: rename_module

def rename_module(request, revision_id):
    """
    Rename a module in a PackageRevision
    """
    revision = get_object_with_related_or_404(PackageRevision, pk=revision_id)
    if request.user.pk != revision.author.pk:
        log_msg = ("[security] Attempt to rename a module to package (%s) by "
                   "non-owner (%s)" % (revision_id, request.user))
        log.warning(log_msg)
        return HttpResponseForbidden('You are not the author of this Package')

    old_name = request.POST.get('old_filename')
    new_name = request.POST.get('new_filename')

    if old_name == 'main':
        return HttpResponseForbidden(
            'Sorry, you cannot change the name of the main module.'
        )

    if not revision.validate_module_filename(new_name):
        return HttpResponseForbidden(
            ('Sorry, there is already a module in your add-on '
             'with the name "%s". Each module in your add-on '
             'needs to have a unique name.') % new_name
        )

    modules = revision.modules.all()
    module = None

    for mod in modules:
        if mod.filename == old_name:
            module = mod

    if not module:
        log_msg = 'Attempt to rename a non existing module %s from %s.' % (
            old_name, revision_id)
        log.warning(log_msg)
        return HttpResponseForbidden(
            'There is no such module in %s' % escape(
                revision.package.full_name))

    module.filename = new_name
    revision.add_commit_message('module renamed')
    revision.update(module)

    return render_json(request,
            "json/module_renamed.json",
            {'revision': revision, 'module': module})
开发者ID:seanmonstar,项目名称:FlightDeck,代码行数:48,代码来源:views.py

示例10: library_autocomplete

def library_autocomplete(request):
    """
    'Live' search by name
    """
    try:
        query = request.GET.get('q')
        limit = request.GET.get('limit', settings.LIBRARY_AUTOCOMPLETE_LIMIT)
        found = Package.objects.libraries().exclude(
            name='jetpack-core').filter(
                Q(name__icontains=query) | Q(full_name__icontains=query)
            )[:limit]
    except:
        found = []

    return render_json(request,
            'json/library_autocomplete.json', {'libraries': found})
开发者ID:clouserw,项目名称:FlightDeck,代码行数:16,代码来源:views.py

示例11: disable

def disable(request, id_number):
    """
    Disable Package and return confirmation
    """
    package = get_object_or_404(Package, id_number=id_number)
    if request.user.pk != package.author.pk:
        log_msg = 'User %s wanted to disable not his own Package %s.' % (
            request.user, id_number)
        log.warning(log_msg)
        return HttpResponseForbidden(
            'You are not the author of this %s' % escape(
                package.get_type_name()))

    package.disable()

    return render_json(request,
            "json/package_disabled.json",
            {'package': package})
开发者ID:clouserw,项目名称:FlightDeck,代码行数:18,代码来源:views.py

示例12: activate

def activate(request, id_number):
    """
    Undelete Package and return confirmation
    """
    package = get_object_or_404(Package, id_number=id_number)
    if request.user.pk != package.author.pk:
        log_msg = ("[security] Attempt to activate package (%s) by "
                   "non-owner (%s)" % (id_number, request.user))
        log.warning(log_msg)
        return HttpResponseForbidden(
            'You are not the author of this %s' % escape(
                package.get_type_name()))

    package.enable()

    return render_json(request,
            "json/package_activated.json",
            {'package': package})
开发者ID:clouserw,项目名称:FlightDeck,代码行数:18,代码来源:views.py

示例13: switch_sdk

def switch_sdk(request, revision_id):
    " switch SDK used to create XPI - sdk_id from POST "
    revision = get_object_with_related_or_404(PackageRevision, pk=revision_id)
    if request.user.pk != revision.author.pk:
        return HttpResponseForbidden('You are not the author of this Add-on')

    sdk_id = request.POST.get('id', None)
    sdk = get_object_or_404(SDK, id=sdk_id)
    old_sdk = revision.sdk
    log.info('Addon %s (%s) switched from Add-on Kit version %s to %s' % (
        revision.package.full_name, revision.package.id_number,
        old_sdk.version, sdk.version))
    revision.sdk = sdk
    revision.add_commit_message('Switched to Add-on Kit %s' % sdk.version)
    revision.save()

    return render_json(request,
            "json/sdk_switched.json",
            {'revision': revision, 'sdk': sdk,
             'sdk_lib': revision.get_sdk_revision()})
开发者ID:seanmonstar,项目名称:FlightDeck,代码行数:20,代码来源:views.py

示例14: rename_attachment

def rename_attachment(request, id_number, type_id, revision_number):
    """
    Rename an attachment in a PackageRevision
    """
    revision = get_package_revision(id_number, type_id, revision_number)
    if request.user.pk != revision.author.pk:
        log_msg = ("[security] Attempt to rename attachment in package (%s) "
                "by non-owner (%s)" % (id_number, request.user))
        log.warning(log_msg)
        return HttpResponseForbidden('You are not the author of this Package')

    uid = request.POST.get('uid', '').strip()
    try:
        attachment = revision.attachments.get(pk=uid)
    except:
        log_msg = ('Attempt to rename a non existing attachment. attachment: '
                   '%s, package: %s.' % (uid, id_number))
        log.warning(log_msg)
        return HttpResponseForbidden(
            'There is no such attachment in %s' % escape(
                revision.package.full_name))

    new_name = request.POST.get('new_filename')
    new_ext = request.POST.get('new_ext') or attachment.ext

    if not revision.validate_attachment_filename(new_name, new_ext):
        return HttpResponseForbidden(
            ('Sorry, there is already an attachment in your add-on '
             'with the name "%s.%s". Each attachment in your add-on '
             'needs to have a unique name.') % (new_name, attachment.ext)
        )
    attachment.filename = new_name
    attachment.ext = new_ext
    attachment = revision.update(attachment)

    return render_json(request,
            "json/attachment_renamed.json",
            {'revision': revision, 'attachment': attachment})
开发者ID:clouserw,项目名称:FlightDeck,代码行数:38,代码来源:views.py

示例15: copy

def copy(request, id_number, type_id,
                 revision_number=None, version_name=None):
    """
    Copy package - create a duplicate of the Package, set user as author
    """
    source = get_package_revision(id_number, type_id, revision_number,
                                  version_name)

    try:
        package = Package.objects.get(
            full_name=source.package.get_copied_full_name(),
            author__username=request.user.username
            )
    except Package.DoesNotExist:
        package = source.package.copy(request.user)
        source.save_new_revision(package)

        return render_json(request,
            "json/%s_copied.json" % package.get_type_name(),
            {'revision': source})

    return HttpResponseForbidden('You already have a %s with that name' %
                                 escape(source.package.get_type_name()))
开发者ID:clouserw,项目名称:FlightDeck,代码行数:23,代码来源:views.py


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