8 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
9 """ |
9 """ |
10 __docformat__ = "restructuredtext en" |
10 __docformat__ = "restructuredtext en" |
11 |
11 |
12 from simplejson import dumps |
12 from simplejson import dumps |
13 from mx.DateTime import now, today |
13 from datetime import datetime |
14 |
14 |
15 from logilab.mtconverter import html_escape |
15 from logilab.mtconverter import html_escape |
16 |
16 |
17 from yams.constraints import SizeConstraint, StaticVocabularyConstraint |
17 from yams.constraints import SizeConstraint, StaticVocabularyConstraint |
18 |
18 |
733 return [values[0].strftime(formatstr)] |
733 return [values[0].strftime(formatstr)] |
734 return values |
734 return values |
735 |
735 |
736 def render_example(self, req): |
736 def render_example(self, req): |
737 formatstr = req.property_value(self.format_key) |
737 formatstr = req.property_value(self.format_key) |
738 return now().strftime(formatstr) |
738 return datetime.now().strftime(formatstr) |
739 |
739 |
740 |
740 |
741 def _edit_render(self, entity): |
741 def _edit_render(self, entity): |
742 wdg = super(DateWidget, self)._edit_render(entity) |
742 wdg = super(DateWidget, self)._edit_render(entity) |
743 cal_button = self.render_calendar_popup(entity) |
743 cal_button = self.render_calendar_popup(entity) |
762 self.add_localized_infos(req) |
762 self.add_localized_infos(req) |
763 req.add_js(('cubicweb.ajax.js', 'cubicweb.calendar.js',)) |
763 req.add_js(('cubicweb.ajax.js', 'cubicweb.calendar.js',)) |
764 req.add_css(('cubicweb.calendar_popup.css',)) |
764 req.add_css(('cubicweb.calendar_popup.css',)) |
765 inputid = self.attrs.get('id', self.rname) |
765 inputid = self.attrs.get('id', self.rname) |
766 helperid = "%shelper" % inputid |
766 helperid = "%shelper" % inputid |
767 _today = today() |
767 _today = datetime.now() |
768 year = int(req.form.get('year', _today.year)) |
768 year = int(req.form.get('year', _today.year)) |
769 month = int(req.form.get('month', _today.month)) |
769 month = int(req.form.get('month', _today.month)) |
770 |
770 |
771 return (u"""<a onclick="toggleCalendar('%s', '%s', %s, %s);" class="calhelper"> |
771 return (u"""<a onclick="toggleCalendar('%s', '%s', %s, %s);" class="calhelper"> |
772 <img src="%s" title="%s" alt="" /></a><div class="calpopup hidden" id="%s"></div>""" |
772 <img src="%s" title="%s" alt="" /></a><div class="calpopup hidden" id="%s"></div>""" |
783 |
783 |
784 def render_example(self, req): |
784 def render_example(self, req): |
785 formatstr1 = req.property_value('ui.datetime-format') |
785 formatstr1 = req.property_value('ui.datetime-format') |
786 formatstr2 = req.property_value('ui.date-format') |
786 formatstr2 = req.property_value('ui.date-format') |
787 return req._('%(fmt1)s, or without time: %(fmt2)s') % { |
787 return req._('%(fmt1)s, or without time: %(fmt2)s') % { |
788 'fmt1': now().strftime(formatstr1), |
788 'fmt1': datetime.now().strftime(formatstr1), |
789 'fmt2': now().strftime(formatstr2), |
789 'fmt2': datetime.now().strftime(formatstr2), |
790 } |
790 } |
791 |
791 |
792 |
792 |
793 class TimeWidget(StringWidget): |
793 class TimeWidget(StringWidget): |
794 format_key = 'ui.time-format' |
794 format_key = 'ui.time-format' |