#NEWLINE# def fm_manage_folder( request ) : #NEWLINE# #INDENT# ret = { #NEWLINE# #INDENT# 'data' : '' , #NEWLINE# #UNINDENT# } #NEWLINE# if ( request . method == 'POST' ) : #NEWLINE# #INDENT# what = request . POST . get ( 'what' , '' ) #NEWLINE# ppath = request . POST . get ( 'path_rel' , '' ) #NEWLINE# ppath = urllib . unquote ( ppath . rstrip ( '/' ) ) #NEWLINE# folder_dest = clean_path ( ppath ) #NEWLINE# ( buser , bmanager ) = get_user_access_to_path ( request . user , folder_dest ) #NEWLINE# if ( folder_dest and bmanager ) : #NEWLINE# #INDENT# root_path = get_upload_library ( ) #NEWLINE# path_dest = clean_path ( folder_dest ) #NEWLINE# parts = path_dest . split ( '/' ) #NEWLINE# if ( ( what == 'rename' ) and ( len ( parts ) > 1 ) ) : #NEWLINE# #INDENT# new_folder = request . POST . get ( 'new_folder' , '' ) . strip ( ) #NEWLINE# n_folder = clean_path ( new_folder ) #NEWLINE# if ( new_folder == n_folder ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# n_folder = urllib . unquote ( n_folder ) #NEWLINE# path_src = ( '%s/%s' % ( root_path , urllib . unquote ( path_dest ) ) ) #NEWLINE# dest = parts [ : ( - 1 ) ] #NEWLINE# dest = '/' . join ( dest ) #NEWLINE# path_dest = ( '%s/%s/%s' % ( root_path , urllib . unquote ( dest ) , n_folder ) ) #NEWLINE# os . rename ( path_src , path_dest ) #NEWLINE# ret [ 'status' ] = 'success' #NEWLINE# ret [ 'message' ] = gettext ( 'Folder renamed successfully' ) #NEWLINE# ret [ 'data' ] = ( '%s/%s/' % ( urllib . unquote ( dest ) , n_folder ) ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# ret [ 'status' ] = 'error' #NEWLINE# ret [ 'message' ] = e #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# ret [ 'status' ] = 'error' #NEWLINE# ret [ 'message' ] = gettext ( 'Invalid folder name' ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( what == 'create' ) : #NEWLINE# #INDENT# new_folder = request . POST . get ( 'new_folder' , '' ) . strip ( ) #NEWLINE# n_folder = clean_path ( new_folder ) #NEWLINE# if ( new_folder == n_folder ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# n_folder = urllib . unquote ( n_folder ) #NEWLINE# rel = ( '%s/%s' % ( urllib . unquote ( path_dest ) , n_folder ) ) #NEWLINE# path = ( '%s/%s' % ( root_path , rel ) ) #NEWLINE# os . mkdir ( path ) #NEWLINE# ret [ 'status' ] = 'success' #NEWLINE# ret [ 'message' ] = gettext ( 'Folder created successfully' ) #NEWLINE# ret [ 'data' ] = ( '<li class="directory collapsed"><a href="#" rel="%s/">%s</a></li>' % ( rel , n_folder ) ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# ret [ 'status' ] = 'error' #NEWLINE# ret [ 'message' ] = e #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# ret [ 'status' ] = 'error' #NEWLINE# ret [ 'message' ] = gettext ( 'Invalid folder name' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# ret [ 'status' ] = 'error' #NEWLINE# ret [ 'message' ] = gettext ( 'Access denied' ) #NEWLINE# #UNINDENT# #UNINDENT# return HttpResponse ( simplejson . dumps ( ret ) )