mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-23 07:23:46 +00:00
Datepicker au bon format
This commit is contained in:
parent
0ea50dcebe
commit
52efe5ff2d
10 changed files with 136 additions and 33 deletions
|
@ -46,7 +46,7 @@ from re2o.utils import remove_user_room, get_input_formats_help_text
|
|||
from re2o.mixins import FormRevMixin
|
||||
from re2o.field_permissions import FieldPermissionFormMixin
|
||||
|
||||
from .widgets import DateTimePicker
|
||||
from .widgets import DateTimePicker, DatePicker
|
||||
|
||||
from .models import (
|
||||
User,
|
||||
|
@ -316,6 +316,7 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
|
|||
self.fields['room'].label = _("Room")
|
||||
self.fields['room'].empty_label = _("No room")
|
||||
self.fields['school'].empty_label = _("Select a school")
|
||||
self.fields['birthday'].label = _("Your birthday")
|
||||
|
||||
def clean_email(self):
|
||||
if not OptionalUser.objects.first().local_email_domain in self.cleaned_data.get('email'):
|
||||
|
@ -334,12 +335,14 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
|
|||
'email',
|
||||
'school',
|
||||
'comment',
|
||||
'birthday',
|
||||
'disclaimer',
|
||||
'room',
|
||||
'shell',
|
||||
'telephone',
|
||||
'gpg_fingerprint'
|
||||
]
|
||||
widgets = {'birthday':DatePicker}
|
||||
|
||||
|
||||
def clean_telephone(self):
|
||||
|
@ -600,7 +603,7 @@ class BanForm(FormRevMixin, ModelForm):
|
|||
super(BanForm, self).__init__(*args, prefix=prefix, **kwargs)
|
||||
self.fields['date_end'].label = _("End date")
|
||||
self.fields['date_end'].localize = False
|
||||
|
||||
|
||||
class Meta:
|
||||
model = Ban
|
||||
exclude = ['user']
|
||||
|
|
|
@ -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),
|
||||
),
|
||||
]
|
20
users/migrations/0078_user_date.py
Normal file
20
users/migrations/0078_user_date.py
Normal 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'),
|
||||
),
|
||||
]
|
20
users/migrations/0079_auto_20180828_0859.py
Normal file
20
users/migrations/0079_auto_20180828_0859.py
Normal 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',
|
||||
),
|
||||
]
|
20
users/migrations/0080_auto_20180828_1029.py
Normal file
20
users/migrations/0080_auto_20180828_1029.py
Normal 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'),
|
||||
),
|
||||
]
|
20
users/migrations/0081_auto_20180828_1031.py
Normal file
20
users/migrations/0081_auto_20180828_1031.py
Normal 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'),
|
||||
),
|
||||
]
|
|
@ -87,6 +87,9 @@ from machines.models import Domain, Interface, Machine, regen
|
|||
from preferences.models import GeneralOption, AssoOption, OptionalUser
|
||||
from preferences.models import OptionalMachine, MailMessageOption
|
||||
|
||||
from datetime import date
|
||||
|
||||
|
||||
|
||||
# Utilitaires généraux
|
||||
|
||||
|
@ -238,6 +241,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
|||
default=get_fresh_user_uid,
|
||||
unique=True
|
||||
)
|
||||
birthday = models.DateField(_("Date"), default=None)
|
||||
disclaimer = models.FileField(upload_to='disclaimers', blank=True)
|
||||
rezo_rez_uid = models.PositiveIntegerField(
|
||||
unique=True,
|
||||
|
|
|
@ -6,11 +6,15 @@
|
|||
<link href="/javascript/jquery-timepicker/jquery-ui-timepicker-addon.css" rel="stylesheet"/>
|
||||
<input {{attrs}} name="{{name}}" type="text" class="form-control" placeholder="Date"/>
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
$(document).ready(function(){
|
||||
{% if time %}
|
||||
$("#{{id}}").datetimepicker({
|
||||
{% else %}
|
||||
$("#{{id}}").datepicker({
|
||||
{% endif %}
|
||||
closeText: "{{closeText}}",
|
||||
currentText: "{{currentText}}",
|
||||
dateFormat:'yy-mm-dd',
|
||||
dateFormat:'dd-mm-yy',
|
||||
dayNames: {{dayNames}},
|
||||
dayNamesMin: {{dayNamesMin}},
|
||||
dayNamesShort: {{dayNamesShort}},
|
||||
|
@ -25,4 +29,5 @@ $(document).ready(function(){
|
|||
closeText: "{{closeText}}",
|
||||
})
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
|
||||
|
|
|
@ -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">
|
||||
|
||||
<script type='text/javascript'>
|
||||
$(function() {
|
||||
$( ".datepicker" ).datepicker({
|
||||
changeMonth: true,
|
||||
changeYear: true,
|
||||
yearRange: "1900:2012",
|
||||
});
|
||||
});
|
||||
function submitBday() {
|
||||
var field = document.getElementById("file");
|
||||
var Bdate = document.getElementById('bday').value;
|
||||
|
@ -100,8 +107,9 @@ function submitBday() {
|
|||
{% render_field userform.telephone class="form-control" requiered=True %}
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label>Date de naissance</label>
|
||||
<input class="form-control" id="bday" name="bday" date-date-format="dd-mm-yy" requiered=True placeholder="Date de naissance" type="date" onchange="submitBday()">
|
||||
{{ userform.birthday.label_tag}}
|
||||
{% 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>
|
||||
|
||||
|
@ -126,7 +134,7 @@ function submitBday() {
|
|||
var div = document.getElementById("div_disclaimer");
|
||||
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 age = ((Date.now() - Bday) / (31557600000));
|
||||
|
||||
|
|
|
@ -25,10 +25,12 @@ def list2str(str_iterable):
|
|||
|
||||
class DateTimePicker(Input):
|
||||
is_localized = False
|
||||
|
||||
def render(self, name, value, attrs=None):
|
||||
super().render(name, value, attrs)
|
||||
flat_attrs = flatatt(attrs)
|
||||
context = Context({
|
||||
'time': True,
|
||||
'name': name,
|
||||
'attrs': flat_attrs,
|
||||
'id': attrs['id'],
|
||||
|
@ -48,3 +50,29 @@ class DateTimePicker(Input):
|
|||
template = get_template('users/datetimepicker.html')
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue