class AgendarForm(forms.Form): CHOICES=(('1','Básico'),('2','Intermedio'),('3','Avanzado')) #hora_inicio= forms.DateTimeField(widget=widgets.AdminDateWidget()) #hora_inicio= forms.DateTimeField(widget=) num_paquete= forms.ChoiceField(choices=CHOICES) #fecha = forms.DateField(widget=SelectDateWidget(empty_label="Nothing"),label="Fecha") hora= forms.DateField(widget=SuitTimeWidget(attrs={'placeholder':'Time'})) fecha2= forms.DateField(widget=SuitDateWidget)
def __init__(self, attrs=None, date_attrs=None, date_format=None, time_attrs=None, time_format=None): widgets = [ SuitDateWidget(attrs=date_attrs, format=date_format), SuitTimeWidget(attrs=time_attrs, format=time_format) ] forms.MultiWidget.__init__(self, widgets, attrs)
class WorkingHoursInline(StackedInline): model = WorkingHours verbose_name = 'Weekday' verbose_name_plural = 'Comfortable hours' formfield_overrides = { models.TimeField: { 'widget': SuitTimeWidget(attrs={ 'placeholder': '16:45', 'maxlength': '5', 'class': 'numonly' }) } }
def test_SuitTimeWidget_output(self): sdw = SuitTimeWidget(attrs={'placeholder': 'Time'}) output = sdw.render('sdw', '') self.assertHTMLEqual( self.get_SuitTimeWidget_output(), output)
def test_SuitTimeWidget_with_existing_placeholder_attr(self): sdw = SuitTimeWidget(attrs={'class': 'custom-cls', 'placeholder': 'p'}) self.assertTrue('vTimeField ' in sdw.attrs['class']) self.assertTrue(' custom-cls' in sdw.attrs['class']) self.assertEqual('p', sdw.attrs['placeholder'])
def test_SuitTimeWidget_with_existing_class_attr(self): sdw = SuitTimeWidget(attrs={'class': 'custom-class'}) self.assertTrue('vTimeField ' in sdw.attrs['class']) self.assertTrue(' custom-class' in sdw.attrs['class']) self.assertEqual(_('Time:')[:-1], sdw.attrs['placeholder'])
def test_SuitTimeWidget(self): sdw = SuitTimeWidget() self.assertTrue('vTimeField' in sdw.attrs['class'])
def test_SuitTimeWidget_output(self): sdw = SuitTimeWidget(attrs={'placeholder': 'Time'}) output = sdw.render('sdw', '') self.assertHTMLEqual(self.get_SuitTimeWidget_output(), output)