OldCASAccount model and migration

This commit is contained in:
Ludovic Stephan 2020-06-12 19:37:06 +02:00
parent 4e9e2f62e8
commit 27184df690
2 changed files with 77 additions and 1 deletions

View file

@ -0,0 +1,33 @@
# Generated by Django 3.0.6 on 2020-06-12 17:26
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('authens', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='OldCASAccount',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('cas_login', models.CharField(max_length=1023, verbose_name='ancien login CAS')),
('entrance_year', models.SmallIntegerField(verbose_name='année de création du compte CAS')),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='old_cas_account', to=settings.AUTH_USER_MODEL, verbose_name='utilisateurice')),
],
options={
'verbose_name': 'Ancien compte CAS',
'verbose_name_plural': 'Anciens comptes CAS',
},
),
migrations.AddConstraint(
model_name='oldcasaccount',
constraint=models.UniqueConstraint(fields=('cas_login', 'entrance_year'), name='clipper_year_uniqueness'),
),
]

View file

@ -8,7 +8,7 @@ User = get_user_model()
class CASAccount(models.Model): class CASAccount(models.Model):
"""Information about CAS accounts. """Information about CAS accounts.
A user is given an instance of this model iff she has a CAS account. A user is given an instance of this model iff they have a CAS account.
Instances of this model should only be created by the `ENSCASBackend` authentication Instances of this model should only be created by the `ENSCASBackend` authentication
backend. backend.
@ -37,3 +37,46 @@ class CASAccount(models.Model):
"entrance_year": self.entrance_year, "entrance_year": self.entrance_year,
"user": self.user.username, "user": self.user.username,
} }
class OldCASAccount(models.Model):
"""Information about expired CAS accounts
user is given an instance of this model iff they had a CAS account that expired.
Instances of this model should not be created with a new user.
"""
user = models.OneToOneField(
User,
verbose_name=_("utilisateurice"),
on_delete=models.CASCADE,
related_name="old_cas_account",
)
cas_login = models.CharField(
verbose_name=_("ancien login CAS"), max_length=1023, blank=False
)
entrance_year = models.SmallIntegerField(
verbose_name=_("année de création du compte CAS"), blank=False, null=False
)
class Meta:
# `unique_together` to be deprecated soon : we use `constraints`
constraints = [
models.UniqueConstraint(
fields=["cas_login", "entrance_year"], name="clipper_year_uniqueness",
)
]
verbose_name = _("Ancien compte CAS")
verbose_name_plural = _("Anciens comptes CAS")
def __str__(self):
return _(
"Ancien compte CAS %(cas_login) (promo %(entrance_year)s) lié à %(user)s"
) % {
"cas_login": self.cas_login,
"entrance_year": self.entrance_year,
"user": self.user.username,
}