1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-11-26 18:37:12 +00:00

Add __str__ to models, remove null=True in CharField and TextField

This commit is contained in:
Yohann D'ANELLO 2020-09-07 01:06:22 +02:00
parent 4a9c37905c
commit 53c4e38771
14 changed files with 168 additions and 15 deletions

View File

@ -188,6 +188,12 @@ class Entry(models.Model):
verbose_name = _("entry") verbose_name = _("entry")
verbose_name_plural = _("entries") 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): def save(self, *args, **kwargs):
qs = Entry.objects.filter(~Q(pk=self.pk), activity=self.activity, note=self.note, guest=self.guest) qs = Entry.objects.filter(~Q(pk=self.pk), activity=self.activity, note=self.note, guest=self.guest)

View File

@ -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;"
),
]

View File

@ -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'),
),
]

View File

@ -44,12 +44,14 @@ class Changelog(models.Model):
) )
previous = models.TextField( previous = models.TextField(
null=True, blank=True,
default="",
verbose_name=_('previous data'), verbose_name=_('previous data'),
) )
data = models.TextField( data = models.TextField(
null=True, blank=True,
default="",
verbose_name=_('new data'), verbose_name=_('new data'),
) )
@ -80,3 +82,7 @@ class Changelog(models.Model):
class Meta: class Meta:
verbose_name = _("changelog") verbose_name = _("changelog")
verbose_name_plural = _("changelogs") 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))

View File

@ -99,7 +99,7 @@ def save_object(sender, instance, **kwargs):
model = instance.__class__ model = instance.__class__
fields = changed_fields 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") instance_json = JSONRenderer().render(CustomSerializer(instance).data).decode("UTF-8")
Changelog.objects.create(user=user, Changelog.objects.create(user=user,
@ -149,6 +149,6 @@ def delete_object(sender, instance, **kwargs):
model=ContentType.objects.get_for_model(instance), model=ContentType.objects.get_for_model(instance),
instance_pk=instance.pk, instance_pk=instance.pk,
previous=instance_json, previous=instance_json,
data=None, data="",
action="delete" action="delete"
).save() ).save()

View File

@ -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;",
),
]

View File

@ -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'),
),
]

View File

@ -46,7 +46,7 @@ class Profile(models.Model):
help_text=_('e.g. "1A0", "9A♥", "SAPHIRE"'), help_text=_('e.g. "1A0", "9A♥", "SAPHIRE"'),
max_length=255, max_length=255,
blank=True, blank=True,
null=True, default="",
) )
department = models.CharField( department = models.CharField(
@ -83,7 +83,7 @@ class Profile(models.Model):
verbose_name=_('address'), verbose_name=_('address'),
max_length=255, max_length=255,
blank=True, blank=True,
null=True, default="",
) )
paid = models.BooleanField( paid = models.BooleanField(
@ -94,11 +94,10 @@ class Profile(models.Model):
ml_events_registration = models.CharField( ml_events_registration = models.CharField(
blank=True, blank=True,
null=True, default='',
default=None,
max_length=2, max_length=2,
choices=[ choices=[
(None, _("No")), ('', _("No")),
('fr', _("Yes (receive them in french)")), ('fr', _("Yes (receive them in french)")),
('en', _("Yes (receive them in english)")), ('en', _("Yes (receive them in english)")),
], ],

View File

@ -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;"
),
]

View File

@ -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'),
),
]

View File

@ -70,8 +70,8 @@ class Note(PolymorphicModel):
"It can be reactivated at any time.")), "It can be reactivated at any time.")),
('forced', _("The note is blocked by the the BDE and can't be manually reactivated.")), ('forced', _("The note is blocked by the the BDE and can't be manually reactivated.")),
], ],
null=True, blank=True,
default=None, default="",
) )
class Meta: class Meta:

View File

@ -90,6 +90,9 @@ class TransactionTemplate(models.Model):
def get_absolute_url(self): def get_absolute_url(self):
return reverse('note:template_update', args=(self.pk,)) return reverse('note:template_update', args=(self.pk,))
def __str__(self):
return self.name
class Transaction(PolymorphicModel): class Transaction(PolymorphicModel):
""" """
@ -150,8 +153,7 @@ class Transaction(PolymorphicModel):
invalidity_reason = models.CharField( invalidity_reason = models.CharField(
verbose_name=_('invalidity reason'), verbose_name=_('invalidity reason'),
max_length=255, max_length=255,
default=None, default='',
null=True,
blank=True, 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 # When a transaction is declared valid, we ensure that the invalidity reason is null, if it was
# previously invalid # previously invalid
self.invalidity_reason = None self.invalidity_reason = ""
if source_balance > 9223372036854775807 or source_balance < -9223372036854775808\ if source_balance > 9223372036854775807 or source_balance < -9223372036854775808\
or dest_balance > 9223372036854775807 or dest_balance < -9223372036854775808: or dest_balance > 9223372036854775807 or dest_balance < -9223372036854775808:

@ -1 +1 @@
Subproject commit 4f5a794798a48cbbf10b42f0a519743fcbb96c33 Subproject commit bac22dcbac9f3ddb981a5e63629a77ca2cb8f8ff

View File

@ -109,6 +109,9 @@ class Invoice(models.Model):
verbose_name = _("invoice") verbose_name = _("invoice")
verbose_name_plural = _("invoices") verbose_name_plural = _("invoices")
def __str__(self):
return _("Invoice #{id}").format(id=self.id)
class Product(models.Model): class Product(models.Model):
""" """
@ -151,6 +154,9 @@ class Product(models.Model):
verbose_name = _("product") verbose_name = _("product")
verbose_name_plural = _("products") verbose_name_plural = _("products")
def __str__(self):
return f"{self.designation} ({self.invoice})"
class RemittanceType(models.Model): class RemittanceType(models.Model):
""" """
@ -256,6 +262,9 @@ class SpecialTransactionProxy(models.Model):
verbose_name = _("special transaction proxy") verbose_name = _("special transaction proxy")
verbose_name_plural = _("special transaction proxies") verbose_name_plural = _("special transaction proxies")
def __str__(self):
return str(self.transaction)
class SogeCredit(models.Model): class SogeCredit(models.Model):
""" """
@ -354,3 +363,6 @@ class SogeCredit(models.Model):
class Meta: class Meta:
verbose_name = _("Credit from the Société générale") verbose_name = _("Credit from the Société générale")
verbose_name_plural = _("Credits 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))