本文整理汇总了Python中models.Manifest.write方法的典型用法代码示例。如果您正苦于以下问题:Python Manifest.write方法的具体用法?Python Manifest.write怎么用?Python Manifest.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Manifest
的用法示例。
在下文中一共展示了Manifest.write方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: detail
# 需要导入模块: from models import Manifest [as 别名]
# 或者: from models.Manifest import write [as 别名]
def detail(request, manifest_name):
if request.method == 'POST':
if not request.user.has_perm('reports.change_machine'):
return HttpResponse(json.dumps('error'))
if request.is_ajax():
json_data = json.loads(request.raw_post_data)
if json_data:
manifest_detail = Manifest.read(manifest_name)
for key in json_data.keys():
manifest_detail[key] = json_data[key]
Manifest.write(manifest_name, manifest_detail,
request.user)
return HttpResponse(json.dumps('success'))
if request.method == 'GET':
manifest = Manifest.read(manifest_name)
valid_install_items = Manifest.getValidInstallItems(manifest_name)
valid_catalogs = Catalog.list()
valid_manifest_names = Manifest.list()
manifest_user = manifest.get(MANIFEST_USERNAME_KEY, '')
c = RequestContext(request,
{'manifest_name': manifest_name.replace(':', '/'),
'manifest_user': manifest_user,
'manifest_user_is_editable': MANIFEST_USERNAME_IS_EDITABLE,
'manifest': manifest,
'valid_install_items': valid_install_items,
'valid_catalogs': valid_catalogs,
'valid_manifest_names': valid_manifest_names,
'user': request.user,
'page': 'manifests'})
c.update(csrf(request))
return render_to_response('manifests/detail.html', c)
示例2: detail
# 需要导入模块: from models import Manifest [as 别名]
# 或者: from models.Manifest import write [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)
示例3: detail
# 需要导入模块: from models import Manifest [as 别名]
# 或者: from models.Manifest import write [as 别名]
def detail(request, manifest_name):
if request.method == 'POST':
if not request.user.has_perm('manifests.change_manifests'):
return HttpResponse(json.dumps('error'))
if request.is_ajax():
json_data = json.loads(request.body)
if json_data:
manifest_detail = Manifest.read(manifest_name)
for key in json_data.keys():
manifest_detail[key] = json_data[key]
Manifest.write(manifest_name, manifest_detail,
request.user)
return HttpResponse(json.dumps('success'))
if request.method == 'GET':
if not request.user.has_perm('manifests.can_view_manifests'):
return HttpResponse(json.dumps('error'))
manifest = Manifest.read(manifest_name)
#valid_install_items = Manifest.getValidInstallItems(manifest_name)
install_items = Manifest.getInstallItemNames(manifest_name)
valid_install_items = (install_items['suggested'] +
install_items['updates'] +
install_items['with_version'])
suggested_install_items = install_items['suggested']
valid_catalogs = Catalog.list()
valid_manifest_names = Manifest.list()
autocomplete_data = json.dumps({
'items': install_items['suggested'],
'catalogs': valid_catalogs,
'manifests': valid_manifest_names
})
manifest_user = manifest.get(MANIFEST_USERNAME_KEY, '')
c = RequestContext(request,
{'manifest_name': manifest_name.replace(':', '/'),
'manifest_user': manifest_user,
'manifest_user_is_editable': MANIFEST_USERNAME_IS_EDITABLE,
'manifest': manifest,
'valid_install_items': valid_install_items,
'install_items': install_items,
'valid_catalogs': valid_catalogs,
'valid_manifest_names': valid_manifest_names,
'autocomplete_data': autocomplete_data,
'user': request.user,
'page': 'manifests'})
c.update(csrf(request))
return render_to_response('manifests/detail.html', c)
示例4: detail
# 需要导入模块: from models import Manifest [as 别名]
# 或者: from models.Manifest import write [as 别名]
def detail(request, manifest_name):
if request.method == "POST":
if not request.user.has_perm("reports.change_machine"):
return HttpResponse(json.dumps("error"))
if request.is_ajax():
json_data = json.loads(request.body)
if json_data:
manifest_detail = Manifest.read(manifest_name)
for key in json_data.keys():
manifest_detail[key] = json_data[key]
Manifest.write(manifest_name, manifest_detail, request.user)
return HttpResponse(json.dumps("success"))
if request.method == "GET":
manifest = Manifest.read(manifest_name)
# valid_install_items = Manifest.getValidInstallItems(manifest_name)
install_items = Manifest.getInstallItemNames(manifest_name)
valid_install_items = install_items["suggested"] + install_items["updates"] + install_items["with_version"]
suggested_install_items = install_items["suggested"]
valid_catalogs = Catalog.list()
valid_manifest_names = Manifest.list()
autocomplete_data = json.dumps(
{"items": install_items["suggested"], "catalogs": valid_catalogs, "manifests": valid_manifest_names}
)
manifest_user = manifest.get(MANIFEST_USERNAME_KEY, "")
c = RequestContext(
request,
{
"manifest_name": manifest_name.replace(":", "/"),
"manifest_user": manifest_user,
"manifest_user_is_editable": MANIFEST_USERNAME_IS_EDITABLE,
"manifest": manifest,
"valid_install_items": valid_install_items,
"install_items": install_items,
"valid_catalogs": valid_catalogs,
"valid_manifest_names": valid_manifest_names,
"autocomplete_data": autocomplete_data,
"user": request.user,
"page": "manifests",
},
)
c.update(csrf(request))
return render_to_response("manifests/detail.html", c)
示例5: new
# 需要导入模块: from models import Manifest [as 别名]
# 或者: from models.Manifest import write [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)
示例6: detail
# 需要导入模块: from models import Manifest [as 别名]
# 或者: from models.Manifest import write [as 别名]
def detail(request, manifest_name):
if request.method == 'POST':
if not request.user.has_perm('manifests.change_manifests'):
return HttpResponse(json.dumps('error'))
if request.is_ajax():
json_data = json.loads(request.body)
if json_data:
manifest_detail = Manifest.read(manifest_name)
for key in json_data.keys():
manifest_detail[key] = json_data[key]
Manifest.write(manifest_name, manifest_detail,
request.user)
logger.info("ManifestWrite instigated.")
return HttpResponse(json.dumps('success'))
if request.method == 'GET':
if not request.user.has_perm('manifests.can_view_manifests'):
return HttpResponse(json.dumps('error'))
manifest = Manifest.read(manifest_name)
#valid_install_items = Manifest.getValidInstallItems(manifest_name)
install_items = Manifest.getInstallItemNames(manifest_name)
valid_install_items = (install_items['suggested'] +
install_items['updates'] +
install_items['with_version'])
suggested_install_items = install_items['suggested']
valid_catalogs = Catalog.list()
valid_manifest_names = Manifest.list()
autocomplete_data = json.dumps({
'items': install_items['suggested'],
'catalogs': valid_catalogs,
'manifests': valid_manifest_names
})
manifest_user = manifest.get(MANIFEST_USERNAME_KEY, '')
manifest_restriction = manifest.get(MANIFEST_RESTRICTION_KEY, '')
user_groups = Group.objects.values_list('name', flat=True)
if manifest_restriction:
manifest_restriction_is_editable = None
if request.user.is_superuser:
manifest_restriction_is_editable = 'yes'
elif request.user.is_staff and 'staff' in manifest_restriction:
manifest_restriction_is_editable = 'yes'
else:
for item in manifest_restriction:
if Manifest.can_edit_restricted_manifest(request.user, item):
manifest_restriction_is_editable = 'yes'
else:
manifest_restriction_is_editable = 'unrestricted'
git_branching_enabled = None
if GIT_BRANCHING:
git_branching_enabled = GIT_BRANCHING
c = RequestContext(request,
{'manifest_name': manifest_name.replace(':', '/'),
'manifest_user': manifest_user,
'manifest_user_is_editable': MANIFEST_USERNAME_IS_EDITABLE,
'manifest': manifest,
'valid_install_items': valid_install_items,
'install_items': install_items,
'valid_catalogs': valid_catalogs,
'valid_manifest_names': valid_manifest_names,
'autocomplete_data': autocomplete_data,
'git_branching_enabled': git_branching_enabled,
'restriction_key': MANIFEST_RESTRICTION_KEY,
'manifest_restriction': manifest_restriction,
'manifest_restriction_is_editable': manifest_restriction_is_editable,
'user_groups': user_groups,
'user': request.user,
'page': 'manifests'})
c.update(csrf(request))
return render_to_response('manifests/detail.html', c)