Changes between Version 1 and Version 2 of Ticket #32845
- Timestamp:
- Jun 13, 2021, 12:40:01 PM (3 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #32845 – Description
v1 v2 23 23 {{{ 24 24 ... 25 initial_filepath = model_instance.file.path 25 26 new_filename = 'sources/new_filename.pdf 26 initial_filepath = model_instance.file.path 27 new_filepath = os.path.join(settings.MEDIA_ROOT, new_filename) 28 # Verify the initial filepath exists and the new filepath does not yet exist. 27 29 assert os.path.exists(initial_filepath) 28 new_filepath = os.path.join(settings.MEDIA_ROOT, new_filename) 29 input( 30 if os.path.exists(new_filepath): 31 raise Exception(f'{new_filepath} already exists.') 32 print( 30 33 f'{model_instance.file.name} ---> {new_filename}\n' 31 34 f'{initial_filepath} ---> {new_filepath} ' 32 35 ) 33 if os.path.exists(new_filepath): 34 raise Exception(f'{new_filepath} already exists.')36 37 # Rename the file. 35 38 f.file.name = new_filename 36 assert os.path.exists(initial_filepath)37 39 os.rename(initial_filepath, new_filepath) 38 40 sleep(5) 41 42 # Verify the file was renamed successfully. 39 43 assert os.path.exists(new_filepath) 40 44 assert not os.path.exists(initial_filepath) 41 45 assert model_instance.file.name == new_filename 46 42 47 input('Continue? ') 48 49 # Save the model instance. 43 50 model_instance.save() 44 51 model_instance.refresh_from_db() 52 53 # Verify the file was renamed successfully. 45 54 assert model_instance.file.path == new_filepath, f'{model_instance.file.path} != {new_filepath}' 46 print()47 55 }}} 48 56