8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 19:33:11 +00:00

Datepicker au bon format

This commit is contained in:
root 2018-08-28 19:03:51 +02:00
parent 0ea50dcebe
commit 52efe5ff2d
10 changed files with 136 additions and 33 deletions

View file

@ -46,7 +46,7 @@ from re2o.utils import remove_user_room, get_input_formats_help_text
from re2o.mixins import FormRevMixin from re2o.mixins import FormRevMixin
from re2o.field_permissions import FieldPermissionFormMixin from re2o.field_permissions import FieldPermissionFormMixin
from .widgets import DateTimePicker from .widgets import DateTimePicker, DatePicker
from .models import ( from .models import (
User, User,
@ -316,6 +316,7 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
self.fields['room'].label = _("Room") self.fields['room'].label = _("Room")
self.fields['room'].empty_label = _("No room") self.fields['room'].empty_label = _("No room")
self.fields['school'].empty_label = _("Select a school") self.fields['school'].empty_label = _("Select a school")
self.fields['birthday'].label = _("Your birthday")
def clean_email(self): def clean_email(self):
if not OptionalUser.objects.first().local_email_domain in self.cleaned_data.get('email'): if not OptionalUser.objects.first().local_email_domain in self.cleaned_data.get('email'):
@ -334,12 +335,14 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
'email', 'email',
'school', 'school',
'comment', 'comment',
'birthday',
'disclaimer', 'disclaimer',
'room', 'room',
'shell', 'shell',
'telephone', 'telephone',
'gpg_fingerprint' 'gpg_fingerprint'
] ]
widgets = {'birthday':DatePicker}
def clean_telephone(self): def clean_telephone(self):

View file

@ -1,25 +0,0 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-08-26 12:40
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0077_auto_20180824_1750'),
]
operations = [
migrations.AddField(
model_name='user',
name='disclaimer',
field=models.FileField(blank=True, upload_to='disclaimers'),
),
migrations.AlterField(
model_name='user',
name='state',
field=models.IntegerField(choices=[(0, 'STATE_ACTIVE'), (1, 'STATE_DISABLED'), (2, 'STATE_ARCHIVE')], default=0),
),
]

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-08-28 13:56
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0077_user_disclaimer'),
]
operations = [
migrations.AddField(
model_name='user',
name='date',
field=models.DateField(default=None, verbose_name='Date'),
),
]

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-08-28 13:59
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('users', '0078_user_date'),
]
operations = [
migrations.RenameField(
model_name='user',
old_name='date',
new_name='birthday',
),
]

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-08-28 15:29
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0079_auto_20180828_0859'),
]
operations = [
migrations.AlterField(
model_name='user',
name='birthday',
field=models.DateTimeField(default=None, verbose_name='Date'),
),
]

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-08-28 15:31
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0080_auto_20180828_1029'),
]
operations = [
migrations.AlterField(
model_name='user',
name='birthday',
field=models.DateField(default=None, verbose_name='Date'),
),
]

View file

