コード例 #1
0
ファイル: fields.py プロジェクト: cy245/TextbookConnect
	def render(self, name, value, attrs=None):
		if value is None: value = ''
		final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
		if value:
			if type(value) != types.StringType:
				# Hope it's datetime.date
				value = value.strftime("%Y-%m-%d")
			final_attrs['value'] = value

		if final_attrs.has_key('calendar'):
			if final_attrs['calendar']:
				return (u"<input%s />"
						" <script language='javascript'>"
						" var inp = document.getElementById('%s');"
						"addCalendar(inp, '%s', 'english', false);"
						"</script>" %(widgets.flatatt(final_attrs), final_attrs['id'],\
									  final_attrs['calendar_class'],))
		return (u"<input%s />" %(widgets.flatatt(final_attrs),))
コード例 #2
0
    def render(self, name, value, attrs=None):
        if value is None: value = ''
        value = smart_unicode(value)
        final_attrs = self.build_attrs(attrs, name=name)

        self.mce_settings['elements'] = "id_%s" % name
        mce_json = JSONEncoder().encode(self.mce_settings)

        return mark_safe(u'<textarea%s>%s</textarea> <script type="text/javascript">\
                tinyMCE.init(%s)</script>' % (flatatt(final_attrs), escape(value), mce_json))
コード例 #3
0
    def render(self, name, value, attrs=None):
        if value is None: value = ''
        value = smart_unicode(value)
        final_attrs = self.build_attrs(attrs, name=name)

        self.mce_settings['elements'] = "id_%s" % name
        mce_json = JSONEncoder().encode(self.mce_settings)

        return mark_safe(
            u'<textarea%s>%s</textarea> <script type="text/javascript">\
                tinyMCE.init(%s)</script>' %
            (flatatt(final_attrs), escape(value), mce_json))
コード例 #4
0
    def render(self, name, value=None, attrs=None):
        final_attrs = self.build_attrs(attrs, name=name)
        if value:
            value = smart_unicode(value)
            final_attrs['value'] = escape(value)
        if not self.attrs.has_key('id'):
            final_attrs['id'] = 'id_%s' % name
        return (u'''<input type="text"%(attrs)s /><div class="autocomplete" id="box_%(name)s"></div>
<script type="text/javascript">new Ajax.Autocompleter('%(id)s', 'box_%(name)s', '%(url)s', %(options)s);</script>'''
        ) % {
            'attrs': flatatt(final_attrs),
            'name': name,
            'id': final_attrs['id'],
            'url': self.url,
            'options': plist_from_dict(self.options)
        }