From 8499caddf7966b64acd2f302b7c2cc8122dab420 Mon Sep 17 00:00:00 2001 From: Is Isilon Date: Thu, 7 Jan 2016 08:32:24 +0800 Subject: [PATCH 1/6] Added html inputs, fields, and samples --- wtformsparsleyjs/core.py | 111 +++++++++++++++++++++++++++++- wtformsparsleyjs/sample/sample.py | 44 +++++++++++- 2 files changed, 152 insertions(+), 3 deletions(-) diff --git a/wtformsparsleyjs/core.py b/wtformsparsleyjs/core.py index f428b9b..129f6cf 100644 --- a/wtformsparsleyjs/core.py +++ b/wtformsparsleyjs/core.py @@ -25,6 +25,16 @@ from wtforms.fields import StringField as _StringField, BooleanField as _Boolean DateTimeField as _DateTimeField, FileField as _FileField, \ SelectMultipleField as _SelectMultipleField +from wtforms.fields.html5 import URLField as _URLField, EmailField as _EmailField, \ + DecimalRangeField as _DecimalRangeField, SearchField as _SearchField, \ + TelField as _TelField, IntegerRangeField as _IntegerRangeField + +from wtforms.widgets.html5 import ColorInput as _ColorInput, DateInput as _DateInput, \ + DateTimeInput as _DateTimeInput, EmailInput as _EmailInput, \ + RangeInput as _RangeInput, TelInput as _TelInput, URLInput as _UrlInput, \ + NumberInput as _NumberInput, SearchInput as _SearchInput, TimeInput as _TimeInput, \ + WeekInput as _WeekInput + def parsley_kwargs(field, kwargs): """ @@ -88,6 +98,7 @@ def parsley_kwargs(field, kwargs): return new_kwargs + def _email_kwargs(kwargs): kwargs[u'data-parsley-type'] = u'email' @@ -124,6 +135,7 @@ def _number_range_kwargs(kwargs, vali): def _input_required_kwargs(kwargs): kwargs[u'data-parsley-required'] = u'true' + def _regexp_kwargs(kwargs, vali): # Apparently, this is the best way to check for RegexObject Type # It's needed because WTForms allows compiled regexps to be passed to the validator @@ -134,35 +146,45 @@ def _regexp_kwargs(kwargs, vali): regex_string = vali.regex kwargs[u'data-parsley-pattern'] = regex_string + def _url_kwargs(kwargs): kwargs[u'data-parsley-type'] = u'url' + def _anyof_kwargs(kwargs, vali): # The inlist validator is no longer available in Parsley 2.x, so a custom anyof validator is used. kwargs[u'data-parsley-anyof'] = json.dumps(vali.values) + def _mac_address_kwargs(kwargs): kwargs[u'data-parsley-pattern'] = '^(?:[0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$' + def _uuid_kwargs(kwargs): kwargs[u'data-parsley-pattern'] = '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$' + def _none_of_kwargs(kwargs, vali): - #data-parsley-noneof is a custom validator, it can be found in scripts/parsley-noneof.js + # data-parsley-noneof is a custom validator, it can be found in scripts/parsley-noneof.js kwargs[u'data-parsley-noneof'] = json.dumps(vali.values) + def _trigger_kwargs(kwargs, trigger=u'change'): kwargs[u'data-parsley-trigger'] = trigger + def _message_kwargs(kwargs, message): kwargs[u'data-parsley-error-message'] = message + def _date_kwargs(kwargs, field): kwargs[u'data-parsley-datefield'] = field.format + def _integer_kwargs(kwargs): kwargs[u'data-parsley-type'] = "integer" + def _number_kwargs(kwargs): kwargs[u'data-parsley-type'] = "number" @@ -194,6 +216,51 @@ class TextArea(_TextArea): class CheckboxInput(_CheckboxInput, ParsleyInputMixin): pass + +class ColorInput(_ColorInput, ParsleyInputMixin): + pass + + +class DateInput(_DateInput, ParsleyInputMixin): + pass + + +class DateTimeInput(_DateTimeInput, ParsleyInputMixin): + pass + + +class EmailInput(_EmailInput, ParsleyInputMixin): + pass + + +class RangeInput(_RangeInput, ParsleyInputMixin): + pass + + +class TelInput(_TelInput, ParsleyInputMixin): + pass + + +class URLInput(_UrlInput, ParsleyInputMixin): + pass + + +class NumberInput(_NumberInput, ParsleyInputMixin): + pass + + +class TimeInput(_TimeInput, ParsleyInputMixin): + pass + + +class WeekInput(_WeekInput, ParsleyInputMixin): + pass + + +class SearchInput(_SearchInput, ParsleyInputMixin): + pass + + class RadioInput(_RadioInput): def __init__(self, parsley_options): self.parsley_options = parsley_options @@ -202,6 +269,7 @@ class RadioInput(_RadioInput): kwargs.update(self.parsley_options) return super(RadioInput, self).__call__(field, **kwargs) + class Select(_Select): def __call__(self, field, **kwargs): kwargs = parsley_kwargs(field, kwargs) @@ -317,3 +385,44 @@ class SelectMultipleField(_SelectMultipleField): def __init__(self, *args, **kwargs): super(SelectMultipleField, self).__init__(*args, **kwargs) + +class URLField(_URLField): + widget = URLInput() + + def __init__(self, *args, **kwargs): + super(URLField, self).__init__(*args, **kwargs) + + +class TelField(_TelField): + widget = TelInput() + + def __init__(self, *args, **kwargs): + super(TelField, self).__init__(*args, **kwargs) + + +class SearchField(_SearchField): + widget = SearchInput() + + def __init__(self, *args, **kwargs): + super(SearchField, self).__init__(*args, **kwargs) + + +class EmailField(_EmailField): + widget = EmailInput() + + def __init__(self, *args, **kwargs): + super(EmailField, self).__init__(*args, **kwargs) + + +class DecimalRangeField(_DecimalRangeField): + widget = RangeInput() + + def __init__(self, *args, **kwargs): + super(DecimalRangeField, self).__init__(*args, **kwargs) + + +class IntegerRangeField(_IntegerRangeField): + widget = NumberInput() + + def __init__(self, *args, **kwargs): + super(IntegerRangeField, self).__init__(*args, **kwargs) diff --git a/wtformsparsleyjs/sample/sample.py b/wtformsparsleyjs/sample/sample.py index ef05131..7836144 100644 --- a/wtformsparsleyjs/sample/sample.py +++ b/wtformsparsleyjs/sample/sample.py @@ -16,7 +16,7 @@ def parsley_testform(): class ParsleyTestForm(Form): - email = wtformsparsleyjs.StringField( + email = wtformsparsleyjs.EmailField( label = 'E-Mail Address', validators = [ validators.Email( @@ -265,7 +265,7 @@ class ParsleyTestForm(Form): default = 6 ) - # No default values for passwords, becuase the aren't rendered as a safety + # No default values for passwords, because the aren't rendered as a safety # feature. secret = wtformsparsleyjs.PasswordField( label = "Enter your secret:", @@ -296,3 +296,43 @@ class ParsleyTestForm(Form): ], default = "This is my life story, it has to be at least 50 characters." ) + + url = wtformsparsleyjs.URLField( + label = "Enter your website: ", + default = "crashoverhackthemainframe.c" + ) + + search = wtformsparsleyjs.SearchField( + label = "Enter your search term: ", + validators = [ + validators.Length( + max = 10, + message = "Search query too long it almost killed our server" + ) + ], + default = "How can mirrors be real when our eyes arn't real?" + ) + + decimal_range = wtformsparsleyjs.DecimalRangeField( + label = "Enter your favorite decimal: ", + validators = [ + validators.NumberRange( + message = "That's not your favourite number, it's between 0 and 50", + min = 0, + max = 50 + ) + ], + default = 70, + ) + + ineger_range = wtformsparsleyjs.IntegerRangeField( + label = "Enter your age (you must be over 18): ", + validators = [ + validators.NumberRange( + message = "That's not your age, it's between 3 and 5", + min = 3, + max = 5 + ), + ], + default = 18 + ) From f449f2013b3bfda9924649f5e9e6358c4533dd44 Mon Sep 17 00:00:00 2001 From: Is Isilon Date: Thu, 7 Jan 2016 08:40:26 +0800 Subject: [PATCH 2/6] Added telephone field example --- wtformsparsleyjs/sample/sample.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/wtformsparsleyjs/sample/sample.py b/wtformsparsleyjs/sample/sample.py index 7836144..d43e168 100644 --- a/wtformsparsleyjs/sample/sample.py +++ b/wtformsparsleyjs/sample/sample.py @@ -302,6 +302,16 @@ class ParsleyTestForm(Form): default = "crashoverhackthemainframe.c" ) + tel = wtformsparsleyjs.TelField( + label = "Enter your telephone number: ", + validators = [ + validators.Regexp('^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}$', + message = "Please enter a valid telephone number e.g. +91 (123) 456-7890" + ) + ], + default = "+91 (123) 456-7890 0000000" + ) + search = wtformsparsleyjs.SearchField( label = "Enter your search term: ", validators = [ From 07bac1fb0aad93152cb4e79d2885f399114e7c02 Mon Sep 17 00:00:00 2001 From: Is Isilon Date: Thu, 7 Jan 2016 08:47:08 +0800 Subject: [PATCH 3/6] Bumped to version 1.0.5 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index e6a8ab8..20b9319 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ from setuptools import setup setup( name='WTForms-ParsleyJS', - version='0.1.4', + version='0.1.5', url='https://github.com/johannes-gehrs/wtforms-parsleyjs', license='MIT', author='Johannes Gehrs', From 5d5b7b50574c58517614170732e2944f1ca79f79 Mon Sep 17 00:00:00 2001 From: Is Isilon Date: Thu, 7 Jan 2016 08:49:14 +0800 Subject: [PATCH 4/6] Bumped to version 2.0.1 to match readme title --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 20b9319..a4172be 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ from setuptools import setup setup( name='WTForms-ParsleyJS', - version='0.1.5', + version='2.0.1', url='https://github.com/johannes-gehrs/wtforms-parsleyjs', license='MIT', author='Johannes Gehrs', From f7e78b08eb8594431fe77f6abf8274780601ef3f Mon Sep 17 00:00:00 2001 From: Is Isilon Date: Thu, 7 Jan 2016 08:53:32 +0800 Subject: [PATCH 5/6] Updated setup.py to new github repo --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index a4172be..d65e354 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ JavaScript validation library. It is configured using specific HTML markup in th This library will generate these attributes from your WTForms validators. For more information consult the README.md in the Github repository at -https://github.com/johannes-gehrs/wtforms-parsleyjs +https://github.com/fuhrysteve/wtforms-parsleyjs """ from setuptools import setup @@ -20,7 +20,7 @@ from setuptools import setup setup( name='WTForms-ParsleyJS', version='2.0.1', - url='https://github.com/johannes-gehrs/wtforms-parsleyjs', + url='https://github.com/fuhrysteve/wtforms-parsleyjs', license='MIT', author='Johannes Gehrs', author_email='jgehrs@gmail.com', From e4abb705ba2aae2be5287fd90298e941c5940be5 Mon Sep 17 00:00:00 2001 From: Is Isilon Date: Thu, 7 Jan 2016 09:31:50 +0800 Subject: [PATCH 6/6] added download_url --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index d65e354..8dd2876 100644 --- a/setup.py +++ b/setup.py @@ -21,6 +21,7 @@ setup( name='WTForms-ParsleyJS', version='2.0.1', url='https://github.com/fuhrysteve/wtforms-parsleyjs', + download_url='https://github.com/fuhrysteve/wtforms-parsleyjs/tarball/2.0.1', license='MIT', author='Johannes Gehrs', author_email='jgehrs@gmail.com',