...
 
Commits (12)
...@@ -147,3 +147,13 @@ th.long_text{ ...@@ -147,3 +147,13 @@ th.long_text{
.dashboard{ .dashboard{
text-align: center; text-align: center;
} }
.table-borderless td,
.table-borderless th {
border: none !important;
}
/* nicer forms */
.form-control {
height: auto;
}
...@@ -46,7 +46,7 @@ from re2o.utils import remove_user_room, get_input_formats_help_text ...@@ -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,
...@@ -313,9 +313,8 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm): ...@@ -313,9 +313,8 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
self.fields['email'].label = _("Email address") self.fields['email'].label = _("Email address")
self.fields['school'].label = _("School") self.fields['school'].label = _("School")
self.fields['comment'].label = _("Comment") self.fields['comment'].label = _("Comment")
self.fields['room'].label = _("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,11 +333,13 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm): ...@@ -334,11 +333,13 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
'email', 'email',
'school', 'school',
'comment', 'comment',
'room', 'birthday',
'disclaimer',
'shell', 'shell',
'telephone', 'telephone',
'gpg_fingerprint' 'gpg_fingerprint'
] ]
widgets = {'birthday':DatePicker}
def clean_telephone(self): def clean_telephone(self):
...@@ -379,6 +380,7 @@ class ClubForm(FormRevMixin, FieldPermissionFormMixin, ModelForm): ...@@ -379,6 +380,7 @@ class ClubForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
prefix = kwargs.pop('prefix', self.Meta.model.__name__) prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(ClubForm, self).__init__(*args, prefix=prefix, **kwargs) super(ClubForm, self).__init__(*args, prefix=prefix, **kwargs)
self.fields['surname'].label = _("Name") self.fields['surname'].label = _("Name")
self.fields['email'].label = _("Email address")
self.fields['school'].label = _("School") self.fields['school'].label = _("School")
self.fields['comment'].label = _("Comment") self.fields['comment'].label = _("Comment")
self.fields['room'].label = _("Room") self.fields['room'].label = _("Room")
...@@ -391,6 +393,7 @@ class ClubForm(FormRevMixin, FieldPermissionFormMixin, ModelForm): ...@@ -391,6 +393,7 @@ class ClubForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
fields = [ fields = [
'surname', 'surname',
'pseudo', 'pseudo',
'email',
'school', 'school',
'comment', 'comment',
'room', 'room',
...@@ -597,7 +600,7 @@ class BanForm(FormRevMixin, ModelForm): ...@@ -597,7 +600,7 @@ class BanForm(FormRevMixin, ModelForm):
super(BanForm, self).__init__(*args, prefix=prefix, **kwargs) super(BanForm, self).__init__(*args, prefix=prefix, **kwargs)
self.fields['date_end'].label = _("End date") self.fields['date_end'].label = _("End date")
self.fields['date_end'].localize = False self.fields['date_end'].localize = False
class Meta: class Meta:
model = Ban model = Ban
exclude = ['user'] exclude = ['user']
......
# -*- 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'),
),
]
# -*- 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',
),
]
# -*- 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'),
),
]
# -*- 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 ...@@ -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,8 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, ...@@ -238,6 +241,8 @@ 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)
rezo_rez_uid = models.PositiveIntegerField( rezo_rez_uid = models.PositiveIntegerField(
unique=True, unique=True,
blank=True, blank=True,
......
...@@ -6,11 +6,15 @@ ...@@ -6,11 +6,15 @@
<link href="/javascript/jquery-timepicker/jquery-ui-timepicker-addon.css" rel="stylesheet"/> <link href="/javascript/jquery-timepicker/jquery-ui-timepicker-addon.css" rel="stylesheet"/>
<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}},
...@@ -25,4 +29,5 @@ $(document).ready(function(){ ...@@ -25,4 +29,5 @@ $(document).ready(function(){
closeText: "{{closeText}}", closeText: "{{closeText}}",
}) })
}); });
</script> </script>
...@@ -24,18 +24,190 @@ with this program; if not, write to the Free Software Foundation, Inc., ...@@ -24,18 +24,190 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% endcomment %} {% endcomment %}
{% load bootstrap3 %} {% load bootstrap3 %}
{% load widget_tweaks %}
{% load massive_bootstrap_form %} {% load massive_bootstrap_form %}
{% load static %} {% load static %}
{% load acl %}
{% load i18n %} {% load i18n %}
{% block title %}{% trans "Users" %}{% endblock %} {% block title %}{% trans "Users" %}{% endblock %}
{% block content %} {% block content %}
{% bootstrap_form_errors userform %} {% bootstrap_form_errors userform %}
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js"></script>
<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;
var Bday = +new Date(Bdate);
var age = ((Date.now() - Bday) / (31557600000));
if (age < 18){
field.style.display = "block";
}
else{
field.style.display = "none";
}
}
</script>
<form class="form" method="post"> <form class="form" method="post">
{% csrf_token %} {% csrf_token %}
{% if action_name == 'Create a user' or action_name == 'Create a club' %}
<h3>Informations générales</h3>
{% if action_name == 'Create a user' %}
<div class="form-row">
<div class="form-group col-md-4">
{{ userform.name.label_tag }}
{% render_field userform.name class="form-control" %}
</div>
<div class="form-group col-md-4">
{{ userform.surname.label_tag }}
{% render_field userform.surname class="form-control" %}
</div>
<div class="form-group col-md-4">
{{ userform.pseudo.label_tag }}
{% render_field userform.pseudo class="form-control" %}
</div>
</div>
{% elif action_name == 'Create a club' %}
<div class="form-row">
<div class="form-group col-md-6">
{{ userform.surname.label_tag }}
{% render_field userform.surname class="form-control" %}
</div>
<div class="form-group col-md-6">
{{ userform.pseudo.label_tag }}
{% render_field userform.pseudo class="form-control" %}
</div>
</div>
{% endif %}
{% if action_name == 'Create a user' %}
<div class="form-row">
<div class="form-group col-md-4">
{{ userform.email.label_tag }}
{% render_field userform.email class="form-control" %}
</div>
<div class="form-group col-md-4">
{{ userform.telephone.label_tag }}
{% render_field userform.telephone class="form-control" %}
</div>
<div class="form-group col-md-4">
{{ userform.birthday.label_tag}}
{% render_field userform.birthday class="form-control" onchange='submitBday()' %}
{# <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 class="form-group">
{% if user.is_authenticated %}
{% can_edit user %}
<div class="disclaimer" style="display:none;" id="div_disclaimer">
<input type="checkbox" id="{{userform.disclaimer.auto_id}}" name="box_disclaimer" requiered=True />
<label for="scales">Décharge parentale reçue</label>
</div>
{% acl_end %}
{% else %}
<div class="disclaimer" style="display:none;" id="div_disclaimer">
{{ userform.disclaimer.label_tag }}
{% render_field userform.disclaimer class="form-control" %}
</div>
{% endif %}
</div>
<script type='text/javascript'>
function submitBday() {
var div = document.getElementById("div_disclaimer");
var input = document.getElementById("{{userform.disclaimer.auto_id}}");
var Bdate = document.getElementById('{{userform.birthday.auto_id}}').value;
var Bday = +new Date(Bdate.replace(/(\d{2})[-/](\d{2})[-/](\d+)/, "$2/$1/$3"));
var age = ((Date.now() - Bday) / (31557600000));
if (age < 18){
div.style.display = "block";
input.setAttribute("requiered", "True");
}
else{
div.style.display = "none";
input.removeAttribute("requiered");
}
}
</script>
{% elif action_name == 'Create a club' %}
<div class="form-group">
{{ userform.email.label_tag }}
{% render_field userform.email class="form-control" %}
</div>
{% endif %}
<div class="form-group">
{{ userform.school.label_tag }}
{% render_field userform.school class="form-control" %}
</div>
<div class="form-group">
{{ userform.room.label_tag }}
{% render_field userform.room class="form-control" %}
</div>
<div class="form-group">
{{ userform.comment.label_tag }}
{% render_field userform.comment class="form-control" %}
</div>
{% if action_name == 'Create a club' %}
<div class="form-group">
{{ userform.mailing.label_tag }}
<input type="checkbox" id="{{userform.mailing.auto_id}}" name="box_mailing" />
</div>
{% endif %}
<h3>Informations avancées (facultatif)</h3>
<div class="table-responsive">
<table class="table table-borderless">
<tr>
<th>
{{ userform.shell.label_tag }}
{% render_field field class="form-control is-valid" %}
</th>
<td>
{% render_field userform.shell class="form-control" placeholder=userform.shell.label %}
</td>
</tr>
{% if action_name == 'Create a user' %}
<tr>
<th>
{{ userform.gpg_fingerprint.label_tag }}
</th>
<td>
{% render_field userform.gpg_fingerprint class="form-control" placeholder=userform.gpg_fingerprint.label %}
</td>
</tr>
{% endif %}
</table>
</div>
{% else %}
{% massive_bootstrap_form userform 'room,school,administrators,members' %} {% massive_bootstrap_form userform 'room,school,administrators,members' %}
{% bootstrap_button action_name button_type="submit" icon="star" %} {% endif %}
<button class="btn btn-success" type="submit">{{ action_name }}</button>
</form> </form>
{% if load_js_file %} {% if load_js_file %}
<script src="{{ load_js_file }}"></script> <script src="{{ load_js_file }}"></script>
......
...@@ -25,10 +25,12 @@ def list2str(str_iterable): ...@@ -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): ...@@ -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)