handles mail and adresses
This commit is contained in:
parent
c898a084fc
commit
5cb6d2dd5e
6 changed files with 94 additions and 31 deletions
|
@ -26,29 +26,10 @@ class SearchForm(forms.Form):
|
||||||
raise forms.ValidationError(("Tous les champs sont vides"), code="invalid")
|
raise forms.ValidationError(("Tous les champs sont vides"), code="invalid")
|
||||||
|
|
||||||
|
|
||||||
class PhoneForm(forms.ModelForm):
|
|
||||||
class Meta:
|
|
||||||
model = Phone
|
|
||||||
exclude = []
|
|
||||||
PhoneFormSet = inlineformset_factory(Profile, Phone, exclude=[])
|
PhoneFormSet = inlineformset_factory(Profile, Phone, exclude=[])
|
||||||
|
|
||||||
|
|
||||||
class SocialForm(forms.ModelForm):
|
|
||||||
class Meta:
|
|
||||||
model = Social
|
|
||||||
exclude = []
|
|
||||||
SocialFormSet = inlineformset_factory(Profile, Social, exclude=[])
|
SocialFormSet = inlineformset_factory(Profile, Social, exclude=[])
|
||||||
|
|
||||||
|
|
||||||
class MailForm(forms.ModelForm):
|
|
||||||
class Meta:
|
|
||||||
model = Mail
|
|
||||||
exclude = []
|
|
||||||
MailFormSet = inlineformset_factory(Profile, Mail, exclude=[])
|
MailFormSet = inlineformset_factory(Profile, Mail, exclude=[])
|
||||||
|
|
||||||
|
|
||||||
class AddressForm(forms.ModelForm):
|
|
||||||
class Meta:
|
|
||||||
model = Address
|
|
||||||
exclude = []
|
|
||||||
AddressFormSet = inlineformset_factory(Profile, Address, exclude=[])
|
AddressFormSet = inlineformset_factory(Profile, Address, exclude=[])
|
||||||
|
|
24
fiches/migrations/0006_auto_20200917_1420.py
Normal file
24
fiches/migrations/0006_auto_20200917_1420.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
# Generated by Django 2.2.16 on 2020-09-17 14:20
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('fiches', '0005_profile_pronoun'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='phone',
|
||||||
|
name='profile',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='numeros', to='fiches.Profile', verbose_name='profil'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='social',
|
||||||
|
name='profile',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='socials', to='fiches.Profile', verbose_name='profil'),
|
||||||
|
),
|
||||||
|
]
|
24
fiches/migrations/0007_auto_20200917_1421.py
Normal file
24
fiches/migrations/0007_auto_20200917_1421.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
# Generated by Django 2.2.16 on 2020-09-17 14:21
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('fiches', '0006_auto_20200917_1420'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='phone',
|
||||||
|
name='profile',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='fiches.Profile', verbose_name='profil'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='social',
|
||||||
|
name='profile',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='fiches.Profile', verbose_name='profil'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -56,12 +56,26 @@
|
||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if profile.social_set.exists %}
|
{% if profile.social_set.exists %}
|
||||||
<p class="phone">
|
<p class="social">
|
||||||
<span class="label">{{ profile.social_set.count|pluralize:_("Réseau social,Réseaux sociaux") }}</span>
|
<span class="label">{{ profile.social_set.count|pluralize:_("Réseau social,Réseaux sociaux") }}</span>
|
||||||
<span class="separator"></span>
|
<span class="separator"></span>
|
||||||
<span class="value">{% for p in profile.social_set.all %}{{ p }}{% if not forloop.last %},<br>{% endif %}{% endfor %}</span>
|
<span class="value">{% for p in profile.social_set.all %}{{ p }}{% if not forloop.last %},<br>{% endif %}{% endfor %}</span>
|
||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if profile.mail_set.exists %}
|
||||||
|
<p class="mail">
|
||||||
|
<span class="label">{{ profile.mail_set.count|pluralize:_("Mail,Mails") }}</span>
|
||||||
|
<span class="separator"></span>
|
||||||
|
<span class="value">{% for p in profile.mail_set.all %}{{ p }}{% if not forloop.last %},<br>{% endif %}{% endfor %}</span>
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
{% if profile.address_set.exists %}
|
||||||
|
<p class="address">
|
||||||
|
<span class="label">{{ profile.address_set.count|pluralize:_("Adresse,Adresses") }}</span>
|
||||||
|
<span class="separator"></span>
|
||||||
|
<span class="value">{% for p in profile.address_set.all %}{{ p }}{% if not forloop.last %},<br>{% endif %}{% endfor %}</span>
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if profile.text_field %}
|
{% if profile.text_field %}
|
||||||
|
|
|
@ -71,6 +71,14 @@
|
||||||
<label for="id_social">{% trans "Réseaux sociaux :" %}</label>
|
<label for="id_social">{% trans "Réseaux sociaux :" %}</label>
|
||||||
{{ social_form }}
|
{{ social_form }}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-entry">
|
||||||
|
<label for="id_mail">{% trans "Mail(s):" %}</label>
|
||||||
|
{{ mail_form }}
|
||||||
|
</div>
|
||||||
|
<div class="form-entry">
|
||||||
|
<label for="id_address">{% trans "Adresse(s):" %}</label>
|
||||||
|
{{ address_form }}
|
||||||
|
</div>
|
||||||
<div class="form-entry">
|
<div class="form-entry">
|
||||||
<label for="id_text_field">{% trans "Champ libre :" %}</label>
|
<label for="id_text_field">{% trans "Champ libre :" %}</label>
|
||||||
<div id="free-text-edit-form" class="wide-form-entry">
|
<div id="free-text-edit-form" class="wide-form-entry">
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.shortcuts import get_object_or_404, redirect
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from fiches.models import Profile
|
from fiches.models import Profile, Phone, Social, Mail, Address
|
||||||
from fiches.forms import ProfileForm, SearchForm, PhoneFormSet, SocialFormSet
|
from fiches.forms import ProfileForm, SearchForm, PhoneFormSet, SocialFormSet, MailFormSet, AddressFormSet
|
||||||
from django.forms import formset_factory
|
from django.forms import formset_factory
|
||||||
from django.forms.models import model_to_dict
|
from django.forms.models import model_to_dict
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
@ -37,12 +37,16 @@ class EditView(UpdateView):
|
||||||
self.object = self.get_object()
|
self.object = self.get_object()
|
||||||
form_class = self.get_form_class()
|
form_class = self.get_form_class()
|
||||||
form = self.get_form(form_class)
|
form = self.get_form(form_class)
|
||||||
phone_form = PhoneFormSet()
|
phone_form = PhoneFormSet(queryset=Phone.objects.filter(profile=self.object))
|
||||||
social_form = SocialFormSet()
|
social_form = SocialFormSet()
|
||||||
|
mail_form = MailFormSet()
|
||||||
|
address_form = AddressFormSet()
|
||||||
return self.render_to_response(
|
return self.render_to_response(
|
||||||
self.get_context_data(form=form,
|
self.get_context_data(form=form,
|
||||||
phone_form=phone_form,
|
phone_form=phone_form,
|
||||||
social_form=social_form))
|
social_form=social_form,
|
||||||
|
mail_form=mail_form,
|
||||||
|
address_form=address_form))
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
self.object = self.get_object()
|
self.object = self.get_object()
|
||||||
|
@ -50,18 +54,24 @@ class EditView(UpdateView):
|
||||||
form = self.get_form(form_class)
|
form = self.get_form(form_class)
|
||||||
phone_form = PhoneFormSet(self.request.POST)
|
phone_form = PhoneFormSet(self.request.POST)
|
||||||
social_form = SocialFormSet(self.request.POST)
|
social_form = SocialFormSet(self.request.POST)
|
||||||
if (form.is_valid() and phone_form.is_valid() and social_form.is_valid()):
|
mail_form = MailFormSet(self.request.POST)
|
||||||
return self.form_valid(form, phone_form, social_form)
|
address_form = AddressFormSet(self.request.POST)
|
||||||
|
if (form.is_valid() and phone_form.is_valid() and social_form.is_valid()
|
||||||
|
and mail_form.is_valid() and address_form.is_valid()):
|
||||||
|
return self.form_valid(form, phone_form, social_form, mail_form, address_form)
|
||||||
else:
|
else:
|
||||||
return self.form_invalid(form, phone_form, social_form)
|
return self.form_invalid(form, phone_form, social_form, mail_form, address_form)
|
||||||
self.form_save(phone_form)
|
|
||||||
|
|
||||||
def form_valid(self, form, phone_form, social_form):
|
def form_valid(self, form, phone_form, social_form, mail_form, address_form):
|
||||||
self.object = form.save()
|
self.object = form.save()
|
||||||
phone_form.instance = self.object
|
phone_form.instance = self.object
|
||||||
phone_form.save()
|
phone_form.save()
|
||||||
social_form.instance = self.object
|
social_form.instance = self.object
|
||||||
social_form.save()
|
social_form.save()
|
||||||
|
mail_form.instance = self.object
|
||||||
|
mail_form.save()
|
||||||
|
address_form.instance = self.object
|
||||||
|
address_form.save()
|
||||||
send_mail(
|
send_mail(
|
||||||
"Fiche annuaire modifée",
|
"Fiche annuaire modifée",
|
||||||
render_to_string("fiches/mail/mail_modif.txt", {"profile": self.get_object()}),
|
render_to_string("fiches/mail/mail_modif.txt", {"profile": self.get_object()}),
|
||||||
|
@ -71,11 +81,13 @@ class EditView(UpdateView):
|
||||||
)
|
)
|
||||||
return HttpResponseRedirect(self.get_success_url())
|
return HttpResponseRedirect(self.get_success_url())
|
||||||
|
|
||||||
def form_invalid(self, form, phone_form, social_form):
|
def form_invalid(self, form, phone_form, social_form, mail_form, address_form):
|
||||||
return self.render_to_response(
|
return self.render_to_response(
|
||||||
self.get_context_data(form=form,
|
self.get_context_data(form=form,
|
||||||
phone_form=phone_form,
|
phone_form=phone_form,
|
||||||
social_form=social_form))
|
social_form=social_form,
|
||||||
|
mail_form=mail_form,
|
||||||
|
address_form=address_form))
|
||||||
|
|
||||||
def get_object(self):
|
def get_object(self):
|
||||||
return self.request.user.profile
|
return self.request.user.profile
|
||||||
|
|
Loading…
Reference in a new issue