[extensions-web] cron: added script for cleanup inactive accounts



commit a8aab4b7ab5fb34d9a26ae10b320d62c985fc2ab
Author: Yuri Konotopov <ykonotopov gnome org>
Date:   Sun Nov 24 00:19:56 2019 +0400

    cron: added script for cleanup inactive accounts
    
    Closes: https://gitlab.gnome.org/Infrastructure/extensions-web/issues/91

 bin/sweettooth-clean-users | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
---
diff --git a/bin/sweettooth-clean-users b/bin/sweettooth-clean-users
new file mode 100755
index 0000000..adeb0c0
--- /dev/null
+++ b/bin/sweettooth-clean-users
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+
+import datetime
+
+import os
+import sys
+import django
+
+_path = os.path.dirname(__file__)
+
+os.environ['DJANGO_SETTINGS_MODULE'] = 'sweettooth.settings'
+sys.path.extend([os.path.join(_path, '..'),
+                 os.path.join(_path, '..', 'sweettooth')])
+
+django.setup()
+
+from django.db.models import Count
+from django.contrib.auth.models import User
+
+User.objects \
+    .filter(is_active=False) \
+    .filter(date_joined__lte=datetime.date.today() - datetime.timedelta(days = 5)) \
+    .annotate(extensions_count=Count('extension')).filter(extensions_count=0) \
+    .delete()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]