mirror of
https://github.com/DarrenOfficial/dpaste.git
synced 2024-11-23 11:56:36 +11:00
Addresses bug in cleanup_snippets script related to non-integer values for EXPIRE_DEFAULT (#192)
See https://github.com/DarrenOfficial/dpaste/issues/191 Co-authored-by: Darren <github@darrennathanael.com>
This commit is contained in:
parent
d56fd5cfa8
commit
7a64572cc1
1 changed files with 15 additions and 14 deletions
|
@ -21,24 +21,25 @@ class Command(BaseCommand):
|
||||||
),
|
),
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
deleteable_snippets = (
|
|
||||||
# Snippets which are expired but haven't been deleted by
|
# Snippets which are expired but haven't been deleted by
|
||||||
# the view.
|
# the view.
|
||||||
Snippet.objects.filter(
|
deleteable_snippets = Snippet.objects.filter(
|
||||||
expires__isnull=False,
|
expires__isnull=False,
|
||||||
expire_type=Snippet.EXPIRE_TIME,
|
expire_type=Snippet.EXPIRE_TIME,
|
||||||
expires__lte=timezone.now(),
|
expires__lte=timezone.now(),
|
||||||
)
|
)
|
||||||
# Snipoets which are Onetime snippets but have never been viewed
|
|
||||||
|
# Snipets which are Onetime snippets but have never been viewed
|
||||||
# the second time. Delete them if they are older than our default
|
# the second time. Delete them if they are older than our default
|
||||||
# expiration.
|
# expiration, unless that default is not an integer (e.g., 'never')
|
||||||
| Snippet.objects.filter(
|
if isinstance(config.EXPIRE_DEFAULT, int):
|
||||||
|
onetime_unviewed_snippets = Snippet.objects.filter(
|
||||||
expire_type=Snippet.EXPIRE_ONETIME,
|
expire_type=Snippet.EXPIRE_ONETIME,
|
||||||
published__lte=(
|
published__lte=(
|
||||||
timezone.now() - timedelta(seconds=config.EXPIRE_DEFAULT)
|
timezone.now() - timedelta(seconds=config.EXPIRE_DEFAULT)
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
deleteable_snippets = (expired_snippets | onetime_unviewed_snippets)
|
||||||
|
|
||||||
if len(deleteable_snippets) == 0:
|
if len(deleteable_snippets) == 0:
|
||||||
self.stdout.write(u"No snippets to delete.")
|
self.stdout.write(u"No snippets to delete.")
|
||||||
|
|
Loading…
Reference in a new issue