mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-13 23:32:21 +01:00
Marietje 4.1: Addition of Django REST framework, Swagger, Dark mode and updates to Django and Bootstrap
This commit is contained in:
@ -9,24 +9,23 @@ from django.utils.timezone import get_default_timezone
|
||||
from queues.models import PlaylistSong
|
||||
from songs.models import Song
|
||||
|
||||
_IMPORTANT_USERNAMES = ['root', 'admin', 'postmaster', 'dsprenkels', 'gmulder', 'bwesterb']
|
||||
_IMPORTANT_USERNAMES = ["root", "admin", "postmaster", "dsprenkels", "gmulder", "bwesterb"]
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Get the list of users that has not logged in for quite a while'
|
||||
help = "Get the list of users that has not logged in for quite a while"
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument(
|
||||
'--purge',
|
||||
action='store_const',
|
||||
default=False,
|
||||
const=True,
|
||||
help='interactively purge the old users')
|
||||
"--purge", action="store_const", default=False, const=True, help="interactively purge the old users"
|
||||
)
|
||||
parser.add_argument(
|
||||
'days_old',
|
||||
nargs='?',
|
||||
"days_old",
|
||||
nargs="?",
|
||||
type=float,
|
||||
default=365.25,
|
||||
help='amount of days after which a user is considered old')
|
||||
help="amount of days after which a user is considered old",
|
||||
)
|
||||
|
||||
def handle(self, purge, *args, **kwargs):
|
||||
if purge:
|
||||
@ -40,7 +39,7 @@ class Command(BaseCommand):
|
||||
self.stdout.write(self.style.NOTICE("No users to be deleted"))
|
||||
return
|
||||
|
||||
self.stdout.write("{} {} {}\n".format('username'.ljust(19), 'name'.ljust(29), 'last_login'))
|
||||
self.stdout.write("{} {} {}\n".format("username".ljust(19), "name".ljust(29), "last_login"))
|
||||
for user in users:
|
||||
self.stdout.write("{} {} {}\n".format(user.username.ljust(19), user.name.ljust(29), user.last_login))
|
||||
self.stdout.write("\n")
|
||||
@ -48,13 +47,11 @@ class Command(BaseCommand):
|
||||
confirmation = input("Type 'YES' to confirm: ")
|
||||
|
||||
for i in range(1, 3):
|
||||
if confirmation == 'YES':
|
||||
if confirmation == "YES":
|
||||
break
|
||||
confirmation = input("Please type 'YES' to confirm (or ^C to abort): ")
|
||||
else:
|
||||
self.stdout.write(
|
||||
self.style.ERROR(
|
||||
'Aborting purge operation after {} prompts'.format(i + 1)))
|
||||
self.stdout.write(self.style.ERROR("Aborting purge operation after {} prompts".format(i + 1)))
|
||||
return
|
||||
|
||||
deleted = 0
|
||||
@ -86,6 +83,8 @@ def get_old_users(days_old):
|
||||
"""Return a queryset with all users older than an amount of days"""
|
||||
User = get_user_model()
|
||||
tz = get_default_timezone()
|
||||
return User.objects.filter(is_staff=False, is_superuser=False, is_active=True).filter(
|
||||
Q(last_login__lt=datetime.now(tz) - timedelta(days_old))
|
||||
| Q(last_login=None)).order_by('username')
|
||||
return (
|
||||
User.objects.filter(is_staff=False, is_superuser=False, is_active=True)
|
||||
.filter(Q(last_login__lt=datetime.now(tz) - timedelta(days_old)) | Q(last_login=None))
|
||||
.order_by("username")
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user