Skip to content

Commit

Permalink
Fixed cleanup of hunt resources on clear
Browse files Browse the repository at this point in the history
  • Loading branch information
dlareau committed Nov 9, 2020
1 parent 0750998 commit ceb6c3c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions huntserver/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ def save(self, *args, **kwargs):
self.full_clean()
if self.is_current_hunt:
Hunt.objects.filter(is_current_hunt=True).update(is_current_hunt=False)
if(self.resource_file.name == ""):
old_obj = Hunt.objects.get(pk=self.pk)
if(old_obj.resource_file.name != ""):
extension = old_obj.resource_file.name.split('.')[-1]
folder = "".join(old_obj.resource_file.name.split('.')[:-1])
if(extension == "zip"):
shutil.rmtree(os.path.join(settings.MEDIA_ROOT, folder), ignore_errors=True)
if os.path.exists(os.path.join(settings.MEDIA_ROOT, old_obj.resource_file.name)):
os.remove(os.path.join(settings.MEDIA_ROOT, old_obj.resource_file.name))
super(Hunt, self).save(*args, **kwargs)

@property
Expand Down

0 comments on commit ceb6c3c

Please sign in to comment.