Diverse Code Cleanups

*Code wurde PEP-8 gerecht formatiert
* Kleine Fehler die der PyCharm Inspector beanstandet wurden korrigiert
This commit is contained in:
Christian Berg
2014-11-26 16:04:52 +01:00
committed by Christian Berg
parent f34281089d
commit 86a0db050d
76 changed files with 619 additions and 528 deletions

View File

@@ -1,15 +1,13 @@
# -*- coding: utf-8 -*-
from django.contrib.auth.models import User
from django.core.management.base import BaseCommand
from django.utils.translation import ugettext_lazy as _
from membership.models import ActivationRequest
class Command(BaseCommand):
help = "Delete all expired user registrations from the database"
def handle(self, *args, **options):
for activation in ActivationRequest.objects.expired():
activation.user.delete()

View File

@@ -8,10 +8,10 @@ It might help your debugging to know or you might want to contact the user to
tell them you have fixed the problem.
"""
from django.contrib.auth.models import User
from django.conf import settings
from django.contrib import auth
from django.contrib.sessions.models import Session
from django.core.management.base import BaseCommand, CommandError
from django.utils.translation import ugettext_lazy as _
from django.core.management.base import BaseCommand
from optparse import make_option
@@ -19,33 +19,36 @@ class Command(BaseCommand):
args = '<session_key session_key ...>'
help = 'If the session still exists find it and show the related User'
option_list = BaseCommand.option_list + (
make_option('--delete',
make_option(
'--delete',
action='store_true',
dest='delete',
default=False,
help='Delete the Useraccount'),
make_option('--ban',
help='Delete the Useraccount'
),
make_option(
'--ban',
action='store_true',
dest='ban',
default=False,
help='Ban the Useraccount'),
)
help='Ban the Useraccount'
),
)
def handle(self, *args, **options):
for session_key in args:
try:
session = Session.objects.get(session_key=session_key)
uid = session.get_decoded().get('_auth_user_id')
user = User.objects.get(pk=uid)
user = auth.get_user_model().objects.get(pk=uid)
except Session.DoesNotExist:
self.stderr.write('Session "%s" does not exist' % session_key)
continue
except User.DoesNotExist:
except settings.AUTH_USER_MODEL.DoesNotExist:
self.stderr.write('Session "%s" has no registed User' % session_key)
continue
if options['delete']:
self.stdout.write('deleting %s'% user.username)
self.stdout.write('deleting %s' % user.username)
user.delete()
elif options['ban']:
self.stdout.write('banning %s' % user.username)