Commit 47f5a6b2 by Kálmán Viktor

dashboard: number inputs in Lease edit

parent fcab9aeb
...@@ -12,7 +12,7 @@ from crispy_forms.layout import TEMPLATE_PACK ...@@ -12,7 +12,7 @@ from crispy_forms.layout import TEMPLATE_PACK
from crispy_forms.utils import render_field from crispy_forms.utils import render_field
from django.template import Context from django.template import Context
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django.forms.widgets import TextInput
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
# from crispy_forms.bootstrap import FormActions # from crispy_forms.bootstrap import FormActions
...@@ -343,7 +343,7 @@ class LeaseForm(forms.ModelForm): ...@@ -343,7 +343,7 @@ class LeaseForm(forms.ModelForm):
for m in methods: for m in methods:
for idx, i in enumerate(intervals): for idx, i in enumerate(intervals):
self.fields["%s_%s" % (m, i)] = forms.IntegerField( self.fields["%s_%s" % (m, i)] = forms.IntegerField(
min_value=0, min_value=0, widget=NumberInput,
initial=initial[m].get(i, 0)) initial=initial[m].get(i, 0))
def save(self, commit=True): def save(self, commit=True):
...@@ -376,6 +376,7 @@ class LeaseForm(forms.ModelForm): ...@@ -376,6 +376,7 @@ class LeaseForm(forms.ModelForm):
Div( Div(
HTML(_("Suspend in")), HTML(_("Suspend in")),
css_class="input-group-addon", css_class="input-group-addon",
style="width: 100px;",
), ),
NumberField("suspend_hours", css_class="form-control"), NumberField("suspend_hours", css_class="form-control"),
Div( Div(
...@@ -403,6 +404,7 @@ class LeaseForm(forms.ModelForm): ...@@ -403,6 +404,7 @@ class LeaseForm(forms.ModelForm):
Div( Div(
HTML(_("Delete in")), HTML(_("Delete in")),
css_class="input-group-addon", css_class="input-group-addon",
style="width: 100px;",
), ),
NumberField("delete_hours", css_class="form-control"), NumberField("delete_hours", css_class="form-control"),
Div( Div(
...@@ -451,10 +453,15 @@ class LinkButton(BaseInput): ...@@ -451,10 +453,15 @@ class LinkButton(BaseInput):
super(LinkButton, self).__init__(name, text, *args, **kwargs) super(LinkButton, self).__init__(name, text, *args, **kwargs)
class NumberInput(TextInput):
input_type = "number"
class NumberField(Field): class NumberField(Field):
template = "crispy_forms/numberfield.html" template = "crispy_forms/numberfield.html"
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
kwargs['min'] = 0
super(NumberField, self).__init__(*args, **kwargs) super(NumberField, self).__init__(*args, **kwargs)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment