diff --git a/src/accounts/admin.py b/src/accounts/admin.py index 441b02c..21667fc 100644 --- a/src/accounts/admin.py +++ b/src/accounts/admin.py @@ -10,7 +10,7 @@ class userprofile(admin.ModelAdmin): #list display list_display = ['user', 'score', 'last_submission_date', 'campus'] # search list - search_fields = ['score', 'user__username', 'campus'] + search_fields = ['score', 'user__username', 'campus__name'] @admin.register(Campus) class campus(admin.ModelAdmin): diff --git a/src/accounts/management/commands/prune_users.py b/src/accounts/management/commands/prune_users.py new file mode 100644 index 0000000..6fcdace --- /dev/null +++ b/src/accounts/management/commands/prune_users.py @@ -0,0 +1,24 @@ +from collections import defaultdict +from django.core.management.base import BaseCommand, CommandError +from accounts import models as acc_models +from django.contrib.auth import models as auth_models +from django.contrib.auth.models import timezone +from datetime import timedelta + +class Command(BaseCommand): + help = 'Remove all users who never logged in' + + def handle(self, *args, **options): + all_users = acc_models.UserProfileInfo.objects.filter(score=0).select_related() + to_remove = [] + for elem in all_users: + user = elem.user + if user.last_login is None and user.date_joined < timezone.now() - timedelta(hours=72): + to_remove.append(user) + print("You are going to remove {} users.".format(len(to_remove))) + answer = input("Continue ? [y/N] ") + + if answer.lower() in ["y","yes"]: + for elem in to_remove: + elem.delete() + print("Users have been successfully pruned.") diff --git a/src/accounts/migrations/0013_auto_20220818_1741.py b/src/accounts/migrations/0013_auto_20220818_1741.py new file mode 100644 index 0000000..b31aa86 --- /dev/null +++ b/src/accounts/migrations/0013_auto_20220818_1741.py @@ -0,0 +1,25 @@ +# Generated by Django 3.2.11 on 2022-08-18 15:41 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0012_auto_20220801_2212'), + ] + + operations = [ + migrations.AddField( + model_name='campus', + name='logo', + field=models.URLField(default='https://42.fr'), + preserve_default=False, + ), + migrations.AddField( + model_name='campus', + name='url', + field=models.URLField(default='https://42.fr', max_length=100), + preserve_default=False, + ), + ] diff --git a/src/accounts/migrations/0014_auto_20220818_1744.py b/src/accounts/migrations/0014_auto_20220818_1744.py new file mode 100644 index 0000000..6d375cb --- /dev/null +++ b/src/accounts/migrations/0014_auto_20220818_1744.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.11 on 2022-08-18 15:44 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0013_auto_20220818_1741'), + ] + + operations = [ + migrations.AlterField( + model_name='campus', + name='logo', + field=models.URLField(blank=True), + ), + migrations.AlterField( + model_name='campus', + name='url', + field=models.URLField(blank=True, max_length=100), + ), + ] diff --git a/src/accounts/models.py b/src/accounts/models.py index 0514306..21d49a0 100644 --- a/src/accounts/models.py +++ b/src/accounts/models.py @@ -28,6 +28,8 @@ class UserProfileInfo(models.Model): class Campus(models.Model): id = models.IntegerField(primary_key=True, unique=True) name = models.CharField(max_length=50) + url = models.URLField(max_length=100,blank=True) + logo = models.URLField(max_length=200,blank=True) def __str__(self): return self.name class Meta: diff --git a/src/accounts/templates/accounts/edit.html b/src/accounts/templates/accounts/edit.html index 2af6d04..4b2a18a 100644 --- a/src/accounts/templates/accounts/edit.html +++ b/src/accounts/templates/accounts/edit.html @@ -92,6 +92,13 @@ {% endif %}