Par défault on a 20ans tout pile
This commit is contained in:
parent
981ace031e
commit
f5c2fed71f
2 changed files with 26 additions and 19 deletions
|
@ -121,7 +121,7 @@
|
|||
const elem = document.querySelector('input[name="birth_date"]');
|
||||
const datepicker = new Datepicker(elem, {
|
||||
format: "yyyy-mm-dd",
|
||||
defaultViewDate: "{% now 'Y-m-d' %}",
|
||||
defaultViewDate: "{{ default_birth_date }}",
|
||||
});
|
||||
|
||||
</script>
|
||||
|
|
|
@ -1,28 +1,29 @@
|
|||
from django.shortcuts import render
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from datetime import date
|
||||
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from fiches.models import Profile, Phone, Social, Mail, Address
|
||||
from fiches.forms import (
|
||||
ProfileForm,
|
||||
SearchForm,
|
||||
PhoneFormSet,
|
||||
SocialFormSet,
|
||||
MailFormSet,
|
||||
AddressFormSet,
|
||||
)
|
||||
from django.core.mail import send_mail
|
||||
from django.db.models import Q
|
||||
from django.forms import formset_factory
|
||||
from django.forms.models import model_to_dict
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.template.loader import render_to_string
|
||||
from django.urls import reverse
|
||||
from django.db.models import Q
|
||||
from django.utils import timezone
|
||||
from django.utils.decorators import method_decorator
|
||||
from datetime import timedelta
|
||||
from django.core.mail import send_mail
|
||||
from django.template.loader import render_to_string
|
||||
from django.views.generic.detail import DetailView
|
||||
from django.views.generic.list import ListView
|
||||
from django.views.generic.edit import FormView, UpdateView
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.views.generic.list import ListView
|
||||
|
||||
from fiches.forms import (
|
||||
AddressFormSet,
|
||||
MailFormSet,
|
||||
PhoneFormSet,
|
||||
ProfileForm,
|
||||
SearchForm,
|
||||
SocialFormSet,
|
||||
)
|
||||
from fiches.models import Address, Mail, Phone, Profile, Social
|
||||
|
||||
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
|
@ -109,6 +110,12 @@ class EditView(UpdateView):
|
|||
)
|
||||
)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
today = date.today()
|
||||
context["default_birth_date"] = today.replace(year=(today.year - 20)).isoformat()
|
||||
return context
|
||||
|
||||
def get_object(self):
|
||||
return self.request.user.profile
|
||||
|
||||
|
@ -116,7 +123,7 @@ class EditView(UpdateView):
|
|||
return reverse("fiche", args=(self.get_object().user,))
|
||||
|
||||
|
||||
@method_decorator(login_required, name="post")
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
class HomeView(FormView):
|
||||
model = Profile
|
||||
template_name = "fiches/home.html"
|
||||
|
|
Loading…
Add table
Reference in a new issue