diff --git a/src/accounts/admin.py b/src/accounts/admin.py index e1fbd9b..03dfdfb 100644 --- a/src/accounts/admin.py +++ b/src/accounts/admin.py @@ -1,5 +1,6 @@ from .models import UserProfileInfo from django.contrib import admin +from .models import Campus #admin.site.register(UserProfileInfo) # Register your models here. @@ -7,6 +8,10 @@ from django.contrib import admin @admin.register(UserProfileInfo) class userprofile(admin.ModelAdmin): #list display - list_display = ['user', 'score', 'last_submission_date'] + list_display = ['user', 'score', 'last_submission_date', 'intra42_campus'] # search list - search_fields = ['score', 'user__username'] \ No newline at end of file + search_fields = ['score', 'user__username', 'intra42_campus'] + +@admin.register(Campus) +class campus(admin.ModelAdmin): + list_display = ['name'] \ No newline at end of file diff --git a/src/accounts/migrations/0008_auto_20220329_1034.py b/src/accounts/migrations/0008_auto_20220329_1034.py new file mode 100644 index 0000000..0578d14 --- /dev/null +++ b/src/accounts/migrations/0008_auto_20220329_1034.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.11 on 2022-03-29 08:34 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0007_auto_20220123_1704'), + ] + + operations = [ + migrations.AddField( + model_name='userprofileinfo', + name='intra42_campus', + field=models.CharField(blank=True, max_length=50, null=True), + ), + migrations.AddField( + model_name='userprofileinfo', + name='intra42_id', + field=models.CharField(blank=True, max_length=20, null=True, unique=True), + ), + ] diff --git a/src/accounts/migrations/0009_auto_20220329_1339.py b/src/accounts/migrations/0009_auto_20220329_1339.py new file mode 100644 index 0000000..e23fec4 --- /dev/null +++ b/src/accounts/migrations/0009_auto_20220329_1339.py @@ -0,0 +1,22 @@ +# Generated by Django 3.2.11 on 2022-03-29 11:39 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0008_auto_20220329_1034'), + ] + + operations = [ + migrations.AlterModelOptions( + name='userprofileinfo', + options={'ordering': ['-score', 'last_submission_date', 'user__username', 'intra42_campus'], 'permissions': (('view_info', 'View user info'),), 'verbose_name': 'profile', 'verbose_name_plural': 'profiles'}, + ), + migrations.AddField( + model_name='userprofileinfo', + name='intra42_campus_id', + field=models.CharField(blank=True, max_length=10, null=True), + ), + ] diff --git a/src/accounts/migrations/0010_auto_20220517_1452.py b/src/accounts/migrations/0010_auto_20220517_1452.py new file mode 100644 index 0000000..88f4fdf --- /dev/null +++ b/src/accounts/migrations/0010_auto_20220517_1452.py @@ -0,0 +1,31 @@ +# Generated by Django 3.2.11 on 2022-05-17 12:52 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0009_auto_20220329_1339'), + ] + + operations = [ + migrations.CreateModel( + name='Campus', + fields=[ + ('id', models.IntegerField(primary_key=True, serialize=False, unique=True)), + ('name', models.CharField(max_length=50)), + ], + options={ + 'verbose_name': 'campus', + 'verbose_name_plural': 'campuses', + 'permissions': (('view_info', 'View user info'),), + }, + ), + migrations.AddField( + model_name='userprofileinfo', + name='campus', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='accounts.campus'), + ), + ] diff --git a/src/accounts/migrations/0011_migration_campus.py b/src/accounts/migrations/0011_migration_campus.py new file mode 100644 index 0000000..c84b7de --- /dev/null +++ b/src/accounts/migrations/0011_migration_campus.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.11 on 2022-05-17 12:54 + +from django.db import migrations +from accounts.models import UserProfileInfo +from accounts.models import Campus + +def migrate_campus(apps, schema_editor): + UserProfileInfo = apps.get_model('accounts', 'UserProfileInfo') + Campus = apps.get_model('accounts', 'Campus') + for user in UserProfileInfo.objects.all(): + if user.intra42_campus_id: + user.campus, created = Campus.objects.get_or_create(id=user.intra42_campus_id, name=user.intra42_campus) + user.save() + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0010_auto_20220517_1452'), + ] + + operations = [ + migrations.RunPython(migrate_campus), + ] diff --git a/src/accounts/models.py b/src/accounts/models.py index b82988e..7bf0c2a 100644 --- a/src/accounts/models.py +++ b/src/accounts/models.py @@ -12,15 +12,29 @@ class UserProfileInfo(models.Model): last_submission_date = models.DateTimeField('Last Submission Date', default=timezone.now) token = models.CharField(max_length=200, blank=True) discord_id = models.CharField(max_length=20, null=True, blank=True, unique=True) + intra42_id = models.CharField(max_length=20, null=True, blank=True, unique=True) + campus = models.ForeignKey('Campus', on_delete=models.DO_NOTHING, null=True, blank=True) + intra42_campus = models.CharField(max_length=50, null=True, blank=True) + intra42_campus_id = models.CharField(max_length=10, null=True, blank=True) member = models.BooleanField(default=False) member_since = models.DateTimeField('Member since', default=timezone.now) member_until = models.DateTimeField('Member until', default=timezone.now) def __str__(self): return self.user.username class Meta: - ordering = ['-score', 'last_submission_date', 'user__username'] + ordering = ['-score', 'last_submission_date', 'user__username', 'intra42_campus'] verbose_name = 'profile' verbose_name_plural = 'profiles' permissions = (("view_info", "View user info"),) +class Campus(models.Model): + id = models.IntegerField(primary_key=True, unique=True) + name = models.CharField(max_length=50) + def __str__(self): + return self.name + class Meta: + verbose_name = 'campus' + verbose_name_plural = 'campuses' + permissions = (("view_info", "View user info"),) + # Create your models here. diff --git a/src/accounts/templates/accounts/edit.html b/src/accounts/templates/accounts/edit.html index 0e1c474..2af6d04 100644 --- a/src/accounts/templates/accounts/edit.html +++ b/src/accounts/templates/accounts/edit.html @@ -60,6 +60,21 @@ {% endif %} +
{% trans "It seems that this user has not created any challenge yet..." %}
+ {% endif %} +