diff --git a/src/agenda_culturel/forms.py b/src/agenda_culturel/forms.py index 4570aaf..f787150 100644 --- a/src/agenda_culturel/forms.py +++ b/src/agenda_culturel/forms.py @@ -788,9 +788,13 @@ class MessageForm(ModelForm): class Meta: model = Message fields = ["subject", "name", "email", "message", "related_event"] - widgets = {"related_event": HiddenInput()} + widgets = {"related_event": HiddenInput(), "user": HiddenInput() } def __init__(self, *args, **kwargs): self.event = kwargs.pop("event", False) + self.internal = kwargs.pop("internal", False) super().__init__(*args, **kwargs) self.fields['related_event'].required = False + if self.internal: + self.fields.pop("name") + self.fields.pop("email") diff --git a/src/agenda_culturel/migrations/0126_message_user.py b/src/agenda_culturel/migrations/0126_message_user.py new file mode 100644 index 0000000..42caa87 --- /dev/null +++ b/src/agenda_culturel/migrations/0126_message_user.py @@ -0,0 +1,21 @@ +# Generated by Django 4.2.9 on 2024-12-11 11:56 + +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), + ('agenda_culturel', '0125_rename_contactmessage_message_alter_message_options'), + ] + + operations = [ + migrations.AddField( + model_name='message', + name='user', + field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.SET_DEFAULT, to=settings.AUTH_USER_MODEL, verbose_name='Author of the message'), + ), + ] diff --git a/src/agenda_culturel/models.py b/src/agenda_culturel/models.py index b404527..65eea51 100644 --- a/src/agenda_culturel/models.py +++ b/src/agenda_culturel/models.py @@ -1761,6 +1761,14 @@ class Message(models.Model): on_delete=models.SET_DEFAULT, ) + user = models.ForeignKey( + User, + verbose_name=_("Author of the message"), + null=True, + default=None, + on_delete=models.SET_DEFAULT, + ) + name = models.CharField( verbose_name=_("Name"), help_text=_("Your name"), diff --git a/src/agenda_culturel/templates/agenda_culturel/message_moderation_form.html b/src/agenda_culturel/templates/agenda_culturel/message_moderation_form.html index 6e2d656..9ed886a 100644 --- a/src/agenda_culturel/templates/agenda_culturel/message_moderation_form.html +++ b/src/agenda_culturel/templates/agenda_culturel/message_moderation_form.html @@ -30,7 +30,7 @@