Replace helpers/custom_widgets.py with helper/widgets.py.
authorTodd Larsen <tlarsen@google.com>
Fri, 03 Oct 2008 23:08:28 +0000
changeset 271 01e90bb21b7e
parent 270 7dd6d8347b56
child 272 00cea07656c0
Replace helpers/custom_widgets.py with helper/widgets.py. Patch by: Todd Larsen Review by: to-be-reviewed
app/soc/views/helper/widgets.py
app/soc/views/helpers/custom_widgets.py
app/soc/views/site/docs/edit.py
app/soc/views/site/home.py
app/soc/views/site/sponsor/profile.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/views/helper/widgets.py	Fri Oct 03 23:08:28 2008 +0000
@@ -0,0 +1,92 @@
+#!/usr/bin/python2.5
+#
+# Copyright 2008 the Melange authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Custom widgets used for form fields.
+"""
+
+__authors__ = [
+  '"Pawel Solyga" <pawel.solyga@gmail.com>',
+  ]
+
+
+import copy
+
+from django import newforms as forms
+from django.newforms import util
+from django.newforms import widgets
+from django.utils import html
+from django.utils import simplejson
+from django.utils import safestring
+
+
+class ReadOnlyInput(forms.widgets.Input):
+  """Read only input widget.
+  """
+  input_type = 'text'
+
+  def render(self, name, value, attrs=None):
+    """Render ReadOnlyInput widget as HTML.
+    """
+    attrs['readonly'] = 'readonly'
+    return super(ReadOnlyInput, self).render(name, value, attrs)
+
+
+class TinyMCE(forms.widgets.Textarea):
+  """TinyMCE widget. 
+  
+  Requires to include tiny_mce_src.js in your template. Widget can be
+  customized by overwriting or adding extra options to mce_settings
+  dictionary
+
+  You can set TinyMCE widget for particular form field using code below:
+    class ExampleForm(forms_helpers.DbModelForm):
+      content = forms.fields.CharField(widget=helper.widgets.TinyMCE())
+  
+  You can include tiny_mce_src.js in your template using:
+    {% block scripts %}
+  	  <script type="text/javascript" src="/tiny_mce/tiny_mce_src.js"></script>
+    {% endblock %}
+  """ 
+  DEF_MCE_SETTINGS = { 'mode': "exact",
+                       'theme': "simple",
+                       'theme_advanced_toolbar_location': "top",
+                       'theme_advanced_toolbar_align': "center"}
+
+  mce_settings = DEF_MCE_SETTINGS.copy()
+
+  TINY_MCE_HTML_FMT = u'''\
+<textarea %(attrs)s>%(value)s</textarea>
+<script type="text/javascript">
+tinyMCE.init(%(settings_json)s)
+</script>'''
+  
+  def render(self, name, value, attrs=None):
+    """Render TinyMCE widget as HTML.
+    """
+    if value is None:
+      value = ''
+    value = util.smart_unicode(value)
+    final_attrs = self.build_attrs(attrs, name=name)
+    
+    self.mce_settings['elements'] = "id_%s" % name
+      
+    # convert mce_settings from dict to JSON
+    mce_json = simplejson.JSONEncoder().encode(self.mce_settings)
+
+    return safestring.mark_safe(self.TINY_MCE_HTML_FMT % 
+        {'attrs': widgets.flatatt(final_attrs),
+         'value': html.escape(value), 
+         'settings_json':  mce_json})
--- a/app/soc/views/helpers/custom_widgets.py	Fri Oct 03 23:01:49 2008 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,92 +0,0 @@
-#!/usr/bin/python2.5
-#
-# Copyright 2008 the Melange authors.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""Custom widgets used for form fields.
-"""
-
-__authors__ = [
-  '"Pawel Solyga" <pawel.solyga@gmail.com>',
-  ]
-
-
-import copy
-
-from django import newforms as forms
-from django.newforms import util
-from django.newforms import widgets
-from django.utils import html
-from django.utils import simplejson
-from django.utils import safestring
-
-
-class ReadOnlyInput(forms.widgets.Input):
-  """Read only input widget.
-  """
-  input_type = 'text'
-
-  def render(self, name, value, attrs=None):
-    """Render ReadOnlyInput widget as HTML.
-    """
-    attrs['readonly'] = 'readonly'
-    return super(ReadOnlyInput, self).render(name, value, attrs)
-
-
-class TinyMCE(forms.widgets.Textarea):
-  """TinyMCE widget. 
-  
-  Requires to include tiny_mce_src.js in your template. Widget can be
-  customized by overwriting or adding extra options to mce_settings
-  dictionary
-
-  You can set TinyMCE widget for particular form field using code below:
-    class ExampleForm(forms_helpers.DbModelForm):
-      content = forms.fields.CharField(widget=custom_widgets.TinyMCE())
-  
-  You can include tiny_mce_src.js in your template using:
-    {% block scripts %}
-  	  <script type="text/javascript" src="/tiny_mce/tiny_mce_src.js"></script>
-    {% endblock %}
-  """ 
-  DEF_MCE_SETTINGS = { 'mode': "exact",
-                       'theme': "simple",
-                       'theme_advanced_toolbar_location': "top",
-                       'theme_advanced_toolbar_align': "center"}
-
-  mce_settings = DEF_MCE_SETTINGS.copy()
-
-  TINY_MCE_HTML_FMT = u'''\
-<textarea %(attrs)s>%(value)s</textarea>
-<script type="text/javascript">
-tinyMCE.init(%(settings_json)s)
-</script>'''
-  
-  def render(self, name, value, attrs=None):
-    """Render TinyMCE widget as HTML.
-    """
-    if value is None:
-      value = ''
-    value = util.smart_unicode(value)
-    final_attrs = self.build_attrs(attrs, name=name)
-    
-    self.mce_settings['elements'] = "id_%s" % name
-      
-    # convert mce_settings from dict to JSON
-    mce_json = simplejson.JSONEncoder().encode(self.mce_settings)
-
-    return safestring.mark_safe(self.TINY_MCE_HTML_FMT % 
-        {'attrs': widgets.flatatt(final_attrs),
-         'value': html.escape(value), 
-         'settings_json':  mce_json})
--- a/app/soc/views/site/docs/edit.py	Fri Oct 03 23:01:49 2008 +0000
+++ b/app/soc/views/site/docs/edit.py	Fri Oct 03 23:08:28 2008 +0000
@@ -34,8 +34,8 @@
 from soc.logic.site import id_user
 from soc.views import helper
 import soc.views.helper.requests
