summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2018-01-15 18:34:54 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2018-01-15 18:34:54 +0100
commit8b9880fb22e0f58d1cbde5720e173ad164cb5a1f (patch)
tree0b0e03536d5e20e14a13d7805ce1e75f1fca04ea /ishtar_common
parent1f374dd36b2901b35e4ab0bdbcfcbcbb93224f1a (diff)
downloadIshtar-8b9880fb22e0f58d1cbde5720e173ad164cb5a1f.tar.bz2
Ishtar-8b9880fb22e0f58d1cbde5720e173ad164cb5a1f.zip
UI: adapt each form to use the new date widget. Force localization of format.
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/context_processors.py7
-rw-r--r--ishtar_common/forms.py41
-rw-r--r--ishtar_common/forms_common.py9
-rw-r--r--ishtar_common/templates/base.html3
-rw-r--r--ishtar_common/widgets.py41
5 files changed, 41 insertions, 60 deletions
diff --git a/ishtar_common/context_processors.py b/ishtar_common/context_processors.py
index 911a28e33..ff97079d5 100644
--- a/ishtar_common/context_processors.py
+++ b/ishtar_common/context_processors.py
@@ -57,7 +57,12 @@ def get_base_context(request):
dct['JQUERY_UI_URL'] = settings.JQUERY_UI_URL
dct['COUNTRY'] = settings.COUNTRY
dct['VERSION'] = __version__
- dct['EXTRA_MEDIA'] = DatePicker().media
+ medias = [DatePicker().media]
+ dct['EXTRA_CSS'] = ""
+ dct['EXTRA_JS'] = ""
+ for media in medias:
+ dct['EXTRA_CSS'] += "\n" + "\n".join(media.render_css())
+ dct['EXTRA_JS'] += "\n" + "\n".join(media.render_js())
if settings.EXTRA_VERSION:
dct['VERSION'] += "-" + unicode(settings.EXTRA_VERSION)
profile = get_current_profile()
diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py
index b31a3143f..a92aef548 100644
--- a/ishtar_common/forms.py
+++ b/ishtar_common/forms.py
@@ -28,10 +28,11 @@ from django import forms
from django.core.urlresolvers import reverse
from django.core import validators
from django.forms.formsets import BaseFormSet, DELETION_FIELD_NAME
-from django.utils import formats
+from django.utils import formats, translation
from django.utils.functional import lazy
from django.utils.translation import ugettext_lazy as _
+from bootstrap_datepicker.widgets import DatePicker
import models
import widgets
from ishtar_common.utils import MultiValueDict
@@ -241,7 +242,31 @@ class FormSet(CustomForm, BaseFormSet):
form.fields[DELETION_FIELD_NAME].widget = widgets.DeleteWidget()
-class TableSelect(forms.Form):
+DATE_FORMAT = {
+ 'fr': "dd/mm/yyyy",
+ 'en': "yyyy/mm/dd",
+}
+
+
+class IshtarForm(forms.Form):
+ def __init__(self, *args, **kwargs):
+ super(IshtarForm, self).__init__(*args, **kwargs)
+ for k in self.fields:
+ cls = 'form-control'
+ if 'class' in self.fields[k].widget.attrs:
+ cls = self.fields[k].widget.attrs['class'] + " " + cls
+ self.fields[k].widget.attrs['class'] = cls
+ widget = self.fields[k].widget
+ if not isinstance(widget, DatePicker):
+ continue
+ lang = translation.get_language()
+ if lang in DATE_FORMAT:
+ widget.options['format'] = DATE_FORMAT[lang]
+ if 'autoclose' not in widget.options:
+ widget.options['autoclose'] = 'true'
+
+
+class TableSelect(IshtarForm):
def __init__(self, *args, **kwargs):
super(TableSelect, self).__init__(*args, **kwargs)
# no field is required for search
@@ -267,7 +292,7 @@ def get_now():
class ClosingDateFormSelection(forms.Form):
form_label = _("Closing date")
end_date = forms.DateField(label=_(u"Closing date"),
- widget=widgets.JQueryDate)
+ widget=DatePicker)
def __init__(self, *args, **kwargs):
if 'initial' not in kwargs:
@@ -339,16 +364,6 @@ def get_data_from_formset(data):
return values
-class IshtarForm(forms.Form):
- def __init__(self, *args, **kwargs):
- super(IshtarForm, self).__init__(*args, **kwargs)
- for k in self.fields:
- cls = 'form-control'
- if 'class' in self.fields[k].widget.attrs:
- cls = self.fields[k].widget.attrs['class'] + " " + cls
- self.fields[k].widget.attrs['class'] = cls
-
-
class FieldType(object):
def __init__(self, key, model, is_multiple=False, extra_args=None):
self.key = key
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py
index 4edb22c18..708e246b2 100644
--- a/ishtar_common/forms_common.py
+++ b/ishtar_common/forms_common.py
@@ -33,6 +33,7 @@ from django.utils.translation import ugettext_lazy as _
import models
import widgets
+from bootstrap_datepicker.widgets import DatePicker
from ishtar_common.templatetags.link_to_window import link_to_window
from forms import FinalForm, FormSet, reverse_lazy, name_validator, \
TableSelect, ManageOldType, CustomForm, FieldType
@@ -863,7 +864,7 @@ class MergeOrganizationForm(MergeForm):
######################
# Sources management #
######################
-class SourceForm(CustomForm, ManageOldType, forms.Form):
+class SourceForm(CustomForm, ManageOldType):
form_label = _(u"Documentation informations")
form_admin_name = _("Source - General")
form_slug = "source-general"
@@ -882,12 +883,12 @@ class SourceForm(CustomForm, ManageOldType, forms.Form):
associated_url = forms.URLField(
required=False, label=_(u"Numerical ressource (web address)"))
receipt_date = forms.DateField(label=_(u"Receipt date"), required=False,
- widget=widgets.JQueryDate)
+ widget=DatePicker)
creation_date = forms.DateField(label=_(u"Creation date"), required=False,
- widget=widgets.JQueryDate)
+ widget=DatePicker)
receipt_date_in_documentation = forms.DateField(
label=_(u"Receipt date in documentation"), required=False,
- widget=widgets.JQueryDate)
+ widget=DatePicker)
comment = forms.CharField(label=_(u"Comment"), widget=forms.Textarea,
required=False)
description = forms.CharField(label=_(u"Description"),
diff --git a/ishtar_common/templates/base.html b/ishtar_common/templates/base.html
index 5171af374..329198be7 100644
--- a/ishtar_common/templates/base.html
+++ b/ishtar_common/templates/base.html
@@ -22,6 +22,7 @@
<script language="javascript" type="text/javascript" src="{{STATIC_URL}}js/ishtar.js?ver={{VERSION}}"></script>
<script language="javascript" type="text/javascript"
src="{{STATIC_URL}}datatables/i18n/{{LANGUAGE_CODE}}.js?ver={{VERSION}}"></script>
+ {{EXTRA_JS|safe}}
<script type='text/javascript'>
var shortcut_url = '{% url "shortcut-menu" %}';
var get_file_url = '{% url "get-file-shortcut" %}';
@@ -44,8 +45,8 @@
<link rel="stylesheet" href="{{STATIC_URL}}datatables/dataTables.bootstrap4.min.css?ver={{VERSION}}">
<link rel="stylesheet" href="{{STATIC_URL}}media/styles.css?ver={{VERSION}}">
{% for url_css in JQGRID_CSS %}<link rel="stylesheet" href="{{url_css}}?ver={{VERSION}}">{% endfor %}
+ {{EXTRA_CSS|safe}}
{% endcompress %}
- {{EXTRA_MEDIA}}
{% block extra_head %}
{% endblock %}
{% comment %}{% if raw_css %}<style media="screen" type="text/css">
diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py
index c34642cf1..e5cb35db4 100644
--- a/ishtar_common/widgets.py
+++ b/ishtar_common/widgets.py
@@ -284,47 +284,6 @@ if settings.SURFACE_UNIT == 'square-metre':
AreaWidget = SquareMeterWidget
-class JQueryDate(forms.TextInput):
- def __init__(self, *args, **kwargs):
- super(JQueryDate, self).__init__(*args, **kwargs)
- if 'class' not in self.attrs:
- self.attrs['class'] = ''
- self.attrs['class'] = 'date-pickup'
-
- def render(self, name, value, attrs=None, renderer=None):
- if value:
- value = unicode(value)
- # very specific...
- if settings.COUNTRY == 'fr' and value and '/' in value:
- values = value.split('/')
- if len(values) == 3:
- value = "%s-%s-%s" % (values[2], values[1], values[0])
- if not attrs:
- attrs = {}
- attrs['autocomplete'] = 'off'
- rendered = super(JQueryDate, self).render(name, value, attrs)
- # use window.onload to be sure that datepicker don't interfere
- # with autocomplete fields
- var_name = name.replace('-', '_')
- rendered += """
-<script type="text/javascript"><!--//
- function load_jquerydate_%(var_name)s(){
- $(".date-pickup").datepicker($.datepicker.regional["%(country)s"]);
- var val = $("#id_%(name)s").val();
- if(val){
- var dt = $.datepicker.parseDate('yy-mm-dd', val);
- val = $.datepicker.formatDate(
- $.datepicker.regional["%(country)s"]['dateFormat'],
- dt);
- $("#id_%(name)s").val(val);
- }
- }
- $(window).load(load_jquerydate_%(var_name)s);
-//--></script>
-""" % {"name": name, "var_name": var_name, "country": settings.COUNTRY}
- return rendered
-
-
class JQueryAutoComplete(forms.TextInput):
def __init__(self, source, associated_model=None, options=None, attrs=None,
new=False, url_new='', multiple=False, limit=None,