#NEWLINE# @ classmethod #NEWLINE# def get_user_workspace( cls , user ) : #NEWLINE# #INDENT# '\n        Get the file workspace (directory) for a user.\n\n        Args:\n          user(User or HttpRequest): User or request object.\n\n        Returns:\n          tethys_apps.base.TethysWorkspace: An object representing the workspace.\n\n        **Example:**\n\n        ::\n\n            import os\n            from .app import MyFirstApp\n\n            def a_controller(request):\n                """\n                Example controller that uses get_user_workspace() method.\n                """\n                # Retrieve the workspace\n                user_workspace = MyFirstApp.get_user_workspace(request.user)\n                new_file_path = os.path.join(user_workspace.path, \'new_file.txt\')\n\n                with open(new_file_path, \'w\') as a_file:\n                    a_file.write(\'...\')\n\n                context = {}\n\n                return render(request, \'my_first_app/template.html\', context)\n\n        ' #NEWLINE# username = '' #NEWLINE# from django.contrib.auth.models import User #NEWLINE# if ( isinstance ( user , User ) or isinstance ( user , SimpleLazyObject ) ) : #NEWLINE# #INDENT# username = user . username #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( user , HttpRequest ) : #NEWLINE# #INDENT# username = user . user . username #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( user is None ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( "Invalid type for argument 'user': must be either an User or HttpRequest object." ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( not username ) : #NEWLINE# #INDENT# username = 'anonymous_user' #NEWLINE# #UNINDENT# project_directory = os . path . dirname ( sys . modules [ cls . __module__ ] . __file__ ) #NEWLINE# workspace_directory = os . path . join ( project_directory , 'workspaces' , 'user_workspaces' , username ) #NEWLINE# return TethysWorkspace ( workspace_directory )