<s> from ionyweb . administration . views import IsSuperAdminView <EOL> from djangorestframework . response import Response , ErrorResponse <EOL> from djangorestframework import status <EOL> from django . conf import settings <EOL> from django . template . loader import render_to_string <EOL> from django . template import RequestContext <EOL> from ionyweb . administration . utils import MESSAGES <EOL> from ionyweb . file_manager . models import File , Directory <EOL> from ionyweb . file_manager . views import ( render_quota_html , <EOL> render_directories_list_html , <EOL> render_files_list_html ) <EOL> from ionyweb . file_manager . functions import get_path_or_create <EOL> class FileManagerQuota ( IsSuperAdminView ) : <EOL> def get ( self , request ) : <EOL> quota = render_quota_html ( request ) <EOL> response = Response ( status . HTTP_200_OK , { "<STR_LIT>" : quota } ) <EOL> return self . render ( response ) <EOL> class FileManagerPanel ( IsSuperAdminView ) : <EOL> def get ( self , request ) : <EOL> directory_list = render_directories_list_html ( request ) <EOL> files_list = render_files_list_html ( request ) <EOL> quota = render_quota_html ( request ) <EOL> selector = False <EOL> if '<STR_LIT>' in request . GET : <EOL> selector = True <EOL> html = render_to_string ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : files_list , <EOL> '<STR_LIT>' : quota , <EOL> '<STR_LIT>' : directory_list , <EOL> '<STR_LIT>' : selector } , <EOL> context_instance = RequestContext ( request ) ) <EOL> response = Response ( status . HTTP_200_OK , { "<STR_LIT:html>" : html } ) <EOL> return self . render ( response ) <EOL> def post ( self , request ) : <EOL> """<STR_LIT>""" <EOL> drop = request . POST . get ( '<STR_LIT>' ) <EOL> inside = request . POST . get ( '<STR_LIT>' ) <EOL> current_dir = request . POST . get ( '<STR_LIT>' ) <EOL> dir_inside = Directory . objects . get ( pk = inside . strip ( '<STR_LIT>' ) ) <EOL> if drop . startswith ( '<STR_LIT>' ) : <EOL> dir_drop = Directory . objects . get ( pk = drop . strip ( '<STR_LIT>' ) ) <EOL> dir_drop . parent = dir_inside <EOL> else : <EOL> dir_drop = File . objects . get ( pk = drop ) <EOL> dir_drop . dir = dir_inside <EOL> dir_drop . save ( ) <EOL> directory_list = render_directories_list_html ( request , current_dir ) <EOL> response = Response ( status . HTTP_200_OK , { "<STR_LIT>" : directory_list } ) <EOL> return self . render ( response ) <EOL> class FileManagerFile ( IsSuperAdminView ) : <EOL> def get ( self , request , pk = None ) : <EOL> managed_file = File . objects . get ( pk = pk ) <EOL> selector = None <EOL> if '<STR_LIT>' in request . GET and request . GET . get ( '<STR_LIT>' ) == '<STR_LIT:true>' : <EOL> selector = managed_file . get_selector_button ( ) <EOL> html = render_to_string ( '<STR_LIT>' , <EOL> { '<STR_LIT:file>' : managed_file , <EOL> '<STR_LIT>' : selector } , <EOL> context_instance = RequestContext ( request ) ) <EOL> response = Response ( status . HTTP_200_OK , { "<STR_LIT:html>" : html } ) <EOL> return self . render ( response ) <EOL> def post ( self , request , pk ) : <EOL> managed_file = File . objects . get ( pk = pk ) <EOL> managed_file . rename ( request . POST . get ( '<STR_LIT:name>' ) ) <EOL> response = Response ( status . HTTP_200_OK , { "<STR_LIT>" : "<STR_LIT>" } ) <EOL> return self . render ( response ) <EOL> def delete ( self , request , pk ) : <EOL> managed_file = File . objects . get ( pk = pk ) <EOL> managed_file . delete ( ) <EOL> quota = render_quota_html ( request ) <EOL> response = Response ( status . HTTP_200_OK , { "<STR_LIT>" : quota } ) <EOL> return self . render ( response ) <EOL> class FileManagerDirectory ( IsSuperAdminView ) : <EOL> def get ( self , request , pk = None ) : <EOL> if pk == "<STR_LIT:0>" : <EOL> managed_dir = request . website . file_manager ( ) . root <EOL> else : <EOL> managed_dir = Directory . objects . get ( pk = pk ) <EOL> if managed_dir . get_root ( ) . filemanager . get ( ) . website . get ( ) != request . website : <EOL> raise ErrorResponse ( status . HTTP_400_BAD_REQUEST , <EOL> { '<STR_LIT>' : MESSAGES . get ( '<STR_LIT>' , "<STR_LIT>" ) } ) <EOL> files_list = render_files_list_html ( request , managed_dir ) <EOL> response = Response ( status . HTTP_200_OK , { "<STR_LIT:html>" : files_list } ) <EOL> return self . render ( response ) <EOL> def put ( self , request , pk = None ) : <EOL> if pk == "<STR_LIT:0>" : <EOL> managed_dir = request . website . file_manager ( ) . root <EOL> else : <EOL> managed_dir = Directory . objects . get ( pk = pk ) <EOL> new_dir = Directory ( ) <EOL> new_dir . name = "<STR_LIT>" <EOL> new_dir . parent = managed_dir <EOL> new_dir . save ( ) <EOL> files_list = render_files_list_html ( request , managed_dir ) <EOL> directory_list = render_directories_list_html ( request ) <EOL> response = Response ( status . HTTP_200_OK , { "<STR_LIT>" : files_list , "<STR_LIT>" : directory_list , '<STR_LIT:id>' : new_dir . id } ) <EOL> return self . render ( response ) <EOL> def post ( self , request , pk = None ) : <EOL> if pk == "<STR_LIT:0>" : <EOL> managed_dir = request . website . file_manager ( ) . root <EOL> else : <EOL> managed_dir = Directory . objects . get ( pk = pk ) <EOL> managed_dir . rename ( request . POST . get ( '<STR_LIT:name>' ) ) ; <EOL> files_list = render_files_list_html ( request , managed_dir . parent ) <EOL> directory_list = render_directories_list_html ( request ) <EOL> response = Response ( status . HTTP_200_OK , { "<STR_LIT>" : files_list , "<STR_LIT>" : directory_list } ) <EOL> return self . render ( response ) <EOL> def delete ( self , request , pk ) : <EOL> Directory . objects . get ( pk = pk ) . delete ( ) <EOL> directory_list = render_directories_list_html ( request ) <EOL> quota = render_quota_html ( request ) <EOL> response = Response ( status . HTTP_200_OK , { "<STR_LIT>" : directory_list , "<STR_LIT>" : quota } ) <EOL> return self . render ( response ) <EOL> class FileManagerThumbnailFile ( IsSuperAdminView ) : <EOL> def get ( self , request ) : <EOL> path = request . GET . get ( '<STR_LIT:path>' ) <EOL> size = request . GET . get ( '<STR_LIT:size>' ) <EOL> thumbnail = get_path_or_create ( path . strip ( settings . MEDIA_URL ) , size , path . strip ( settings . MEDIA_URL ) [ : - len ( path . split ( "<STR_LIT:/>" ) [ - <NUM_LIT:1> ] ) ] ) <EOL> response = Response ( status . HTTP_200_OK , { "<STR_LIT>" : "<STR_LIT>" % ( settings . MEDIA_URL , thumbnail ) } ) <EOL> return self . render ( response ) <EOL> class FileManagerDisplayMode ( IsSuperAdminView ) : <EOL> def post ( self , request ) : <EOL> mode = request . POST . get ( '<STR_LIT>' ) <EOL> list_mode = [ ] <EOL> for i in settings . DISPLAY_MODE : <EOL> list_mode . append ( i [ <NUM_LIT:0> ] ) <EOL> if mode in list_mode : <EOL> profile = request . user . profile . get ( ) <EOL> profile . file_manager_display_mode = mode <EOL> profile . save ( ) <EOL> response = Response ( status . HTTP_200_OK ) <EOL> return self . render ( response ) <EOL> else : <EOL> response = Response ( status . HTTP_404_NOT_FOUND ) <EOL> return self . render ( response ) </s>
