...
 
Commits (12)
......@@ -147,3 +147,13 @@ th.long_text{
.dashboard{
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
from re2o.mixins import FormRevMixin
from re2o.field_permissions import FieldPermissionFormMixin
from .widgets import DateTimePicker
from .widgets import DateTimePicker, DatePicker
from .models import (
User,
......@@ -313,9 +313,8 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
self.fields['email'].label = _("Email address")
self.fields['school'].label = _("School")
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['birthday'].label = _("Your birthday")
def clean_email(self):
if not OptionalUser.objects.first().local_email_domain in self.cleaned_data.get('email'):
......@@ -334,11 +333,13 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
'email',
'school',
'comment',
'room',
'birthday',
'disclaimer',
'shell',
'telephone',
'gpg_fingerprint'
]
widgets = {'birthday':DatePicker}
def clean_telephone(self):
......@@ -379,6 +380,7 @@ class ClubForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(ClubForm, self).__init__(*args, prefix=prefix, **kwargs)
self.fields['surname'].label = _("Name")
self.fields['email'].label = _("Email address")
self.fields['school'].label = _("School")
self.fields['comment'].label = _("Comment")
self.fields['room'].label = _("Room")
......@@ -391,6 +393,7 @@ class ClubForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
fields = [
'surname',
'pseudo',
'email',
'school',
'comment',
'room',
......
# -*- 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
from preferences.models import GeneralOption, AssoOption, OptionalUser
from preferences.models import OptionalMachine, MailMessageOption
from datetime import date
# Utilitaires généraux
......@@ -238,6 +241,8 @@ 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,
blank=True,
......
......@@ -7,10 +7,14 @@
<input {{attrs}} name="{{name}}" type="text" class="form-control" placeholder="Date"/>
<script>
$(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}},
......@@ -26,3 +30,4 @@ $(document).ready(function(){
})
});
</script>
......@@ -24,18 +24,190 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% endcomment %}
{% load bootstrap3 %}
{% load widget_tweaks %}
{% load massive_bootstrap_form %}
{% load static %}
{% load acl %}
{% load i18n %}
{% block title %}{% trans "Users" %}{% endblock %}
{% block content %}
{% 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">
{% 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' %}
{% bootstrap_button action_name button_type="submit" icon="star" %}
{% endif %}
<button class="btn btn-success" type="submit">{{ action_name }}</button>
</form>
{% if load_js_file %}
<script src="{{ load_js_file }}"></script>
......
......@@ -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)