@require_POST
@csrf_protect
def snippet_save(request):
 if (not test_user_authenticated(request)):
  return login(request, next='/cobbler_web/snippet/list', expired=True)
 editmode = request.POST.get('editmode', 'edit')
 snippet_name = request.POST.get('snippet_name', None)
 snippetdata = request.POST.get('snippetdata', '').replace('\r\n', '\n')
 if (snippet_name is None):
  return HttpResponse('NO SNIPPET NAME SPECIFIED')
 if (editmode != 'edit'):
  if (snippet_name.find('/var/lib/cobbler/snippets/') != 0):
   snippet_name = ('/var/lib/cobbler/snippets/' + snippet_name)
 delete1 = request.POST.get('delete1', None)
 delete2 = request.POST.get('delete2', None)
 if (delete1 and delete2):
  remote.remove_autoinstall_snippet(snippet_name, request.session['token'])
  return HttpResponseRedirect('/cobbler_web/snippet/list')
 else:
  remote.write_autoinstall_snippet(snippet_name, snippetdata, request.session['token'])
  return HttpResponseRedirect('/cobbler_web/snippet/list')

@ require_POST @ csrf_protect def snippet_save ( request ) : if ( not test_user_authenticated ( request ) ) : return login ( request , next = '/cobbler_web/snippet/list' , expired = True ) editmode = request . POST . get ( 'editmode' , 'edit' ) snippet_name = request . POST . get ( 'snippet_name' , None ) snippetdata = request . POST . get ( 'snippetdata' , '' ) . replace ( '\r\n' , '\n' ) if ( snippet_name is None ) : return HttpResponse ( 'NO SNIPPET NAME SPECIFIED' ) if ( editmode != 'edit' ) : if ( snippet_name . find ( '/var/lib/cobbler/snippets/' ) != 0 ) : snippet_name = ( '/var/lib/cobbler/snippets/' + snippet_name ) delete1 = request . POST . get ( 'delete1' , None ) delete2 = request . POST . get ( 'delete2' , None ) if ( delete1 and delete2 ) : remote . remove_autoinstall_snippet ( snippet_name , request . session [ 'token' ] ) return HttpResponseRedirect ( '/cobbler_web/snippet/list' ) else : remote . write_autoinstall_snippet ( snippet_name , snippetdata , request . session [ 'token' ] ) return HttpResponseRedirect ( '/cobbler_web/snippet/list' )
this snippet saves a snippet once edited .