Author: batiste.bieler
Date: Sun Jun  7 08:23:19 2009
New Revision: 552

Added:
    trunk/example/widgets.py
Modified:
    trunk/example/templates/pages/index.html
    trunk/pages/admin/__init__.py

Log:
Add an example of a custom widget

Modified: trunk/example/templates/pages/index.html
==============================================================================
--- trunk/example/templates/pages/index.html    (original)
+++ trunk/example/templates/pages/index.html    Sun Jun  7 08:23:19 2009
@@ -117,6 +117,9 @@
          <div>body placeholder
              <div id="body" class="placeholder">{% placeholder body on  
current_page with WYMEditor parsed  %}</div>
          </div>
+        <div>
+            {% placeholder custom_widget_example on current_page with  
example.widgets.CustomTextarea parsed  %}
+        </div>
      </div>
      {% endif %}
  {% endblock %}

Added: trunk/example/widgets.py
==============================================================================
--- (empty file)
+++ trunk/example/widgets.py    Sun Jun  7 08:23:19 2009
@@ -0,0 +1,20 @@
+from django.forms import Textarea
+from django.utils.safestring import mark_safe
+from pages.settings import PAGES_MEDIA_URL
+
+class CustomTextarea(Textarea):
+    """class Media:
+        js = ['path to your javascript']
+        css = {
+            'all': ['path to your CSS']
+        }"""
+
+    def __init__(self, attrs=None):
+        attrs = {'class': 'custom-textarea'}
+        super(CustomTextarea, self).__init__(attrs)
+
+    def render(self, name, value, attrs=None):
+        rendered = super(CustomTextarea, self).render(name, value, attrs)
+        return mark_safe("""Take a look at \
+                example.widgets.CustomTextarea<br>""") \
+                + rendered
\ No newline at end of file

Modified: trunk/pages/admin/__init__.py
==============================================================================
--- trunk/pages/admin/__init__.py       (original)
+++ trunk/pages/admin/__init__.py       Sun Jun  7 08:23:19 2009
@@ -215,9 +215,9 @@
              instance.author = request.user
          return instance

-    def get_widget(self, request, name, fallback=Textarea):
+    def get_widget(self, name, fallback=Textarea):
          """
-        Given the request and name of a placeholder return a Widget  
subclass
+        Given the name of a placeholder return a Widget subclass
          like Textarea or TextInput.
          """
          if name and '.' in name:
@@ -280,7 +280,7 @@
                          form.base_fields[field_name].required = False

          for placeholder in get_placeholders(template):
-            widget = self.get_widget(request, placeholder.widget)()
+            widget = self.get_widget(placeholder.widget)()
              if placeholder.parsed:
                  help_text = _('Note: This field is evaluated as template  
code.')
              else:

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pinax-updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/pinax-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to