@ -87,6 +87,9 @@ from machines.models import Domain, Interface, Machine, regen
from preferences.models import GeneralOption, AssoOption, OptionalUser from preferences.models import GeneralOption, AssoOption, OptionalUser
from preferences.models import OptionalMachine, MailMessageOption from preferences.models import OptionalMachine, MailMessageOption
from datetime import date
# Utilitaires généraux # Utilitaires généraux
@ -238,6 +241,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
default=get_fresh_user_uid, default=get_fresh_user_uid,
unique=True unique=True
) )
birthday = models.DateField(_("Date"), default=None)
disclaimer = models.FileField(upload_to='disclaimers', blank=True) disclaimer = models.FileField(upload_to='disclaimers', blank=True)
rezo_rez_uid = models.PositiveIntegerField( rezo_rez_uid = models.PositiveIntegerField(
unique=True, unique=True,

View file

@ -7,10 +7,14 @@
<input {{attrs}} name="{{name}}" type="text" class="form-control" placeholder="Date"/> <input {{attrs}} name="{{name}}" type="text" class="form-control" placeholder="Date"/>
<script> <script>
$(document).ready(function(){ $(document).ready(function(){
{% if time %}
$("#{{id}}").datetimepicker({ $("#{{id}}").datetimepicker({
{% else %}
$("#{{id}}").datepicker({
{% endif %}
closeText: "{{closeText}}", closeText: "{{closeText}}",
currentText: "{{currentText}}", currentText: "{{currentText}}",
dateFormat:'yy-mm-dd', dateFormat:'dd-mm-yy',
dayNames: {{dayNames}}, dayNames: {{dayNames}},
dayNamesMin: {{dayNamesMin}}, dayNamesMin: {{dayNamesMin}},
dayNamesShort: {{dayNamesShort}}, dayNamesShort: {{dayNamesShort}},
@ -26,3 +30,4 @@ $(document).ready(function(){
}) })
}); });
</script> </script>

View file

@ -38,6 +38,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css" type="text/css"> <link rel="stylesheet" href="//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css" type="text/css">
<script type='text/javascript'> <script type='text/javascript'>
$(function() {
$( ".datepicker" ).datepicker({
changeMonth: true,
changeYear: true,
yearRange: "1900:2012",
});
});
function submitBday() { function submitBday() {
var field = document.getElementById("file"); var field = document.getElementById("file");
var Bdate = document.getElementById('bday').value; var Bdate = document.getElementById('bday').value;
@ -100,8 +107,9 @@ function submitBday() {
{% render_field userform.telephone class="form-control" requiered=True %} {% render_field userform.telephone class="form-control" requiered=True %}
</div> </div>
<div class="form-group col-md-4"> <div class="form-group col-md-4">
<label>Date de naissance</label> {{ userform.birthday.label_tag}}
<input class="form-control" id="bday" name="bday" date-date-format="dd-mm-yy" requiered=True placeholder="Date de naissance" type="date" onchange="submitBday()"> {% render_field userform.birthday class="form-control" requiered=True %}
{# <input class="form-control" id="bday" name="bday" date-date-format="dd-mm-yy" requiered=True placeholder="Date de naissance" type="date" onchange="submitBday()"> #}
</div> </div>
</div> </div>
@ -126,7 +134,7 @@ function submitBday() {
var div = document.getElementById("div_disclaimer"); var div = document.getElementById("div_disclaimer");
var input = document.getElementById("{{userform.disclaimer.auto_id}}"); var input = document.getElementById("{{userform.disclaimer.auto_id}}");
var Bdate = document.getElementById('bday').value; var Bdate = document.getElementById('{{userform.birthday.auto_id').value;
var Bday = +new Date(Bdate); var Bday = +new Date(Bdate);
var age = ((Date.now() - Bday) / (31557600000)); var age = ((Date.now() - Bday) / (31557600000));

View file

@ -25,10 +25,12 @@ def list2str(str_iterable):
class DateTimePicker(Input): class DateTimePicker(Input):
is_localized = False is_localized = False
def render(self, name, value, attrs=None): def render(self, name, value, attrs=None):
super().render(name, value, attrs) super().render(name, value, attrs)
flat_attrs = flatatt(attrs) flat_attrs = flatatt(attrs)
context = Context({ context = Context({
'time': True,
'name': name, 'name': name,
'attrs': flat_attrs, 'attrs': flat_attrs,
'id': attrs['id'], 'id': attrs['id'],
@ -48,3 +50,29 @@ class DateTimePicker(Input):
template = get_template('users/datetimepicker.html') template = get_template('users/datetimepicker.html')
return template.render(context) return template.render(context)
class DatePicker(Input):
is_localized = False
def render(self, name, value, attrs=None):
super().render(name, value, attrs)
flat_attrs = flatatt(attrs)
context = Context({
'time': False,
'name': name,
'attrs': flat_attrs,
'id': attrs['id'],
'closeText': _("Close"),
'currentText': _("Today"),
'dayNames': mark_safe(list2str((str(item[1]) for item in WEEKDAYS.items()))),
'dayNamesMin': mark_safe(list2str((str(item[1]) for item in WEEKDAYS_ABBR.items()))),
'dayNamesShort': mark_safe(list2str((str(item[1]) for item in WEEKDAYS_ABBR.items()))),
'firstDay': mark_safe('"' + str(WEEKDAYS[settings.FIRST_DAY_OF_WEEK]) + '"'),
'isRTL': str(get_language_bidi()).lower(),
'monthNames': mark_safe(list2str((str(item[1]) for item in MONTHS.items()))),
'monthNamesShort': mark_safe(list2str((str(item[1]) for item in MONTHS_3.items()))),
'nextText': mark_safe('"' + str(_('Next')) + '"'),
'prevText': mark_safe('"' + str(_('Previous')) + '"'),
'weekHeader': mark_safe('"' + str(_('Wk')) + '"' ),
})
template = get_template('users/datetimepicker.html')
return template.render(context)