Skip to content

Commit

Permalink
Delete old QGIS project file on update.
Browse files Browse the repository at this point in the history
  • Loading branch information
wlorenzetti committed Nov 16, 2023
1 parent 481f07d commit 367eb19
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions g3w-admin/qdjango/receivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,36 @@ def delete_cache_project_settings(sender, **kwargs):

instance = kwargs['instance']

@receiver(pre_save, sender=Project)
def get_old_instance(sender, **kwargs):
"""
Get old instance before to update it
"""

try:
kwargs['instance']._meta.old_instance = sender.objects.get(pk=kwargs['instance'].pk)
except: # to handle initial object creation
return None # just exiting from signal

@receiver(post_save, sender=Project)
def delete_project_file_on_update(sender, **kwargs):
"""
On update delete old QGIS project file if is name changed
"""

# Only for update
if not kwargs['created']:
try:
instance = kwargs['instance']
old_instance = instance._meta.old_instance

if old_instance.qgis_file.path != instance.qgis_file.path:
os.remove(old_instance.qgis_file.path)
del(old_instance)
except Exception as e:
logger.error(e)



@receiver(post_delete, sender=Layer)
def remove_embedded_layers(sender, **kwargs):
Expand Down

0 comments on commit 367eb19

Please sign in to comment.