~ubuntu-branches/ubuntu/trusty/horizon/trusty-updates

« back to all changes in this revision

Viewing changes to horizon/forms/base.py

  • Committer: Package Import Robot
  • Author(s): Adam Gandelman
  • Date: 2013-09-06 11:59:43 UTC
  • mfrom: (1.1.30)
  • Revision ID: package-import@ubuntu.com-20130906115943-h3td0l7tp16mb9oc
Tags: 1:2013.2~b3-0ubuntu1
* New upstream release.
* debian/control: Minimum python-openstack-auth version >= 1.1.1.
* debian/control: Add python-troveclient.
* debian/static: Refresh static assets for 2013.2~b3.
* debian/patches: ubuntu_local_settings.patch -> ubuntu_settings.patch, also
  patch location of secret key in openstack_dashboard/settings.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#    under the License.
20
20
 
21
21
from django import forms
22
 
from django.forms.forms import NON_FIELD_ERRORS
23
 
from django.utils import dates
24
 
from django.utils import timezone
 
22
from django.forms.forms import NON_FIELD_ERRORS  # noqa
25
23
 
26
24
 
27
25
class SelfHandlingMixin(object):
38
36
    A base :class:`Form <django:django.forms.Form>` class which includes
39
37
    processing logic in its subclasses.
40
38
    """
 
39
    required_css_class = 'required'
 
40
 
41
41
    def api_error(self, message):
42
42
        """
43
43
        Adds an error to the form's error dictionary after validation
49
49
 
50
50
 
51
51
class DateForm(forms.Form):
52
 
    """ A simple form for selecting a start date. """
53
 
    month = forms.ChoiceField(choices=dates.MONTHS.items())
54
 
    year = forms.ChoiceField()
 
52
    """ A simple form for selecting a range of time. """
 
53
    start = forms.DateField(input_formats=("%Y-%m-%d",))
 
54
    end = forms.DateField(input_formats=("%Y-%m-%d",))
55
55
 
56
56
    def __init__(self, *args, **kwargs):
57
57
        super(DateForm, self).__init__(*args, **kwargs)
58
 
        years = [(year, year) for year
59
 
                 in xrange(2009, timezone.now().year + 1)]
60
 
        years.reverse()
61
 
        self.fields['year'].choices = years
 
58
        self.fields['start'].widget.attrs['data-date-format'] = "yyyy-mm-dd"
 
59
        self.fields['end'].widget.attrs['data-date-format'] = "yyyy-mm-dd"