Code cleanup and update for Django 1.10. Fixed all warnings.

This commit is contained in:
Martin Mahner 2016-09-04 20:06:07 +02:00
parent a39697bdeb
commit b51c16bcbc
4 changed files with 14 additions and 10 deletions

View file

@ -1,26 +1,29 @@
import sys import sys
from optparse import make_option from optparse import make_option
from django.core.management.base import LabelCommand from django.core.management.base import BaseCommand
from django.utils import timezone from django.utils import timezone
from dpaste.models import Snippet from dpaste.models import Snippet
class Command(LabelCommand): class Command(BaseCommand):
option_list = LabelCommand.option_list + (
make_option('--dry-run', '-d', action='store_true', dest='dry_run',
help='Don\'t do anything.'),
)
help = "Purges snippets that are expired" help = "Purges snippets that are expired"
def add_arguments(self, parser):
parser.add_argument('--dry-run', action='store_true', dest='dry_run',
help='Don\'t do anything.'),
def handle(self, *args, **options): def handle(self, *args, **options):
deleteable_snippets = 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()
) )
self.stdout.write(u"%s snippets gets deleted:\n" % deleteable_snippets.count()) if len(deleteable_snippets) == 0:
self.stdout.write(u"No snippets to delete.")
return None
self.stdout.write(u"Will delete %s snippet(s):\n" % deleteable_snippets.count())
for d in deleteable_snippets: for d in deleteable_snippets:
self.stdout.write(u"- %s (%s)\n" % (d.secret_id, d.expires)) self.stdout.write(u"- %s (%s)\n" % (d.secret_id, d.expires))
if options.get('dry_run'): if options.get('dry_run'):

View file

@ -1,7 +1,6 @@
from dpaste.settings.base import * from dpaste.settings.base import *
DEBUG = True DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = ( ADMINS = (
#('Your Name', 'name@example.com'), #('Your Name', 'name@example.com'),

View file

@ -1,4 +1,4 @@
from django.conf.urls import patterns, url from django.conf.urls import url
from ..views import snippet_api from ..views import snippet_api

View file

@ -40,7 +40,9 @@ SETTINGS = {
), ),
'STATIC_ROOT': '/tmp/dpaste_test_static/', 'STATIC_ROOT': '/tmp/dpaste_test_static/',
'STATIC_URL': '/static/', 'STATIC_URL': '/static/',
'ROOT_URLCONF': 'dpaste.urls' 'ROOT_URLCONF': 'dpaste.urls',
'LANGUAGE_CODE': 'en',
'LANGUAGES': (('en', 'English'),),
} }
def runtests(*test_args): def runtests(*test_args):