def detail(request, pkginfo_path): if request.method == 'GET': print "Got read request for %s" % pkginfo_path pkginfo = Pkginfo.read(pkginfo_path) if pkginfo is None: raise Http404("%s does not exist" % pkginfo_path) c = {'plist_text': pkginfo, 'pathname': pkginfo_path} return render(request, 'pkgsinfo/detail.html', context=c) if request.method == 'POST': # 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" % pkginfo_path if not request.user.has_perm('pkgsinfo.delete_pkginfofile'): raise PermissionDenied json_data = json.loads(request.body) Pkginfo.delete(pkginfo_path, request.user, delete_pkg=json_data.get('deletePkg', False)) return HttpResponse(json.dumps('success'), content_type='application/json') # regular POST (update/change) print "Got write request for %s" % pkginfo_path if not request.user.has_perm('pkgsinfo.change_pkginfofile'): 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') Pkginfo.write(json_data['plist_data'], pkginfo_path, request.user) return HttpResponse(json.dumps('success'), content_type='application/json')
def detail(request, pkginfo_path): if request.method == 'GET': print "Got read request for %s" % pkginfo_path pkginfo = Pkginfo.read(pkginfo_path) if pkginfo is None: raise Http404("%s does not exist" % pkginfo_path) c = {'plist_text': pkginfo, 'pathname': pkginfo_path} return render(request, 'pkgsinfo/detail.html', context=c) if request.method == 'POST': # 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" % pkginfo_path if not request.user.has_perm('pkgsinfo.delete_pkginfofile'): raise PermissionDenied json_data = json.loads(request.body) Pkginfo.delete( pkginfo_path, request.user, delete_pkg=json_data.get('deletePkg', False) ) return HttpResponse( json.dumps('success'), content_type='application/json') # regular POST (update/change) print "Got write request for %s" % pkginfo_path if not request.user.has_perm('pkgsinfo.change_pkginfofile'): 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') Pkginfo.write( json_data['plist_data'], pkginfo_path, request.user) return HttpResponse( json.dumps('success'), content_type='application/json')