Skip to content

Commit

Permalink
Merge pull request #60 from plone/thet-pawidgets
Browse files Browse the repository at this point in the history
pickadate optimizations
  • Loading branch information
jensens authored Feb 10, 2017
2 parents 6d92326 + a807cf4 commit c899002
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
6 changes: 5 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ Breaking changes:

New features:

- *add item here*
- Do not show the "Clear" button for required Date or DateTime fields.
[thet]

Bug fixes:

- Test fixes for plone.app.widgets 2.1.
[thet]

- remove deprecated __of__ for browserviews
[pbauer]

Expand Down
30 changes: 23 additions & 7 deletions plone/app/z3cform/tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def setUp(self):

self.request = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'en'})
self.field = Date(__name__='datefield')
self.field.required = False
self.widget = DateWidget(self.request)
self.widget.field = self.field
self.widget.pattern_options = {'date': {'firstDay': 0}}
Expand All @@ -164,7 +165,6 @@ def test_widget(self):
'firstDay': 0,
'min': [current_year - 100, 1, 1],
'max': [current_year + 20, 1, 1],
'clear': u'Clear',
'format': 'mmmm d, yyyy',
'monthsFull': [u'January', u'February', u'March',
u'April', u'May', u'June', u'July',
Expand All @@ -175,19 +175,27 @@ def test_widget(self):
'weekdaysFull': [u'Sunday', u'Monday', u'Tuesday',
u'Wednesday', u'Thursday', u'Friday',
u'Saturday'],
'today': u'Today',
'selectYears': 200,
'placeholder': u'Enter date...',
'monthsShort': [u'Jan', u'Feb', u'Mar', u'Apr', u'May',
u'Jun', u'Jul', u'Aug', u'Sep', u'Oct',
u'Nov', u'Dec']
},
'time': False
'time': False,
'today': u'Today',
'clear': u'Clear',
}
},
self.widget._base_args(),
)

def test_widget_required(self):
"""Required fields should not have a "Clear" button.
"""
self.field.required = True
base_args = self.widget._base_args()
self.assertEqual(base_args['pattern_options']['clear'], False)

def test_data_converter(self):
from plone.app.z3cform.widget import DateWidgetConverter
converter = DateWidgetConverter(self.field, self.widget)
Expand Down Expand Up @@ -240,7 +248,9 @@ def setUp(self):

self.request = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'en'})
self.field = Datetime(__name__='datetimefield')
self.field.required = False
self.widget = DatetimeWidget(self.request)
self.widget.field = self.field
self.widget.pattern_options = {
'date': {'firstDay': 0},
'time': {'interval': 15}
Expand All @@ -258,7 +268,6 @@ def test_widget(self):
'firstDay': 0,
'min': [current_year - 100, 1, 1],
'max': [current_year + 20, 1, 1],
'clear': u'Clear',
'format': 'mmmm d, yyyy',
'monthsFull': [u'January', u'February', u'March',
u'April', u'May', u'June', u'July',
Expand All @@ -269,7 +278,6 @@ def test_widget(self):
'weekdaysFull': [u'Sunday', u'Monday', u'Tuesday',
u'Wednesday', u'Thursday', u'Friday',
u'Saturday'],
'today': u'Today',
'selectYears': 200,
'placeholder': u'Enter date...',
'monthsShort': [u'Jan', u'Feb', u'Mar', u'Apr', u'May',
Expand All @@ -278,15 +286,23 @@ def test_widget(self):
},
'time': {
'placeholder': u'Enter time...',
'today': u'Today',
'format': 'h:i a',
'interval': 15
}
},
'today': u'Today',
'clear': u'Clear',
}
},
self.widget._base_args(),
)

def test_widget_required(self):
"""Required fields should not have a "Clear" button.
"""
self.field.required = True
base_args = self.widget._base_args()
self.assertEqual(base_args['pattern_options']['clear'], False)

def test_data_converter(self):
from plone.app.z3cform.widget import DatetimeWidgetConverter
converter = DatetimeWidgetConverter(self.field, self.widget)
Expand Down
3 changes: 3 additions & 0 deletions plone/app/z3cform/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ def _base_args(self):
self.value) or u'').strip()

args.setdefault('pattern_options', {})
if self.field.required:
# Required fields should not have a "Clear" button
args['pattern_options']['clear'] = False
args['pattern_options'] = dict_merge(
get_date_options(self.request),
args['pattern_options'])
Expand Down

1 comment on commit c899002

@jenkins-plone-org
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jensens Jenkins CI reporting about code analysis
See the full report here: http://jenkins.plone.org/job/package-plone.app.z3cform/34/violations

plone/app/z3cform/inline_validation.py:15:1: C901 'InlineValidationView.__call__' is too complex (15)
plone/app/z3cform/templates.py:24:1: E305 expected 2 blank lines after class or function definition, found 1
plone/app/z3cform/tests/example.py:26:5: D001 found implements( replace it with zope.interface.implementer
plone/app/z3cform/tests/example.py:31:13: Q000 Remove bad quotes.
plone/app/z3cform/tests/example.py:44:34: Q000 Remove bad quotes.
plone/app/z3cform/tests/example.py:55:13: Q000 Remove bad quotes.
plone/app/z3cform/tests/example.py:70:30: Q000 Remove bad quotes.
plone/app/z3cform/tests/example.py:71:55: Q000 Remove bad quotes.
plone/app/z3cform/tests/example.py:72:52: Q000 Remove bad quotes.
plone/app/z3cform/tests/example.py:77:13: Q000 Remove bad quotes.
plone/app/z3cform/tests/test_objectsubform.py:21:15: Q000 Remove bad quotes.
plone/app/z3cform/tests/test_objectsubform.py:26:15: D001 found implements( replace it with zope.interface.implementer
plone/app/z3cform/tests/test_objectsubform.py:46:15: Q000 Remove bad quotes.
plone/app/z3cform/tests/test_objectsubform.py:49:19: Q000 Remove bad quotes.
plone/app/z3cform/tests/test_objectsubform.py:57:13: Q000 Remove bad quotes.
plone/app/z3cform/tests/test_objectsubform.py:62:15: D001 found implements( replace it with zope.interface.implementer
plone/app/z3cform/tests/test_widgets.py:41:5: D001 found implements( replace it with zope.interface.implementer
plone/app/z3cform/tests/test_widgets.py:1273:40: Q000 Remove bad quotes.
plone/app/z3cform/tests/test_utils.py:21:9: E731 do not assign a lambda expression, use a def
plone/app/z3cform/tests/test_widget.py:12:15: D001 found implements( replace it with zope.interface.implementer

Follow these instructions to reproduce it locally.

Please sign in to comment.