mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-23 11:53:12 +00:00
Datetimepicker pour les bans et whitelists
This commit is contained in:
parent
c693f9f5ba
commit
39e96bc53d
6 changed files with 88 additions and 23 deletions
7
CHANGELOG.md
Normal file
7
CHANGELOG.md
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
Datepicker
|
||||||
|
=======
|
||||||
|
Install libjs-jquery
|
||||||
|
Install libjs-jquery-ui
|
||||||
|
Install libjs-jquery-timepicker
|
||||||
|
Install (if not) javascript-common
|
||||||
|
Enable (if not) javascript-common conf
|
|
@ -429,6 +429,10 @@ end=$(dialog --clear \
|
||||||
2>&1 >/dev/tty)
|
2>&1 >/dev/tty)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apt install libjs-jquery
|
||||||
|
apt install libjs-jquery-ui
|
||||||
|
apt install libjs-jquery-timepicker
|
||||||
|
|
||||||
main_function() {
|
main_function() {
|
||||||
if [ ! -z "$1" ]
|
if [ ! -z "$1" ]
|
||||||
then
|
then
|
||||||
|
|
|
@ -159,6 +159,7 @@ BOOTSTRAP_BASE_URL = '/static/bootstrap/'
|
||||||
# Use only absolute paths with '/' delimiters even on Windows
|
# Use only absolute paths with '/' delimiters even on Windows
|
||||||
STATICFILES_DIRS = (
|
STATICFILES_DIRS = (
|
||||||
os.path.join(BASE_DIR, 'static').replace('\\', '/'),
|
os.path.join(BASE_DIR, 'static').replace('\\', '/'),
|
||||||
|
os.path.join(BASE_DIR, 'javascript').replace('\\', '/'),
|
||||||
)
|
)
|
||||||
# Directory where the static files served by the server are stored
|
# Directory where the static files served by the server are stored
|
||||||
STATIC_ROOT = os.path.join(BASE_DIR, 'static_files')
|
STATIC_ROOT = os.path.join(BASE_DIR, 'static_files')
|
||||||
|
|
|
@ -569,13 +569,12 @@ class BanForm(FormRevMixin, ModelForm):
|
||||||
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
||||||
super(BanForm, self).__init__(*args, prefix=prefix, **kwargs)
|
super(BanForm, self).__init__(*args, prefix=prefix, **kwargs)
|
||||||
self.fields['date_end'].label = 'Date de fin'
|
self.fields['date_end'].label = 'Date de fin'
|
||||||
self.fields['date_end'].help_text = get_input_formats_help_text(
|
self.fields['date_end'].localize = False
|
||||||
self.fields['date_end'].input_formats
|
|
||||||
)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Ban
|
model = Ban
|
||||||
exclude = ['user']
|
exclude = ['user']
|
||||||
|
widgets = {'date_end':DateTimePicker}
|
||||||
|
|
||||||
|
|
||||||
class WhitelistForm(FormRevMixin, ModelForm):
|
class WhitelistForm(FormRevMixin, ModelForm):
|
||||||
|
|
28
users/templates/users/datetimepicker.html
Normal file
28
users/templates/users/datetimepicker.html
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
{% load static %}
|
||||||
|
<script src="{% static 'js/jquery-2.2.4.min.js' %}"></script>
|
||||||
|
<script src="{% static 'js/jquery-ui-1.12.1/jquery-ui.min.js' %}"></script>
|
||||||
|
<script src="{% static 'js/jquery-ui-timepicker-addon.js' %}"></script>
|
||||||
|
<link href="{% static 'js/jquery-ui-1.12.1/jquery-ui.min.css' %}" rel="stylesheet"/>
|
||||||
|
<link href="{% static 'css/jquery-ui-timepicker-addon.css' %}" rel="stylesheet"/>
|
||||||
|
<input {{attrs}} name="datetimepicker" type="text" class="form-control" placeholder="Date"/>
|
||||||
|
<script>
|
||||||
|
$(document).ready(function(){
|
||||||
|
$("#{{id}}").datetimepicker({
|
||||||
|
closeText: "{{closeText}}",
|
||||||
|
currentText: "{{currentText}}",
|
||||||
|
dateFormat:'yy-mm-dd',
|
||||||
|
dayNames: {{dayNames}},
|
||||||
|
dayNamesMin: {{dayNamesMin}},
|
||||||
|
dayNamesShort: {{dayNamesShort}},
|
||||||
|
firstDay: {{firstDay}},
|
||||||
|
isRTL: {{isRTL}},
|
||||||
|
monthNames: {{monthNames}},
|
||||||
|
monthNamesShort: {{monthNamesShort}},
|
||||||
|
nextText: {{nextText}},
|
||||||
|
prevText: {{prevText}},
|
||||||
|
timeFormat: 'HH:mm:ss',
|
||||||
|
weekHeader: {{weekHeader}},
|
||||||
|
closeText: "{{closeText}}",
|
||||||
|
})
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -3,21 +3,47 @@ from django.forms.utils import flatatt
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from django.template import Context, Template
|
from django.template import Context, Template
|
||||||
from django.template.loader import get_template
|
from django.template.loader import get_template
|
||||||
|
from django.conf import settings
|
||||||
|
from django.utils.translation import ugettext_lazy as _, get_language_bidi
|
||||||
|
from django.utils.dates import (
|
||||||
|
WEEKDAYS,
|
||||||
|
WEEKDAYS_ABBR,
|
||||||
|
MONTHS,
|
||||||
|
MONTHS_3,
|
||||||
|
MONTHS_AP,
|
||||||
|
MONTHS_ALT
|
||||||
|
)
|
||||||
|
|
||||||
|
def list2str(str_iterable):
|
||||||
|
"""
|
||||||
|
Utility function to return a string representing a list of string
|
||||||
|
|
||||||
|
:params str_iterable: An iterable object where each element is of type str
|
||||||
|
:returns: A representation of the iterable as a list (e.g '["a", "b"]')
|
||||||
|
"""
|
||||||
|
return '["' + '", "'.join(str_iterable) + '"]'
|
||||||
|
|
||||||
class DateTimePicker(Input):
|
class DateTimePicker(Input):
|
||||||
|
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)
|
||||||
html = '''{% load static %}<script src="{% static 'js/jquery-2.2.4.min.js' %}"></script><script src="{% static 'js/jquery-ui-1.12.1/jquery-ui.min.js' %}"></script><script src="{% static 'js/jquery-ui-timepicker-addon.js' %}"></script><link href="{% static 'js/jquery-ui-1.12.1/jquery-ui.min.css' %}" rel="stylesheet"/><link href="{% static 'css/jquery-ui-timepicker-addon.css' %}" rel="stylesheet"/>'''
|
context = Context({
|
||||||
html += '''<input %(attrs)s name="datetimepicker" type="text" class="form-control" id="datetimepicker"/>
|
'attrs': flat_attrs,
|
||||||
<script>
|
'id': attrs['id'],
|
||||||
$(document).ready(function(){
|
'closeText': _("Close"),
|
||||||
$("#%(id)s").datetimepicker({
|
'currentText': _("Today"),
|
||||||
dateFormat:'yy-mm-dd',
|
'dayNames': mark_safe(list2str((str(item[1]) for item in WEEKDAYS.items()))),
|
||||||
timeFormat: 'HH:mm:ss',
|
'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]) + '"'),
|
||||||
</script>'''%{'attrs':flat_attrs, 'id':attrs['id']}
|
'isRTL': str(get_language_bidi()).lower(),
|
||||||
template = Template(html)
|
'monthNames': mark_safe(list2str((str(item[1]) for item in MONTHS.items()))),
|
||||||
context = Context({})
|
'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)
|
return template.render(context)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue