1 3 4 9 19 21 26 28 29 30 31 32 33 34 35 36 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 70 73 74 76 77 78 79 80 85 89 90 91 93 95 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 125 126 129 130 131 135 138 140 144 145 146 148 149 151 153 154 157 158 159 160 161 162 163 165 166 167 172 174 178 179 180 181 182 185 188 189 191 192 194 196 197 200 201 202 203 205 206 207 208 209 210 214 215 217 219 221 222 225 226 227 228 230 231 232 233 234 235 239 240 242 244 245 247 250 251 252 257 259 263 264 265 266 268 270 272 277 281 284 287 288 289 290 293 294 296 298 300 301 302 303 305 307 310 311 313 314 315 316 317 318 319 320 322 323 324 325 326 328 329 330 331 332 333 335 336 337 338 339 340 342 343 345 349 351 354 355 356 357 358 359 361 |
# -*- coding: utf-8 -*- in the admin via a placeholder tag in your template."""
from filebrowser.fields import FileBrowseWidget class FileBrowseInput(FileBrowseWidget): """FileBrowseInput widget."""
def __init__(self, attrs={}): super(FileBrowseInput, self).__init__(attrs) register_widget(FileBrowseInput)
from tagging.models import Tag from django.utils import simplejson
class AutoCompleteTagInput(TextInput): """An autocompete widget""" class Media: js = [join(PAGES_MEDIA_URL, path) for path in ( 'javascript/jquery.js', 'javascript/jquery.bgiframe.min.js', 'javascript/jquery.ajaxQueue.js', 'javascript/jquery.autocomplete.min.js' )]
def __init__(self, language=None, attrs=None, **kwargs): self.language = language super(AutoCompleteTagInput, self).__init__(attrs)
def render(self, name, value, language=None, attrs=None, **kwargs): rendered = super(AutoCompleteTagInput, self).render( name, value, attrs) page_tags = Tag.objects.usage_for_model(Page) context = { 'name': name, 'tags': simplejson.dumps([tag.name for tag in page_tags], ensure_ascii=False), } return rendered + mark_safe(render_to_string( 'pages/widgets/autocompletetaginput.html', context))
register_widget(AutoCompleteTagInput)
"""A RichTextarea widget.""" 'javascript/jquery.js', )] 'all': [join(PAGES_MEDIA_URL, path) for path in ( 'css/rte.css', )] }
'name': name, 'PAGES_MEDIA_URL': PAGES_MEDIA_URL, } 'pages/widgets/richtextarea.html', context))
from tinymce import widgets as tinymce_widgets
class TinyMCE(tinymce_widgets.TinyMCE): """TinyMCE widget.""" def __init__(self, language=None, attrs=None, mce_attrs=None, **kwargs): self.language = language
if mce_attrs is None: mce_attrs = {}
self.mce_attrs = mce_attrs self.mce_attrs.update({ 'mode': "exact", 'theme': "advanced", 'width': 640, 'height': 400, 'theme_advanced_toolbar_location': "top", 'theme_advanced_toolbar_align': "left" }) # take into account the default settings, don't allow # the above hard coded ones overriding them self.mce_attrs.update( getattr(settings, 'TINYMCE_DEFAULT_CONFIG', {})) super(TinyMCE, self).__init__(language, attrs, mce_attrs) register_widget(TinyMCE)
"""CKEditor widget."""
join(settings.MEDIA_URL, 'filebrowser/js/FB_CKEditor.js'), ]
'INSTALLED_APPS', []) self.attrs.update(attrs)
'name': name, 'filebrowser': self.filebrowser, } 'pages/widgets/ckeditor.html', context))
"""WYMEditor widget."""
'javascript/jquery.js', 'javascript/jquery.ui.js', 'javascript/jquery.ui.resizable.js', 'wymeditor/jquery.wymeditor.js', 'wymeditor/plugins/resizable/jquery.wymeditor.resizable.js', )]
js.append(join(PAGES_MEDIA_URL, 'wymeditor/plugins/filebrowser/jquery.wymeditor.filebrowser.js'))
self.attrs.update(attrs)
'name': name, 'lang': self.language[:2], 'language': self.language, 'PAGES_MEDIA_URL': PAGES_MEDIA_URL, }
context['filebrowser'] = 1
'pages/widgets/wymeditor.html', context))
"""markItUpMarkdown widget."""
'javascript/jquery.js', 'markitup/jquery.markitup.js', 'markitup/sets/markdown/set.js', )] 'all': [join(PAGES_MEDIA_URL, path) for path in ( 'markitup/skins/simple/style.css', 'markitup/sets/markdown/style.css', )] }
'name': name, } 'pages/widgets/markitupmarkdown.html', context))
"""markItUpHTML widget."""
'javascript/jquery.js', 'markitup/jquery.markitup.js', 'markitup/sets/default/set.js', )] 'all': [join(PAGES_MEDIA_URL, path) for path in ( 'markitup/skins/simple/style.css', 'markitup/sets/default/style.css', )] }
'name': name, } 'pages/widgets/markituphtml.html', context))
"""EditArea is a html syntax coloured widget.""" 'edit_area/edit_area_full.js', )]
self.attrs.update(attrs)
'name': name, 'language': self.language, 'PAGES_MEDIA_URL': PAGES_MEDIA_URL, } 'pages/widgets/editarea.html', context))
else: field_content += _('Current file: %s<br/>') % value field_content += '''<br><label for="%s-delete">%s</label> <input name="%s-delete" id="%s-delete" type="checkbox" value="true"> ''' % (name, _('Delete image'), name, name)
'''A youtube `Widget` for the admin.''' video_url=None, weight=None, height=None): TextInput(attrs=attrs), TextInput(attrs=attrs), TextInput(attrs=attrs) ]
# backslashes are forbidden in URLs return (None, None, None)
value = [u'', u'', u''] for da in filter(lambda x: x.startswith(name), data): index = int(da[len(name)+1:]) value[index] = data[da] if value[0] == value[1] == value[2] == u'': return None return u'%s\\%s\\%s' % tuple(value)
"""Need to be reimplemented to be correct.""" if data == initial: return False return bool(initial) != bool(data)
""" Given a list of rendered widgets (as strings), it inserts an HTML linebreak between them.
Returns a Unicode string representing the HTML for the whole lot. """ <tr><td>url</td><td>%s</td></tr> <tr><td>width</td><td>%s</td></tr> <tr><td>weight</td><td>%s</td></tr> </table>""" % tuple(rendered_widgets)
# page is None
'name': name, 'value':value, 'page':self.page, 'language': value, 'page_languages':PAGE_LANGUAGES } 'pages/widgets/languages.html', context)) |