Opened 7 years ago

Closed 7 years ago

#6112 closed (duplicate)

SelectDateWidget don't render correctly

Reported by:… Owned by: nobody
Component: Forms Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


SelectDateWidget don't render correctly

Attachments (4)

selectdate.diff (614 bytes) - added by terryh 7 years ago.
selectdate_right.diff (776 bytes) - added by anonymous 7 years ago.
SelectDate_datetime.patch (819 bytes) - added by Martin Conte Mac Donell <Reflejo@…> 7 years ago.
This is IMHO a better way to do that
SelectDate_datetime.3.patch (825 bytes) - added by Martin Conte Mac Donell <Reflejo@…> 7 years ago.
This is IMHO a better way to do that (Err.. Sorry for the other one)

Download all attachments as: .zip

Change History (11)

Changed 7 years ago by terryh

Changed 7 years ago by anonymous

comment:1 Changed 7 years ago by Martin Conte Mac Donell <Reflejo@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

I don't see why you are forcing unicode to datetime values.

comment:2 Changed 7 years ago by terryh

The "value" from instance, then the "value" is instance.
The "value" from request.POST, then the "value" is unicode string.

force_unicode just make sure the "value". make it render correctly, no matter where it come from.

comment:3 Changed 7 years ago by Martin Conte Mac Donell <Reflejo@…>

Actually if you are using SelectDateWidget it's suppose to have only numbers (represented as string; but just numbers) from request.POST. I mean, value_from_datadict is returning '%s-%s-%s' % (y, m, d). And those y m and d MUST be numbers to create

I'm still not seeing where is the unicode chance here.

comment:4 Changed 7 years ago by terryh

the following alwayse asume "value" is string

33 def render(self, name, value, attrs=None):
34 try:
35 value =*map(int, value.split('-')))

But if there is no y, and m and d, will return, if you try form_for_instance, then render it, you will see, just in my case, maybe I'm wrong

57 def value_from_datadict(self, data, files, name):
58 y, m, d = data.get(self.year_field % name), data.get(self.month_field % name), data.get(self.day_field % name)
59 if y and m and d:
60 return '%s-%s-%s' % (y, m, d)
61 return data.get(name, None)

comment:5 Changed 7 years ago by Martin Conte Mac Donell <Reflejo@…>

Just to be clean here.

What "don't render correctly" means?. What did you see?

comment:6 Changed 7 years ago by terryh

with this patch

IPython 0.8.1 -- An enhanced Interactive Python.
?       -> Introduction to IPython's features.
%magic  -> Information about IPython's 'magic' % functions.
help    -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

In [1]: from django.newforms import extras

In [2]: from django import newforms

In [3]: import datetime

In [4]: w = extras.SelectDateWidget()

In [5]: from BeautifulSoup import BeautifulSoup

In [6]: BeautifulSoup(w.render('birthday',
<select name="birthday_month">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12" selected="selected">December</option>
<select name="birthday_day">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6" selected="selected">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
<select name="birthday_year">
<option value="2007" selected="selected">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option value="2010">2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>

without this patch, this widget select nothing

Changed 7 years ago by Martin Conte Mac Donell <Reflejo@…>

This is IMHO a better way to do that

comment:7 Changed 7 years ago by Martin Conte Mac Donell <Reflejo@…>

  • Resolution set to duplicate
  • Status changed from new to closed

You don't need to force unicode here, you should ask if the comming value is a String (unicode or str) or datetime.

(Duplicate of #5917?)

Changed 7 years ago by Martin Conte Mac Donell <Reflejo@…>

This is IMHO a better way to do that (Err.. Sorry for the other one)

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.