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


Python Manifest.new方法代码示例

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


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

示例1: detail

# 需要导入模块: from models import Manifest [as 别名]
# 或者: from models.Manifest import new [as 别名]
def detail(request, manifest_path):
    if request.method == 'GET':
        print "Got read request for %s" % manifest_path
        manifest = Manifest.read(manifest_path)
        #autocomplete_data = Manifest.getAutoCompleteData(manifest_path)
        if manifest is None:
            raise Http404("%s does not exist" % manifest_path)
        c = {'plist_text': manifest,
             'pathname': manifest_path}
        return render(request, 'manifests/detail.html', context=c)
    if request.method == 'POST':
        # could be PUT, POST, or DELETE
        if request.META.has_key('HTTP_X_METHODOVERRIDE'):
            http_method = request.META['HTTP_X_METHODOVERRIDE']
            if http_method.lower() == 'delete':
                print "Got delete request for %s" % manifest_path
                if not request.user.has_perm('manifest.delete_manifestfile'):
                    raise PermissionDenied
                Manifest.delete(manifest_path, request.user)
                return HttpResponse(
                    json.dumps('success'), content_type='application/json')
            elif http_method.lower() == 'put':
                # regular POST (update/change)
                print "Got write request for %s" % manifest_path
                if not request.user.has_perm('manifest.change_manifestfile'):
                    raise PermissionDenied
                if request.is_ajax():
                    json_data = json.loads(request.body)
                    if json_data and 'plist_data' in json_data:
                        plist_data = json_data['plist_data'].encode('utf-8')
                        Manifest.write(
                            json_data['plist_data'], manifest_path,
                            request.user)
                        return HttpResponse(
                            json.dumps('success'),
                            content_type='application/json')
            else:
                print "Got unknown HTTP_X_METHODOVERRIDE for %s: %s" % (
                    manifest_path, http_method)
        else:
            # true POST request; create new resource
            print "Got create request for %s" % manifest_path
            try:
                json_data = json.loads(request.body)
            except ValueError:
                json_data = None
            if json_data and 'plist_data' in json_data:
                plist_data = json_data['plist_data'].encode('utf-8')
                Manifest.write(
                    json_data['plist_data'], manifest_path,
                    request.user)
            else:
                plist_data = Manifest.new(manifest_path, request.user)
            c = {'plist_text': plist_data,
                 'pathname': manifest_path,}
            return render(request, 'manifests/detail.html', context=c)
开发者ID:wollardj,项目名称:mwa2,代码行数:58,代码来源:views.py

示例2: new

# 需要导入模块: from models import Manifest [as 别名]
# 或者: from models.Manifest import new [as 别名]
def new(request):
    if request.method == "POST":  # If the form has been submitted...
        form = NewManifestForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            # Process the data in form.cleaned_data
            # ...
            # Redirect after POST
            manifest = Manifest.new()
            manifest_name = form.cleaned_data["manifest_name"]
            user_name = form.cleaned_data.get("user_name", "")
            manifest[MANIFEST_USERNAME_KEY] = user_name
            Manifest.write(manifest_name, manifest, request.user)
            return HttpResponseRedirect("/%smanifest/view/%s" % (SUB_PATH, manifest_name))
        else:
            # form not valid, try again
            c = RequestContext(request, {"form": form})
    else:
        form = NewManifestForm()  # An unbound form
        c = RequestContext(request, {"form": form})
        c.update(csrf(request))

    return render_to_response("manifests/new.html", c)
开发者ID:eahrold,项目名称:munkiwebadmin,代码行数:24,代码来源:views.py


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