diff --git a/apps/activity/models.py b/apps/activity/models.py index 9d3431be..fe2cfb20 100644 --- a/apps/activity/models.py +++ b/apps/activity/models.py @@ -188,6 +188,12 @@ class Entry(models.Model): verbose_name = _("entry") verbose_name_plural = _("entries") + def __str__(self): + return _("Entry for {guest}, invited by {note} to the activity {activity}").format( + guest=str(self.guest), note=str(self.note), activity=str(self.activity)) if self.guest \ + else _("Entry for {note} to the activity {activity}").format( + guest=str(self.guest), note=str(self.note), activity=str(self.activity)) + def save(self, *args, **kwargs): qs = Entry.objects.filter(~Q(pk=self.pk), activity=self.activity, note=self.note, guest=self.guest) diff --git a/apps/logs/migrations/0002_replace_null_by_blank.py b/apps/logs/migrations/0002_replace_null_by_blank.py new file mode 100644 index 00000000..65fc4b14 --- /dev/null +++ b/apps/logs/migrations/0002_replace_null_by_blank.py @@ -0,0 +1,17 @@ +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('logs', '0001_initial'), + ] + + operations = [ + migrations.RunSQL( + "UPDATE logs_changelog SET previous = '' WHERE previous IS NULL;" + ), + migrations.RunSQL( + "UPDATE logs_changelog SET data = '' WHERE data IS NULL;" + ), + ] diff --git a/apps/logs/migrations/0003_remove_null_tag_on_charfields.py b/apps/logs/migrations/0003_remove_null_tag_on_charfields.py new file mode 100644 index 00000000..a6e3a581 --- /dev/null +++ b/apps/logs/migrations/0003_remove_null_tag_on_charfields.py @@ -0,0 +1,23 @@ +# Generated by Django 2.2.16 on 2020-09-06 19:17 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('logs', '0002_replace_null_by_blank'), + ] + + operations = [ + migrations.AlterField( + model_name='changelog', + name='data', + field=models.TextField(blank=True, default='', verbose_name='new data'), + ), + migrations.AlterField( + model_name='changelog', + name='previous', + field=models.TextField(blank=True, default='', verbose_name='previous data'), + ), + ] diff --git a/apps/logs/models.py b/apps/logs/models.py index e558ea82..0077af72 100644 --- a/apps/logs/models.py +++ b/apps/logs/models.py @@ -44,12 +44,14 @@ class Changelog(models.Model): ) previous = models.TextField( - null=True, + blank=True, + default="", verbose_name=_('previous data'), ) data = models.TextField( - null=True, + blank=True, + default="", verbose_name=_('new data'), ) @@ -80,3 +82,7 @@ class Changelog(models.Model): class Meta: verbose_name = _("changelog") verbose_name_plural = _("changelogs") + + def __str__(self): + return _("Changelog of type \"{action}\" for model {model} at {timestamp}").format( + action=self.get_action_display(), model=str(self.model), timestamp=str(self.timestamp)) diff --git a/apps/logs/signals.py b/apps/logs/signals.py index e58ba7c1..f313cc5b 100644 --- a/apps/logs/signals.py +++ b/apps/logs/signals.py @@ -99,7 +99,7 @@ def save_object(sender, instance, **kwargs): model = instance.__class__ fields = changed_fields - previous_json = JSONRenderer().render(CustomSerializer(previous).data).decode("UTF-8") if previous else None + previous_json = JSONRenderer().render(CustomSerializer(previous).data).decode("UTF-8") if previous else "" instance_json = JSONRenderer().render(CustomSerializer(instance).data).decode("UTF-8") Changelog.objects.create(user=user, @@ -149,6 +149,6 @@ def delete_object(sender, instance, **kwargs): model=ContentType.objects.get_for_model(instance), instance_pk=instance.pk, previous=instance_json, - data=None, + data="", action="delete" ).save() diff --git a/apps/member/migrations/0004_replace_null_by_blank.py b/apps/member/migrations/0004_replace_null_by_blank.py new file mode 100644 index 00000000..a53e3801 --- /dev/null +++ b/apps/member/migrations/0004_replace_null_by_blank.py @@ -0,0 +1,20 @@ +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('member', '0003_create_bde_and_kfet'), + ] + + operations = [ + migrations.RunSQL( + "UPDATE member_profile SET address = '' WHERE address IS NULL;", + ), + migrations.RunSQL( + "UPDATE member_profile SET ml_events_registration = '' WHERE ml_events_registration IS NULL;", + ), + migrations.RunSQL( + "UPDATE member_profile SET section = '' WHERE section IS NULL;", + ), + ] diff --git a/apps/member/migrations/0005_remove_null_tag_on_charfields.py b/apps/member/migrations/0005_remove_null_tag_on_charfields.py new file mode 100644 index 00000000..11b9f37b --- /dev/null +++ b/apps/member/migrations/0005_remove_null_tag_on_charfields.py @@ -0,0 +1,28 @@ +# Generated by Django 2.2.16 on 2020-09-06 19:17 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('member', '0004_replace_null_by_blank'), + ] + + operations = [ + migrations.AlterField( + model_name='profile', + name='address', + field=models.CharField(blank=True, default='', max_length=255, verbose_name='address'), + ), + migrations.AlterField( + model_name='profile', + name='ml_events_registration', + field=models.CharField(blank=True, choices=[('', 'No'), ('fr', 'Yes (receive them in french)'), ('en', 'Yes (receive them in english)')], default='', max_length=2, verbose_name='Register on the mailing list to stay informed of the events of the campus (1 mail/week)'), + ), + migrations.AlterField( + model_name='profile', + name='section', + field=models.CharField(blank=True, default='', help_text='e.g. "1A0", "9A♥", "SAPHIRE"', max_length=255, verbose_name='section'), + ), + ] diff --git a/apps/member/models.py b/apps/member/models.py index bce525af..c7467120 100644 --- a/apps/member/models.py +++ b/apps/member/models.py @@ -46,7 +46,7 @@ class Profile(models.Model): help_text=_('e.g. "1A0", "9A♥", "SAPHIRE"'), max_length=255, blank=True, - null=True, + default="", ) department = models.CharField( @@ -83,7 +83,7 @@ class Profile(models.Model): verbose_name=_('address'), max_length=255, blank=True, - null=True, + default="", ) paid = models.BooleanField( @@ -94,11 +94,10 @@ class Profile(models.Model): ml_events_registration = models.CharField( blank=True, - null=True, - default=None, + default='', max_length=2, choices=[ - (None, _("No")), + ('', _("No")), ('fr', _("Yes (receive them in french)")), ('en', _("Yes (receive them in english)")), ], diff --git a/apps/note/migrations/0003_replace_null_by_blank.py b/apps/note/migrations/0003_replace_null_by_blank.py new file mode 100644 index 00000000..21da860d --- /dev/null +++ b/apps/note/migrations/0003_replace_null_by_blank.py @@ -0,0 +1,17 @@ +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('note', '0002_create_special_notes'), + ] + + operations = [ + migrations.RunSQL( + "UPDATE note_note SET inactivity_reason = '' WHERE inactivity_reason IS NULL;" + ), + migrations.RunSQL( + "UPDATE note_transaction SET invalidity_reason = '' WHERE invalidity_reason IS NULL;" + ), + ] diff --git a/apps/note/migrations/0004_remove_null_tag_on_charfields.py b/apps/note/migrations/0004_remove_null_tag_on_charfields.py new file mode 100644 index 00000000..012fc359 --- /dev/null +++ b/apps/note/migrations/0004_remove_null_tag_on_charfields.py @@ -0,0 +1,23 @@ +# Generated by Django 2.2.16 on 2020-09-06 19:17 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('note', '0003_replace_null_by_blank'), + ] + + operations = [ + migrations.AlterField( + model_name='note', + name='inactivity_reason', + field=models.CharField(blank=True, choices=[('manual', 'The user blocked his/her note manually, eg. when he/she left the school for holidays. It can be reactivated at any time.'), ('forced', "The note is blocked by the the BDE and can't be manually reactivated.")], default='', max_length=255), + ), + migrations.AlterField( + model_name='transaction', + name='invalidity_reason', + field=models.CharField(blank=True, default='', max_length=255, verbose_name='invalidity reason'), + ), + ] diff --git a/apps/note/models/notes.py b/apps/note/models/notes.py index 877247df..9efdd1d0 100644 --- a/apps/note/models/notes.py +++ b/apps/note/models/notes.py @@ -70,8 +70,8 @@ class Note(PolymorphicModel): "It can be reactivated at any time.")), ('forced', _("The note is blocked by the the BDE and can't be manually reactivated.")), ], - null=True, - default=None, + blank=True, + default="", ) class Meta: diff --git a/apps/note/models/transactions.py b/apps/note/models/transactions.py index d10bf3a6..b89b405f 100644 --- a/apps/note/models/transactions.py +++ b/apps/note/models/transactions.py @@ -90,6 +90,9 @@ class TransactionTemplate(models.Model): def get_absolute_url(self): return reverse('note:template_update', args=(self.pk,)) + def __str__(self): + return self.name + class Transaction(PolymorphicModel): """ @@ -150,8 +153,7 @@ class Transaction(PolymorphicModel): invalidity_reason = models.CharField( verbose_name=_('invalidity reason'), max_length=255, - default=None, - null=True, + default='', blank=True, ) @@ -195,7 +197,7 @@ class Transaction(PolymorphicModel): # When a transaction is declared valid, we ensure that the invalidity reason is null, if it was # previously invalid - self.invalidity_reason = None + self.invalidity_reason = "" if source_balance > 9223372036854775807 or source_balance < -9223372036854775808\ or dest_balance > 9223372036854775807 or dest_balance < -9223372036854775808: diff --git a/apps/scripts b/apps/scripts index 4f5a7947..bac22dcb 160000 --- a/apps/scripts +++ b/apps/scripts @@ -1 +1 @@ -Subproject commit 4f5a794798a48cbbf10b42f0a519743fcbb96c33 +Subproject commit bac22dcbac9f3ddb981a5e63629a77ca2cb8f8ff diff --git a/apps/treasury/models.py b/apps/treasury/models.py index e57496ec..175829fe 100644 --- a/apps/treasury/models.py +++ b/apps/treasury/models.py @@ -109,6 +109,9 @@ class Invoice(models.Model): verbose_name = _("invoice") verbose_name_plural = _("invoices") + def __str__(self): + return _("Invoice #{id}").format(id=self.id) + class Product(models.Model): """ @@ -151,6 +154,9 @@ class Product(models.Model): verbose_name = _("product") verbose_name_plural = _("products") + def __str__(self): + return f"{self.designation} ({self.invoice})" + class RemittanceType(models.Model): """ @@ -256,6 +262,9 @@ class SpecialTransactionProxy(models.Model): verbose_name = _("special transaction proxy") verbose_name_plural = _("special transaction proxies") + def __str__(self): + return str(self.transaction) + class SogeCredit(models.Model): """ @@ -354,3 +363,6 @@ class SogeCredit(models.Model): class Meta: verbose_name = _("Credit from the Société générale") verbose_name_plural = _("Credits from the Société générale") + + def __str__(self): + return _("Soge credit for {user}").format(user=str(self.user))