diff --git a/mayan/apps/common/widgets.py b/mayan/apps/common/widgets.py index b89d01f0a0..2bdd5a8a03 100644 --- a/mayan/apps/common/widgets.py +++ b/mayan/apps/common/widgets.py @@ -11,15 +11,6 @@ from django.utils.safestring import mark_safe from django.utils.translation import ugettext_lazy as _ -class PlainWidget(forms.widgets.Widget): - """ - Class to define a form widget that effectively nulls the htmls of a - widget and reduces the output to only it's value - """ - def render(self, name, value, attrs=None): - return mark_safe('%s' % value) - - class DetailSelectMultiple(forms.widgets.SelectMultiple): def __init__(self, queryset=None, *args, **kwargs): self.queryset = queryset @@ -61,41 +52,30 @@ class DetailSelectMultiple(forms.widgets.SelectMultiple): return mark_safe(output + '\n') -def exists_widget(path): - try: - return two_state_template(os.path.exists(path)) - except Exception as exception: - return exception - - -def two_state_template(state, ok_icon='fa fa-check', fail_icon='fa fa-times'): - if state: - return mark_safe(''.format(ok_icon)) - else: - return mark_safe(''.format(fail_icon)) - - -class TextAreaDiv(forms.widgets.Widget): +# From: http://www.peterbe.com/plog/emailinput-html5-django +class EmailInput(forms.widgets.Input): """ - Class to define a form widget that simulates the behavior of a - Textarea widget but using a div tag instead + Class for a login form widget that accepts only well formated + email address """ - - def __init__(self, attrs=None): - # The 'rows' and 'cols' attributes are required for HTML correctness. - default_attrs = {'class': 'text_area_div'} - if attrs: - default_attrs.update(attrs) - super(TextAreaDiv, self).__init__(default_attrs) + input_type = 'email' def render(self, name, value, attrs=None): - if value is None: - value = '' + if attrs is None: + attrs = {} + attrs.update(dict(autocorrect='off', + autocapitalize='off', + spellcheck='false')) + return super(EmailInput, self).render(name, value, attrs=attrs) - flat_attrs = flatatt(self.build_attrs(attrs, name=name)) - content = conditional_escape(force_unicode(value)) - result = '
%s' % (flat_attrs, content) - return mark_safe(result) + +class PlainWidget(forms.widgets.Widget): + """ + Class to define a form widget that effectively nulls the htmls of a + widget and reduces the output to only it's value + """ + def render(self, name, value, attrs=None): + return mark_safe('%s' % value) class ScrollableCheckboxSelectMultiple(forms.widgets.CheckboxSelectMultiple): @@ -129,3 +109,40 @@ class ScrollableCheckboxSelectMultiple(forms.widgets.CheckboxSelectMultiple): output.append('') return mark_safe('
%s' % (flat_attrs, content) + return mark_safe(result) + + +def exists_widget(path): + try: + return two_state_template(os.path.exists(path)) + except Exception as exception: + return exception + + +def two_state_template(state, ok_icon='fa fa-check', fail_icon='fa fa-times'): + if state: + return mark_safe(''.format(ok_icon)) + else: + return mark_safe(''.format(fail_icon))