#NEWLINE# def fm_rename_file( request ) : #NEWLINE# #INDENT# pathfile = request . POST . get ( 'dir' , None ) #NEWLINE# newfile = request . POST . get ( 'new_name' , None ) #NEWLINE# ret = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# if ( pathfile and newfile ) : #NEWLINE# #INDENT# path = clean_path ( pathfile ) #NEWLINE# if ( path != pathfile ) : #NEWLINE# #INDENT# ret [ 'message' ] = gettext ( 'Incorrect path' ) #NEWLINE# ret [ 'status' ] = 'error' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ( buser , bmanager ) = get_user_access_to_path ( request . user , path ) #NEWLINE# if ( bmanager is False ) : #NEWLINE# #INDENT# ret [ 'message' ] = gettext ( 'Access denied' ) #NEWLINE# ret [ 'status' ] = 'error' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# oldfile = os . path . basename ( path ) #NEWLINE# tab = oldfile . split ( ',' ) #NEWLINE# path = os . path . dirname ( path ) #NEWLINE# s = os . path . splitext ( newfile ) #NEWLINE# fname = slugify ( s [ 0 ] ) #NEWLINE# fext = s [ 1 ] #NEWLINE# dest = ( '%s/%s/%s' % ( get_upload_library ( ) , path , ( '%s,%s%s' % ( tab [ 0 ] , fname , fext ) ) ) ) #NEWLINE# src = ( '%s/%s/%s' % ( get_upload_library ( ) , path , oldfile ) ) #NEWLINE# os . rename ( src , dest ) #NEWLINE# file = ZornaFile . objects . get ( pk = int ( tab [ 0 ] ) ) #NEWLINE# file . modifier = request . user #NEWLINE# file . save ( ) #NEWLINE# ret [ 'message' ] = gettext ( 'File renamed successfully' ) #NEWLINE# ret [ 'status' ] = 'success' #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# ret [ 'message' ] = gettext ( 'Invalid file path' ) #NEWLINE# ret [ 'status' ] = 'error' #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ( ret [ 'status' ] == 'error' ) : #NEWLINE# #INDENT# ret [ 'new_name' ] = os . path . basename ( pathfile ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ret [ 'new_name' ] = ( '%s%s' % ( fname , fext ) ) #NEWLINE# #UNINDENT# json_data = simplejson . dumps ( tab ) #NEWLINE# return HttpResponse ( json_data )