import datetime
import re
from django.forms.widgets import Widget, Select
from django.utils.dates import MONTHS
from django.utils.safestring import mark_safe
__all__ = ('MonthYearWidget',)
RE_DATE = re.compile(r'(\d{4})-(\d\d?)-(\d\d?)$')
class MonthYearWidget(Widget):
"""
A Widget that splits date input into two <select> boxes for month and year,
with 'day' defaulting to the first of the month.
Based on SelectDateWidget, in
django/trunk/django/forms/extras/widgets.py
"""
none_value = (0, '---')
month_field = '%s_month'
year_field = '%s_year'
def __init__(self, attrs=None, years=None, required=True):
# years is an optional list/tuple of years to use in the "year" select box.
self.attrs = attrs or {}
self.required = required
if years:
self.years = years
else:
this_year = datetime.date.today().year
self.years = range(this_year, this_year+10)
def render(self, name, value, attrs=None):
try:
year_val, month_val = value.year, value.month
except AttributeError:
year_val = month_val = None
if isinstance(value, basestring):
match = RE_DATE.match(value)
if match:
year_val, month_val, day_val = [int(v) for v in match.groups()]
output = []
if 'id' in self.attrs:
id_ = self.attrs['id']
else:
id_ = 'id_%s' % name
month_choices = MONTHS.items()
if not (self.required and value):
month_choices.append(self.none_value)
month_choices.sort()
local_attrs = self.build_attrs(id=self.month_field % id_)
s = Select(choices=month_choices)
select_html = s.render(self.month_field % name, month_val, local_attrs)
output.append(select_html)
year_choices = [(i, i) for i in self.years]
if not (self.required and value):
year_choices.insert(0, self.none_value)
local_attrs['id'] = self.year_field % id_
s = Select(choices=year_choices)
select_html = s.render(self.year_field % name, year_val, local_attrs)
output.append(select_html)
return mark_safe(u'\n'.join(output))
def id_for_label(self, id_):
return '%s_month' % id_
id_for_label = classmethod(id_for_label)
def value_from_datadict(self, data, files, name):
y = data.get(self.year_field % name)
m = data.get(self.month_field % name)
if y == m == "0":
return None
if y and m:
return '%s-%s-%s' % (y, m, 1)
return data.get(name, None)
Comments
There's a bug in this snippet. Line 56 should read:
And line 65 should read:
Otherwise you get strange behavior when only one of them is filled in.
#
The second last line
will only work if you didn't customize your DATE_FORMAT/DATE_INPUT_FORMATS (the former is usually the first item of the latter, i.e. the "preferred" input format). In order for this to always work, add
at the top, and replace that second last line with:
P.S.: django.utils.formats.localize() is for rendering output, not input, and expects a setting in the format of DATE_FORMAT, i.e. without percentage signs... That's why I'm using time.strptime()
P.P.S.: Theoretically, the int() conversion could be try'd but the widget doesn't allow free text input so I find it ok to leave it out
#
"That's why I'm using time.strptime()" - uhm, make that "date.strftime()" :-)
#
Kesehatan adalah tingkat tips cepat hamil efisiensi fungsional atau metabolik dari makhluk hidup. Pada manusia, itu adalah kondisi umum pikiran dan tubuh seseorang, biasanya berarti bebas dari penyakit, cedera atau sakit (seperti dalam "kesehatan yang baik" atau "sehat") [1] Organisasi Kesehatan Dunia (WHO) didefinisikan. kesehatan dalam arti yang lebih luas pada tahun 1946 sebagai soal ulangan harian sd "keadaan lengkap fisik, mental, dan kesejahteraan sosial dan bukan hanya ketiadaan penyakit atau kelemahan." [2] [3] Meskipun definisi ini telah dikenakan kontroversi, khususnya sebagai kurang nilai operasional dan karena masalah yang diciptakan oleh penggunaan belajar bahasa inggris cepat kata "lengkap", tetap yang paling abadi. [4] [5] definisi lainnya telah diusulkan, di antaranya definisi terbaru yang berkorelasi kesehatan dan kepuasan pribadi. [6] [7] Klasifikasi sistem seperti WHO Keluarga Klasifikasi Internasional, termasuk Klasifikasi teknisi komputer Internasional Berfungsi, cacat, dan kesehatan (ICF) dan Klasifikasi Internasional Penyakit (ICD), biasanya digunakan untuk mendefinisikan dan mengukur komponen kesehatan .
Kegiatan sistematis untuk mencegah atau mengobati masalah kesehatan dan meningkatkan kesehatan pada manusia yang dilakukan oleh penyedia layanan kesehatan. click here Aplikasi yang berkaitan dengan kesehatan hewan dilindungi oleh ilmu kedokteran hewan. Istilah "sehat" juga banyak digunakan dalam konteks berbagai jenis organisasi non-hidup dan dampaknya untuk kepentingan manusia,kursus bahasa inggris online seperti dalam arti masyarakat yang sehat, kota sehat atau lingkungan yang sehat. Selain intervensi perawatan kesehatan dan lingkungan seseorang, sejumlah faktor lain yang diketahui dapat mempengaruhi status kesehatan individu, termasuk latar belakang, gaya hidup, mendapatkan uang dari internet dan kondisi ekonomi dan sosial, ini disebut sebagai "penentu kesehatan".
#