Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Delete old QGIS project file on update. #660

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading