def new_worksheet(name): """ Create a new worksheet with the given |name|. """ if not request.user.is_authenticated: raise PermissionError("You must be logged in to create a worksheet.") ensure_unused_worksheet_name(name) # Don't need any permissions to do this. worksheet = Worksheet({ 'name': name, 'title': None, 'frozen': None, 'items': [], 'owner_id': request.user.user_id }) local.model.new_worksheet(worksheet) # Make worksheet publicly readable by default set_worksheet_permission(worksheet, local.model.public_group_uuid, GROUP_OBJECT_PERMISSION_READ) if spec_util.is_dashboard(name): populate_worksheet(worksheet, 'dashboard', 'CodaLab Dashboard') if spec_util.is_public_home(name): populate_worksheet(worksheet, 'home', 'Public Home') return worksheet.uuid
def get_worksheet_uuid_or_create(base_worksheet_uuid, worksheet_spec): """ Return the uuid of the specified worksheet if it exists. If not, create a new worksheet if the specified worksheet is home_worksheet or dashboard. Otherwise, throw an error. """ try: return canonicalize.get_worksheet_uuid( local.model, request.user, base_worksheet_uuid, worksheet_spec ) except NotFoundError: # A bit hacky, duplicates a bit of canonicalize if (worksheet_spec == '' or worksheet_spec == HOME_WORKSHEET) and request.user: return new_worksheet(spec_util.home_worksheet(request.user.user_name)) elif spec_util.is_dashboard(worksheet_spec): return new_worksheet(worksheet_spec) else: raise
def get_worksheet_uuid_or_create(base_worksheet_uuid, worksheet_spec): """ Return the uuid of the specified worksheet if it exists. If not, create a new worksheet if the specified worksheet is home_worksheet or dashboard. Otherwise, throw an error. """ try: return canonicalize.get_worksheet_uuid( local.model, request.user, base_worksheet_uuid, worksheet_spec ) except NotFoundError: # A bit hacky, duplicates a bit of canonicalize if (worksheet_spec == '' or worksheet_spec == HOME_WORKSHEET) and request.user: return new_worksheet(spec_util.home_worksheet(request.user.user_name)) elif spec_util.is_dashboard(worksheet_spec): return new_worksheet(worksheet_spec) else: raise
def new_worksheet(name): """ Create a new worksheet with the given |name|. """ if not request.user.is_authenticated: raise PermissionError("You must be logged in to create a worksheet.") ensure_unused_worksheet_name(name) # Don't need any permissions to do this. worksheet = Worksheet( {'name': name, 'title': None, 'frozen': None, 'items': [], 'owner_id': request.user.user_id} ) local.model.new_worksheet(worksheet) # Make worksheet publicly readable by default set_worksheet_permission(worksheet, local.model.public_group_uuid, GROUP_OBJECT_PERMISSION_READ) if spec_util.is_dashboard(name): populate_worksheet(worksheet, 'dashboard', 'CodaLab Dashboard') if spec_util.is_public_home(name): populate_worksheet(worksheet, 'home', 'Public Home') return worksheet.uuid