diff --git a/biscuit/core/migrations/0007_unlink_school_schoolterm.py b/biscuit/core/migrations/0007_unlink_school_schoolterm.py new file mode 100644 index 0000000000000000000000000000000000000000..4e26febd83153a971022c950f77929b91efa462b --- /dev/null +++ b/biscuit/core/migrations/0007_unlink_school_schoolterm.py @@ -0,0 +1,31 @@ +# Generated by Django 2.2.8 on 2019-12-11 23:27 + +from django.db import migrations, models + + +def mark_current_term(apps, schema_editor): + db_alias = schema_editor.connection.alias + + SchoolTerm = apps.get_model('core', 'SchoolTerm') # noqa + + if not SchoolTerm.objects.filter(current=True).exists(): + SchoolTerm.objects.using(db_alias).latest('date_start').update(current=True) + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0006_create_superuser'), + ] + + operations = [ + migrations.RemoveField( + model_name='school', + name='current_term', + ), + migrations.AddField( + model_name='schoolterm', + name='current', + field=models.NullBooleanField(default=None, unique=True), + ), + ] diff --git a/biscuit/core/models.py b/biscuit/core/models.py index ffd0189e1a901c1fa7349b8cf164b9da8f00b49d..ae3f5950a570f17b8e8cec7ad96be167bca2d79a 100644 --- a/biscuit/core/models.py +++ b/biscuit/core/models.py @@ -38,7 +38,9 @@ class School(models.Model): logo = ImageCropField(verbose_name=_('School logo'), blank=True, null=True) logo_cropping = ImageRatioField('logo', '600x600', size_warning=True) - current_term = models.ForeignKey('SchoolTerm', models.CASCADE, related_name='+') + @property + def current_term(self): + return SchoolTerm.objects.get(current=True) class Meta: ordering = ['name', 'name_official'] @@ -57,6 +59,13 @@ class SchoolTerm(models.Model): date_end = models.DateField(verbose_name=_( 'Effective end date of term'), null=True) + current = models.NullBooleanField(default=None, unique=True) + + def save(self, *args, **kwargs): + if self.current is False: + self.current = None + super().save(*args, **kwargs) + class Person(models.Model, ExtensibleModel): """ A model describing any person related to a school, including, but not diff --git a/biscuit/core/tests/browser/test_selenium.py b/biscuit/core/tests/browser/test_selenium.py index 918ec79c2d3175f5c9104d2db4d845e131947cea..fcdde21653e644fc90461e5e52f4a3a506ffd7b1 100644 --- a/biscuit/core/tests/browser/test_selenium.py +++ b/biscuit/core/tests/browser/test_selenium.py @@ -11,6 +11,8 @@ SeleniumTestCaseBase.browsers = list(filter(bool, os.environ.get('TEST_SELENIUM_ SeleniumTestCaseBase.selenium_hub = os.environ.get('TEST_SELENIUM_HUB', '') or None class SeleniumTests(SeleniumTestCase): + serialized_rollback = True + @classmethod def _screenshot(cls, filename): screenshot_path = os.environ.get('TEST_SCREENSHOT_PATH', None)