@@ -166,16 +166,16 @@ def delete(self, user=None, parent=None, **kwargs):
166
166
self ._materialized_path = self .materialized_path
167
167
return super (OsfStorageFileNode , self ).delete (user = user , parent = parent ) if self ._check_delete_allowed () else None
168
168
169
+ def update_region_from_latest_version (self , destination_parent ):
170
+ raise NotImplementedError
171
+
169
172
def move_under (self , destination_parent , name = None ):
170
173
if self .is_preprint_primary :
171
174
if self .target != destination_parent .target or self .provider != destination_parent .provider :
172
175
raise exceptions .FileNodeIsPrimaryFile ()
173
176
if self .is_checked_out :
174
177
raise exceptions .FileNodeCheckedOutError ()
175
- most_recent_fileversion = self .versions .select_related ('region' ).order_by ('-created' ).first ()
176
- if most_recent_fileversion and most_recent_fileversion .region != destination_parent .target .osfstorage_region :
177
- most_recent_fileversion .region = destination_parent .target .osfstorage_region
178
- most_recent_fileversion .save ()
178
+ self .update_region_from_latest_version (destination_parent )
179
179
return super (OsfStorageFileNode , self ).move_under (destination_parent , name )
180
180
181
181
def check_in_or_out (self , user , checkout , save = False ):
@@ -293,6 +293,12 @@ def serialize(self, include_full=None, version=None):
293
293
})
294
294
return ret
295
295
296
+ def update_region_from_latest_version (self , destination_parent ):
297
+ most_recent_fileversion = self .versions .select_related ('region' ).order_by ('-created' ).first ()
298
+ if most_recent_fileversion and most_recent_fileversion .region != destination_parent .target .osfstorage_region :
299
+ most_recent_fileversion .region = destination_parent .target .osfstorage_region
300
+ most_recent_fileversion .save ()
301
+
296
302
def create_version (self , creator , location , metadata = None ):
297
303
latest_version = self .get_version ()
298
304
version = FileVersion (identifier = self .versions .count () + 1 , creator = creator , location = location )
@@ -451,6 +457,9 @@ def serialize(self, include_full=False, version=None):
451
457
ret ['fullPath' ] = self .materialized_path
452
458
return ret
453
459
460
+ def update_region_from_latest_version (self , destination_parent ):
461
+ for child in self .children .all ().prefetch_related ('versions' ):
462
+ child .update_region_from_latest_version (destination_parent )
454
463
455
464
class Region (models .Model ):
456
465
_id = models .CharField (max_length = 255 , db_index = True )
0 commit comments