+import soc.views.helper.widgets
 from soc.views import simple
-from soc.views.helpers import custom_widgets
 from soc.views.helpers import forms_helpers
 from soc.views.helpers import response_helpers
 from soc.views.user import profile
@@ -47,7 +47,7 @@
   """Django form displayed when Developer edits a Document.
   """
   doc_key_name = forms.CharField(widget=forms.HiddenInput)
-  content = forms.fields.CharField(widget=custom_widgets.TinyMCE())
+  content = forms.fields.CharField(widget=helper.widgets.TinyMCE())
   
   class Meta:
     model = soc.models.document.Document
@@ -206,7 +206,7 @@
   """Django form displayed when Developer creates a Document.
   """
   doc_key_name = forms.CharField(widget=forms.HiddenInput)
-  content = forms.fields.CharField(widget=custom_widgets.TinyMCE())
+  content = forms.fields.CharField(widget=helper.widgets.TinyMCE())
   
   class Meta:
     model = soc.models.document.Document
--- a/app/soc/views/site/home.py	Fri Oct 03 23:01:49 2008 +0000
+++ b/app/soc/views/site/home.py	Fri Oct 03 23:08:28 2008 +0000
@@ -39,7 +39,7 @@
 from soc.views import simple
 from soc.views import helper
 import soc.views.helper.templates
-from soc.views.helpers import custom_widgets
+import soc.views.helper.widgets
 from soc.views.helpers import forms_helpers
 from soc.views.helpers import response_helpers
 
@@ -50,9 +50,8 @@
 
 
 class DocumentForm(forms_helpers.DbModelForm):
-  content = forms.fields.CharField(widget=custom_widgets.TinyMCE())
-  #link_name = forms.CharField(widget=forms.TextInput(
-  #                                attrs={'readonly':'true'}))
+  content = forms.fields.CharField(widget=helper.widgets.TinyMCE())
+
   class Meta:
     """Inner Meta class that defines some behavior for the form.
     """
--- a/app/soc/views/site/sponsor/profile.py	Fri Oct 03 23:01:49 2008 +0000
+++ b/app/soc/views/site/sponsor/profile.py	Fri Oct 03 23:08:28 2008 +0000
@@ -33,8 +33,8 @@
 from soc.logic.site import id_user
 from soc.views import helper
 import soc.views.helper.requests
+import soc.views.helper.widgets
 from soc.views import simple
-from soc.views.helpers import custom_widgets
 from soc.views.helpers import forms_helpers
 from soc.views.helpers import response_helpers
 from soc.views.user import profile
@@ -67,7 +67,7 @@
 class EditForm(CreateForm):
   """Django form displayed when editing a Sponsor.
   """
-  link_name = forms.CharField(widget=custom_widgets.ReadOnlyInput())
+  link_name = forms.CharField(widget=helper.widgets.ReadOnlyInput())
 
   def clean_link_name(self):
     link_name = self.cleaned_data.get('link_name')