Les personnes connextées ont un formulaire simplifié
This commit is contained in:
parent
c1f7bfd8c4
commit
a94b9a53f2
@ -788,9 +788,13 @@ class MessageForm(ModelForm):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = Message
|
model = Message
|
||||||
fields = ["subject", "name", "email", "message", "related_event"]
|
fields = ["subject", "name", "email", "message", "related_event"]
|
||||||
widgets = {"related_event": HiddenInput()}
|
widgets = {"related_event": HiddenInput(), "user": HiddenInput() }
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.event = kwargs.pop("event", False)
|
self.event = kwargs.pop("event", False)
|
||||||
|
self.internal = kwargs.pop("internal", False)
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.fields['related_event'].required = False
|
self.fields['related_event'].required = False
|
||||||
|
if self.internal:
|
||||||
|
self.fields.pop("name")
|
||||||
|
self.fields.pop("email")
|
||||||
|
21
src/agenda_culturel/migrations/0126_message_user.py
Normal file
21
src/agenda_culturel/migrations/0126_message_user.py
Normal file
@ -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'),
|
||||||
|
),
|
||||||
|
]
|
@ -1761,6 +1761,14 @@ class Message(models.Model):
|
|||||||
on_delete=models.SET_DEFAULT,
|
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(
|
name = models.CharField(
|
||||||
verbose_name=_("Name"),
|
verbose_name=_("Name"),
|
||||||
help_text=_("Your name"),
|
help_text=_("Your name"),
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
<h1>Modération du message « {{ object.subject }} »</h1>
|
<h1>Modération du message « {{ object.subject }} »</h1>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Date : {{ object.date.date }} à {{ object.date.time }}</li>
|
<li>Date : {{ object.date.date }} à {{ object.date.time }}</li>
|
||||||
<li>Auteur : {{ object.name }} {% if object.email %}<a href="mailto:{{ object.email }}">{{ object.email }}</a>{% endif %}</li>
|
<li>Auteur : {% if object.user %}<em>{{ object.user }}</em>{% else %}{{ object.name }}{% endif %} {% if object.email %}<a href="mailto:{{ object.email }}">{{ object.email }}</a>{% endif %}</li>
|
||||||
{% if object.related_event %}<li>Événement associé : <a href="{{ object.related_event.get_absolute_url }}">{{ object.related_event.title }}</a> du {{ object.related_event.start_day }}</li>{% endif %}
|
{% if object.related_event %}<li>Événement associé : <a href="{{ object.related_event.get_absolute_url }}">{{ object.related_event.title }}</a> du {{ object.related_event.start_day }}</li>{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
</header>
|
</header>
|
||||||
|
@ -46,7 +46,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>{{ obj.date }}</td>
|
<td>{{ obj.date }}</td>
|
||||||
<td><a href="{% url 'message' obj.pk %}">{{ obj.subject }}</a></td>
|
<td><a href="{% url 'message' obj.pk %}">{{ obj.subject }}</a></td>
|
||||||
<td>{{ obj.name }}</td>
|
<td>{% if obj.user %}<em>{{ obj.user }}</em>{% else %}{{ obj.name }}{% endif %}</td>
|
||||||
<td>{% if obj.related_event %}<a href="{{ obj.related_event.get_absolute_url }}">{{ obj.related_event.pk }}</a>{% else %}/{% endif %}</td>
|
<td>{% if obj.related_event %}<a href="{{ obj.related_event.get_absolute_url }}">{{ obj.related_event.pk }}</a>{% else %}/{% endif %}</td>
|
||||||
<td>{% if obj.closed %}{% picto_from_name "check-square" "fermé" %}{% else %}{% picto_from_name "square" "ouvert" %}{% endif %}</td>
|
<td>{% if obj.closed %}{% picto_from_name "check-square" "fermé" %}{% else %}{% picto_from_name "square" "ouvert" %}{% endif %}</td>
|
||||||
<td>{% if obj.spam %}{% picto_from_name "check-square" "spam" %}{% else %}{% picto_from_name "square" "non spam" %}{% endif %}</td>
|
<td>{% if obj.spam %}{% picto_from_name "check-square" "spam" %}{% else %}{% picto_from_name "square" "non spam" %}{% endif %}</td>
|
||||||
|
@ -765,8 +765,15 @@ class MessageCreateView(SuccessMessageMixin, CreateView):
|
|||||||
def get_form_kwargs(self):
|
def get_form_kwargs(self):
|
||||||
kwargs = super().get_form_kwargs()
|
kwargs = super().get_form_kwargs()
|
||||||
kwargs["event"] = self.event
|
kwargs["event"] = self.event
|
||||||
|
if self.request.user.is_authenticated:
|
||||||
|
kwargs["internal"] = True
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
form.instance.user = self.request.user
|
||||||
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
|
||||||
def get_initial(self):
|
def get_initial(self):
|
||||||
result = super().get_initial()
|
result = super().get_initial()
|
||||||
if "pk" in self.kwargs:
|
if "pk" in self.kwargs:
|
||||||
|
Loading…
Reference in New Issue
Block a user