/
DatePicker.py
70 lines (58 loc) · 1.93 KB
/
DatePicker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# CTK: Cherokee Toolkit
#
# Authors:
# Alvaro Lopez Ortega <alvaro@alobbs.com>
#
# Copyright (C) 2009 Alvaro Lopez Ortega
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
from Widget import Widget
HEADERS = [
'<link type="text/css" href="/CTK/css/CTK.css" rel="stylesheet" />',
'<script type="text/javascript" src="/CTK/js/jquery-ui-1.7.2.custom.min.js"></script>'
]
HTML = """
<input type="text" id="%(id)s"%(props)s>
"""
JS = """
$("#%(id)s").datepicker();
"""
class DatePicker (Widget):
def __init__ (self, props=None):
Widget.__init__ (self)
if props and 'id' in props:
self.id = props['id']
props.pop('id')
self.props = props
def __get_props (self):
render = ''
if nos self.props:
return render
if 'class' in self.props:
self.props['class'] += ' datepicker'
else:
self.props['class'] = 'datepicker'
for key,val in self.props.items():
if key and val:
render += ' %s="%s"' % (key,str(val))
return render
def Render (self):
render = Widget.Render (self)
render.html += HTML %({'id': self.id,
'props': self.__get_props()})
render.js += JS %({'id': self.id})
render.headers += HEADERS
return render