Commits

Steve Losh  committed cbe22f6 Merge

Merge.

  • Participants
  • Parent commits 9d76893, c071339

Comments (0)

Files changed (7)

File docs/usage.rst

 Ensures that this field is not left blank when editing the page in the admin
 interface.
 
+``help_text``
+~~~~~~~~~~~~
+
+Defines help text for individual fields.
+
 Further Usage
 -------------
 

File stoat/admin.py

                     except ValueError:
                         val = True
                 else:
-                    val = pc.content
+                    val = pc.get_content()
 
                 initial['content_' + clean_field_title(pc.title)] = val
 

File stoat/forms.py

 def _get_field(typ, title, options):
     typ = typ.lower()
     required = options.get('required', False)
+    help_text = options.get('help_text')
 
     if typ == 'char':
-        return forms.CharField(max_length=140, label=title, required=required)
+        return forms.CharField(max_length=140, label=title, required=required, help_text=help_text)
 
     if typ == 'text':
-        return forms.CharField(widget=forms.Textarea(), label=title, required=required)
+        return forms.CharField(widget=forms.Textarea(), label=title, required=required, help_text=help_text)
 
     if typ == 'int':
-        return forms.IntegerField(label=title, required=required)
+        return forms.IntegerField(label=title, required=required, help_text=help_text)
 
     if typ == 'url':
-        return forms.URLField(label=title, required=required, verify_exists=False)
+        return forms.URLField(label=title, required=required, verify_exists=False, help_text=help_text)
 
     if typ == 'ckeditor':
         from ckeditor.widgets import CKEditor
 
         config = options.get('config', 'default')
         return forms.CharField(widget=CKEditor(ckeditor_config=config),
-                               label=title, required=required)
+                               label=title, required=required, help_text=help_text)
 
     if typ == 'email':
-        return forms.EmailField(label=title, required=required)
+        return forms.EmailField(label=title, required=required, help_text=help_text)
 
     if typ == 'bool':
-        return forms.BooleanField(label=title, required=required)
+        return forms.BooleanField(label=title, required=required, help_text=help_text)
 
     if typ == 'float':
-        return forms.FloatField(label=title, required=required)
+        return forms.FloatField(label=title, required=required, help_text=help_text)
 
     if typ == 'decimal':
-        return forms.DecimalField(label=title, required=required)
+        return forms.DecimalField(label=title, required=required, help_text=help_text)
 
     if typ == 'img':
         from filebrowser.fields import FileBrowseFormField, FileBrowseWidget
         attrs = { 'directory': '', 'extensions': '', 'format': 'Image', }
 
         return FileBrowseFormField(format='Image', label=title, required=required,
-                                   widget=FileBrowseWidget(attrs=attrs))
+                                   widget=FileBrowseWidget(attrs=attrs), help_text=help_text)
+
+    if typ == 'file':
+        from filebrowser.fields import FileBrowseFormField, FileBrowseWidget
+
+        fmat = options.get('format', 'File')
+        attrs = { 'directory': '', 'extensions': '', 'format': fmat, }
+
+        return FileBrowseFormField(format=fmat, label=title, required=required,
+                                   widget=FileBrowseWidget(attrs=attrs),
+                                   help_text=help_text)
 
     if typ == 'fk':
         app_label = options.get('app', 'stoat')
         model_name = options.get('model', 'Page')
         model = get_model(app_label, model_name)
 
-        return forms.ModelChoiceField(model.objects.all(), label=title, required=required)
+        return forms.ModelChoiceField(model.objects.all(), label=title, required=required, help_text=help_text)
 
     if typ == 'inline':
         return None

File stoat/models.py

     ('text', 'text'),
     ('ckeditor', 'ckeditor'),
     ('img', 'img'),
+    ('file', 'file'),
     ('fk', 'fk'),
     ('int', 'int'),)
 TEMPLATES = sorted([(name, name) for name in settings.STOAT_TEMPLATES.keys()])
     def nav_children(self):
         """Return a list of child Page objects."""
         return list(self.get_children().filter(show_in_nav=True))
-        
+
     def nav_next_sibling(self):
         """ Return the next sibling object, or None if it was the rightmost sibling."""
         siblings = self.nav_siblings()
         for i, sibling in enumerate(siblings):
             if sibling == self and i < len(siblings) - 1:
                 next_sibling = siblings[i+1]
-        return next_sibling   
-        
+        return next_sibling
+
     def nav_prev_sibling(self):
         """ Return the previous sibling object, or None if it was the leftmost sibling."""
         siblings = self.nav_siblings()
         for i, sibling in enumerate(siblings):
             if sibling == self and i > 0:
                 prev_sibling = siblings[i-1]
-        return prev_sibling 
+        return prev_sibling
 
     def nav_siblings_and_children(self):
         """Return a nested list of sibling/children Page objects (including this page)."""
             except ValueError:
                 result = True
             return result
+        elif self.typ in ['file', 'img']:
+            from filebrowser.base import FileObject
+            from django.conf import settings
+            import os
+            return FileObject(os.path.join(settings.MEDIA_ROOT, self.content))
         else:
             return self.content
 

File stoat/search_indexes.py

 
 from models import Page
 
-INDEX_CLASS = getattr(settings, 'STOAT_HAYSTACK_INDEX_CLASS')
+INDEX_CLASS = getattr(settings, 'STOAT_HAYSTACK_INDEX_CLASS', None)
 if INDEX_CLASS:
     module_name, index_name = INDEX_CLASS.rsplit('.', 1)
     module = __import__(module_name, fromlist=[index_name])

File stoat/templates/admin/stoat/page_content.html

                 <div class="column span-flexible">
                     {{ field }}
                     {{ field.errors }}
+                    {% if field.help_text %}
+                        <p class="help">{{ field.help_text }}</p>
+                    {% endif %}
                 </div>
             </div>
         </div>

File stoat/tests/test_navigation.py

         real_sibs = set(['/top-one/one-sub/'])
         test_sibs = set([p.url for p in page.nav_siblings()])
         self.assertTrue(real_sibs == test_sibs)
-        
+
     def test_nav_next_sibling(self):
         page = get(Page, url='/')
         real_sibs = set(['/', '/top-one/', '/top-two/'])
         real_next_sib = '/top-one/'
         self.assertTrue(real_next_sib == page.nav_next_sibling().url)
-        
+
         page = get(Page, url='/top-two/')
         real_next_sib = None
         self.assertTrue(real_next_sib == page.nav_next_sibling())
-        
+
     def test_nav_prev_sibling(self):
         page = get(Page, url='/')
         real_sibs = set(['/', '/top-one/', '/top-two/'])
         real_prev_sib = None
         self.assertTrue(real_prev_sib == page.nav_prev_sibling())
-        
+
         page = get(Page, url='/top-two/')
         real_sibs = set(['/', '/top-one/', '/top-two/'])
         real_prev_sib = '/top-one/'
         real_kids = set(['/top-one/one-sub/one-sub-sub/'])
         test_kids = set([p.url for p in page.nav_children()])
         self.assertTrue(real_kids == test_kids)
-        
+
     def test_nav_siblings_and_children(self):
         def test_siblings(saclist, urllist):
             urls = set([sib.url for sib, children in saclist])