예제 #1
0
def delete(request, manifest_name=None):
    if request.method == 'POST':
        Manifest.delete(manifest_name, request.user)
        return HttpResponseRedirect('/manifest/')
    else:
        c = RequestContext(request, {'manifest_name': manifest_name})
        c.update(csrf(request))
        return render_to_response('manifests/delete.html', c)
예제 #2
0
def delete(request, manifest_name=None):
    if request.method == 'POST':
        Manifest.delete(manifest_name, request.user)
        return HttpResponseRedirect('/manifest/')
    else:
        c = RequestContext(request, {'manifest_name': manifest_name})
        c.update(csrf(request))
        return render_to_response('manifests/delete.html', c)
예제 #3
0
파일: views.py 프로젝트: wollardj/mwa2
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)
예제 #4
0
def delete(request, manifest_name=None):
    if not request.user.has_perm('reports.delete_machine'):
        return HttpResponse(json.dumps('error'))
    if request.method == 'POST':
        Manifest.delete(manifest_name, request.user)
        return HttpResponseRedirect('/manifest/')
    else:
        c = RequestContext(request, {'manifest_name': manifest_name})
        c.update(csrf(request))
        return render_to_response('manifests/delete.html', c)
예제 #5
0
def delete(request, manifest_name=None):
    if not request.user.has_perm("reports.delete_machine"):
        return HttpResponse(json.dumps("error"))
    if request.method == "POST":
        Manifest.delete(manifest_name, request.user)
        return HttpResponseRedirect("/%smanifest/" % SUB_PATH)
    else:
        c = RequestContext(request, {"manifest_name": manifest_name})
        c.update(csrf(request))
        return render_to_response("manifests/delete.html", c)
예제 #6
0
def delete(request, manifest_name=None):
    if not request.user.has_perm('reports.delete_machine'):
        return HttpResponse(json.dumps('error'))
    if request.method == 'POST':
        Manifest.delete(manifest_name, request.user)
        return HttpResponseRedirect('/%smanifest/' % SUB_PATH)
    else:
        c = RequestContext(request, {'manifest_name': manifest_name})
        c.update(csrf(request))
        return render_to_response('manifests/delete.html', c)
예제 #7
0
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)