Merge branch 'release' into develop
authorStephen Burrows <stephen.r.burrows@gmail.com>
Tue, 7 Jun 2011 17:06:09 +0000 (13:06 -0400)
committerStephen Burrows <stephen.r.burrows@gmail.com>
Tue, 7 Jun 2011 17:06:09 +0000 (13:06 -0400)
13 files changed:
docs/contrib/shipherd.rst
docs/tutorials/getting-started.rst
docs/tutorials/intro.rst
docs/tutorials/shipherd.rst [new file with mode: 0644]
philo/admin/nodes.py
philo/contrib/penfield/models.py
philo/contrib/shipherd/templatetags/shipherd.py
philo/migrations/0015_auto__add_unique_node_slug_parent__add_unique_template_slug_parent.py [moved from philo/migrations/0016_auto__add_unique_node_slug_parent__add_unique_template_slug_parent.py with 100% similarity]
philo/migrations/0016_auto__add_field_file_name.py [new file with mode: 0644]
philo/migrations/0017_generate_filenames.py [new file with mode: 0644]
philo/models/base.py
philo/models/nodes.py
philo/utils/entities.py

index 915dac8..7d2eaf7 100644 (file)
@@ -29,6 +29,7 @@ Models
 
 .. automodule:: philo.contrib.shipherd.models
        :members: Navigation, NavigationItem, NavigationMapper
+       :show-inheritance:
 
 Navigation caching
 ------------------
index eeb9ce8..d5d4c71 100644 (file)
@@ -70,18 +70,20 @@ Editing page contents
 Great! We've got a page that says "Hello World". But what if we want it to say something else? Should we really have to edit the :class:`.Template` to change the content of the :class:`.Page`? And what if we want to share the :class:`.Template` but have different content? Adjust the :class:`.Template` to look like this::
        
        <html>
-               <head>
-                       <title>{% container page_title %}</title>
-               </head>
-               <body>
-                       {% container page_body as content %}
-                       {% if content %}
-                               <p>{{ content }}</p>
-                       {% endif %}
-                       <p>The time is {% now %}.</p>
-               </body>
+           <head>
+               <title>{% container page_title %}</title>
+           </head>
+           <body>
+               {% container page_body as content %}
+               {% if content %}
+                   <p>{{ content }}</p>
+               {% endif %}
+               <p>The time is {% now %}.</p>
+           </body>
        </html>
 
 Now go edit your :class:`.Page`. Two new fields called "Page title" and "Page body" have shown up! You can put anything you like in here and have it show up in the appropriate places when the page is rendered.
 
 .. seealso:: :ttag:`philo.templatetags.containers.container`
+
+Congrats! You've done it!
index 903dfea..c7d3e99 100644 (file)
@@ -5,3 +5,4 @@ Tutorials
        :maxdepth: 1
        
        getting-started
+       shipherd
diff --git a/docs/tutorials/shipherd.rst b/docs/tutorials/shipherd.rst
new file mode 100644 (file)
index 0000000..f7988e6
--- /dev/null
@@ -0,0 +1,49 @@
+Using Shipherd in the Admin
+===========================
+
+The navigation mechanism is fairly complex; unfortunately, there's no real way around that - without a lot of equally complex code that you are quite welcome to write and contribute! ;-)
+
+For this guide, we'll assume that you have the setup described in :doc:`getting-started`. We'll be adding a main :class:`.Navigation` to the root :class:`.Node` and making it display as part of the :class:`.Template`.
+
+Creating the Navigation
++++++++++++++++++++++++
+
+Start off by adding a new :class:`.Navigation` instance with :attr:`~.Navigation.node` set to the good ole' ``root`` node and :attr:`~.Navigation.key` set to ``main``. The default :attr:`~.Navigation.depth` of 3 is fine.
+
+Now open up that first inline :class:`.NavigationItem`. Make the text ``Hello World`` and set the target :class:`.Node` to, again, ``root``. (Of course, this is a special case. If we had another node that we wanted to point to, we would choose that.)
+
+Press save and you've created your first navigation.
+
+Displaying the Navigation
++++++++++++++++++++++++++
+
+All you need to do now is show the navigation in the template! This is quite easy, using the :ttag:`~philo.contrib.shipherd.templatetags.shipherd.recursenavigation` templatetag. For now we'll keep it simple. Adjust the "Hello World Template" to look like this::
+       
+       <html>
+           <head>
+               <title>{% container page_title %}</title>
+           </head>
+           <body>
+               <ul>
+                   {% recursenavigation node "main" %}
+                       <li{% if navloop.active %} class="active"{% endif %}>
+                           {{ item.text }}
+                       </li>
+                   {% endnavigation %}
+               </ul>
+               {% container page_body as content %}
+               {% if content %}
+                   <p>{{ content }}</p>
+               {% endif %}
+               <p>The time is {% now %}.</p>
+           </body>
+       </html>
+
+Now have a look at the page - your navigation is there!
+
+Linking to google
++++++++++++++++++
+
+Edit the ``main`` :class:`.Navigation` again to add another :class:`.NavigationItem`. This time give it the :attr:`~.NavigationItem.text` ``Google`` and set the :attr:`~.TargetURLModel.url_or_subpath` field to ``http://google.com``. A navigation item will show up on the Hello World page that points to ``google.com``! Granted, your navigation probably shouldn't do that, because confusing navigation is confusing; the point is that it is possible to provide navigation to arbitrary URLs.
+
+:attr:`~.TargetURLModel.url_or_subpath` can also be used in conjuction with a :class:`.Node` to link to a subpath beyond that :class:`.Node`'s url.
index 853ba25..46c456a 100644 (file)
@@ -47,10 +47,12 @@ class RedirectAdmin(ViewAdmin):
 class FileAdmin(ViewAdmin):
        fieldsets = (
                (None, {
-                       'fields': ('file', 'mimetype')
+                       'fields': ('name', 'file', 'mimetype')
                }),
        )
-       list_display = ('mimetype', 'file')
+       list_display = ('name', 'mimetype', 'file')
+       search_fields = ('name',)
+       list_filter = ('mimetype',)
 
 
 admin.site.register(Node, NodeAdmin)
index bcd0ba4..3632ff6 100644 (file)
@@ -512,8 +512,8 @@ class BlogView(FeedView):
                return {'blog': self.blog}
        
        def get_entry_queryset(self):
-               """Returns the default :class:`QuerySet` of :class:`BlogEntry` instances for the :class:`BlogView`."""
-               return self.blog.entries.all()
+               """Returns the default :class:`QuerySet` of :class:`BlogEntry` instances for the :class:`BlogView` - all entries that are considered posted in the past. This allows for scheduled posting of entries."""
+               return self.blog.entries.filter(date__lte=datetime.now())
        
        def get_tag_queryset(self):
                """Returns the default :class:`QuerySet` of :class:`.Tag`\ s for the :class:`BlogView`'s :meth:`get_entries_by_tag` and :meth:`tag_archive_view`."""
@@ -831,8 +831,8 @@ class NewsletterView(FeedView):
                return {'newsletter': self.newsletter}
        
        def get_article_queryset(self):
-               """Returns the default :class:`QuerySet` of :class:`NewsletterArticle` instances for the :class:`NewsletterView`."""
-               return self.newsletter.articles.all()
+               """Returns the default :class:`QuerySet` of :class:`NewsletterArticle` instances for the :class:`NewsletterView` - all articles that are considered posted in the past. This allows for scheduled posting of articles."""
+               return self.newsletter.articles.filter(date__lte=datetime.now())
        
        def get_issue_queryset(self):
                """Returns the default :class:`QuerySet` of :class:`NewsletterIssue` instances for the :class:`NewsletterView`."""
index 9e572aa..85a0bc5 100644 (file)
@@ -131,7 +131,7 @@ def recursenavigation(parser, token):
                <ul>
                    {% recursenavigation node "main" %}
                        <li{% if navloop.active %} class='active'{% endif %}>
-                           {{ navloop.item.text }}
+                           {{ item.text }}
                            {% if item.get_children %}
                                <ul>
                                    {{ children }}
diff --git a/philo/migrations/0016_auto__add_field_file_name.py b/philo/migrations/0016_auto__add_field_file_name.py
new file mode 100644 (file)
index 0000000..0d8e654
--- /dev/null
@@ -0,0 +1,139 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        
+        # Adding field 'File.name'
+        db.add_column('philo_file', 'name', self.gf('django.db.models.fields.CharField')(default='<Generated name>', max_length=255), keep_default=False)
+
+
+    def backwards(self, orm):
+        
+        # Deleting field 'File.name'
+        db.delete_column('philo_file', 'name')
+
+
+    models = {
+        'contenttypes.contenttype': {
+            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        },
+        'philo.attribute': {
+            'Meta': {'unique_together': "(('key', 'entity_content_type', 'entity_object_id'), ('value_content_type', 'value_object_id'))", 'object_name': 'Attribute'},
+            'entity_content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'attribute_entity_set'", 'to': "orm['contenttypes.ContentType']"}),
+            'entity_object_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
+            'value_content_type': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'attribute_value_set'", 'null': 'True', 'to': "orm['contenttypes.ContentType']"}),
+            'value_object_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'})
+        },
+        'philo.collection': {
+            'Meta': {'object_name': 'Collection'},
+            'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+        },
+        'philo.collectionmember': {
+            'Meta': {'object_name': 'CollectionMember'},
+            'collection': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'members'", 'to': "orm['philo.Collection']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'index': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'member_content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+            'member_object_id': ('django.db.models.fields.PositiveIntegerField', [], {})
+        },
+        'philo.contentlet': {
+            'Meta': {'object_name': 'Contentlet'},
+            'content': ('philo.models.fields.TemplateField', [], {}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
+            'page': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'contentlets'", 'to': "orm['philo.Page']"})
+        },
+        'philo.contentreference': {
+            'Meta': {'object_name': 'ContentReference'},
+            'content_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
+            'page': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'contentreferences'", 'to': "orm['philo.Page']"})
+        },
+        'philo.file': {
+            'Meta': {'object_name': 'File'},
+            'file': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'mimetype': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+        },
+        'philo.foreignkeyvalue': {
+            'Meta': {'object_name': 'ForeignKeyValue'},
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']", 'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'object_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'})
+        },
+        'philo.jsonvalue': {
+            'Meta': {'object_name': 'JSONValue'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'value': ('philo.models.fields.JSONField', [], {'default': "'null'", 'db_index': 'True'})
+        },
+        'philo.manytomanyvalue': {
+            'Meta': {'object_name': 'ManyToManyValue'},
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']", 'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'values': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['philo.ForeignKeyValue']", 'null': 'True', 'blank': 'True'})
+        },
+        'philo.node': {
+            'Meta': {'unique_together': "(('parent', 'slug'),)", 'object_name': 'Node'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+            'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+            'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['philo.Node']"}),
+            'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+            'slug': ('django.db.models.fields.SlugField', [], {'max_length': '255', 'db_index': 'True'}),
+            'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+            'view_content_type': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'node_view_set'", 'null': 'True', 'to': "orm['contenttypes.ContentType']"}),
+            'view_object_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True', 'blank': 'True'})
+        },
+        'philo.page': {
+            'Meta': {'object_name': 'Page'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'template': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'pages'", 'to': "orm['philo.Template']"}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+        },
+        'philo.redirect': {
+            'Meta': {'object_name': 'Redirect'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'reversing_parameters': ('philo.models.fields.JSONField', [], {'blank': 'True'}),
+            'status_code': ('django.db.models.fields.IntegerField', [], {'default': '302'}),
+            'target_node': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'philo_redirect_related'", 'null': 'True', 'to': "orm['philo.Node']"}),
+            'url_or_subpath': ('django.db.models.fields.CharField', [], {'max_length': '200', 'blank': 'True'})
+        },
+        'philo.tag': {
+            'Meta': {'ordering': "('name',)", 'object_name': 'Tag'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '255', 'db_index': 'True'})
+        },
+        'philo.template': {
+            'Meta': {'unique_together': "(('parent', 'slug'),)", 'object_name': 'Template'},
+            'code': ('philo.models.fields.TemplateField', [], {}),
+            'documentation': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+            'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+            'mimetype': ('django.db.models.fields.CharField', [], {'default': "'text/html'", 'max_length': '255'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['philo.Template']"}),
+            'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+            'slug': ('django.db.models.fields.SlugField', [], {'max_length': '255', 'db_index': 'True'}),
+            'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'})
+        }
+    }
+
+    complete_apps = ['philo']
diff --git a/philo/migrations/0017_generate_filenames.py b/philo/migrations/0017_generate_filenames.py
new file mode 100644 (file)
index 0000000..613ac7a
--- /dev/null
@@ -0,0 +1,139 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import DataMigration
+from django.db import models
+
+class Migration(DataMigration):
+
+       def forwards(self, orm):
+               "Write your forwards methods here."
+               for f in orm.File.objects.filter(name="<Generated name>"):
+                       f.name = f.file.name
+                       f.save()
+
+
+       def backwards(self, orm):
+               "Write your backwards methods here."
+               pass
+
+
+       models = {
+               'contenttypes.contenttype': {
+                       'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+                       'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+                       'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+                       'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+                       'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+               },
+               'philo.attribute': {
+                       'Meta': {'unique_together': "(('key', 'entity_content_type', 'entity_object_id'), ('value_content_type', 'value_object_id'))", 'object_name': 'Attribute'},
+                       'entity_content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'attribute_entity_set'", 'to': "orm['contenttypes.ContentType']"}),
+                       'entity_object_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+                       'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+                       'key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
+                       'value_content_type': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'attribute_value_set'", 'null': 'True', 'to': "orm['contenttypes.ContentType']"}),
+                       'value_object_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'})
+               },
+               'philo.collection': {
+                       'Meta': {'object_name': 'Collection'},
+                       'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+                       'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+                       'name': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+               },
+               'philo.collectionmember': {
+                       'Meta': {'object_name': 'CollectionMember'},
+                       'collection': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'members'", 'to': "orm['philo.Collection']"}),
+                       'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+                       'index': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True', 'blank': 'True'}),
+                       'member_content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+                       'member_object_id': ('django.db.models.fields.PositiveIntegerField', [], {})
+               },
+               'philo.contentlet': {
+                       'Meta': {'object_name': 'Contentlet'},
+                       'content': ('philo.models.fields.TemplateField', [], {}),
+                       'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+                       'name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
+                       'page': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'contentlets'", 'to': "orm['philo.Page']"})
+               },
+               'philo.contentreference': {
+                       'Meta': {'object_name': 'ContentReference'},
+                       'content_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True', 'blank': 'True'}),
+                       'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+                       'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+                       'name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
+                       'page': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'contentreferences'", 'to': "orm['philo.Page']"})
+               },
+               'philo.file': {
+                       'Meta': {'object_name': 'File'},
+                       'file': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}),
+                       'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+                       'mimetype': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+                       'name': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+               },
+               'philo.foreignkeyvalue': {
+                       'Meta': {'object_name': 'ForeignKeyValue'},
+                       'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']", 'null': 'True', 'blank': 'True'}),
+                       'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+                       'object_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'})
+               },
+               'philo.jsonvalue': {
+                       'Meta': {'object_name': 'JSONValue'},
+                       'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+                       'value': ('philo.models.fields.JSONField', [], {'default': "'null'", 'db_index': 'True'})
+               },
+               'philo.manytomanyvalue': {
+                       'Meta': {'object_name': 'ManyToManyValue'},
+                       'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']", 'null': 'True', 'blank': 'True'}),
+                       'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+                       'values': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['philo.ForeignKeyValue']", 'null': 'True', 'blank': 'True'})
+               },
+               'philo.node': {
+                       'Meta': {'unique_together': "(('parent', 'slug'),)", 'object_name': 'Node'},
+                       'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+                       'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+                       'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+                       'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['philo.Node']"}),
+                       'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+                       'slug': ('django.db.models.fields.SlugField', [], {'max_length': '255', 'db_index': 'True'}),
+                       'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+                       'view_content_type': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'node_view_set'", 'null': 'True', 'to': "orm['contenttypes.ContentType']"}),
+                       'view_object_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True', 'blank': 'True'})
+               },
+               'philo.page': {
+                       'Meta': {'object_name': 'Page'},
+                       'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+                       'template': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'pages'", 'to': "orm['philo.Template']"}),
+                       'title': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+               },
+               'philo.redirect': {
+                       'Meta': {'object_name': 'Redirect'},
+                       'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+                       'reversing_parameters': ('philo.models.fields.JSONField', [], {'blank': 'True'}),
+                       'status_code': ('django.db.models.fields.IntegerField', [], {'default': '302'}),
+                       'target_node': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'philo_redirect_related'", 'null': 'True', 'to': "orm['philo.Node']"}),
+                       'url_or_subpath': ('django.db.models.fields.CharField', [], {'max_length': '200', 'blank': 'True'})
+               },
+               'philo.tag': {
+                       'Meta': {'ordering': "('name',)", 'object_name': 'Tag'},
+                       'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+                       'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+                       'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '255', 'db_index': 'True'})
+               },
+               'philo.template': {
+                       'Meta': {'unique_together': "(('parent', 'slug'),)", 'object_name': 'Template'},
+                       'code': ('philo.models.fields.TemplateField', [], {}),
+                       'documentation': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+                       'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+                       'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+                       'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+                       'mimetype': ('django.db.models.fields.CharField', [], {'default': "'text/html'", 'max_length': '255'}),
+                       'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+                       'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['philo.Template']"}),
+                       'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+                       'slug': ('django.db.models.fields.SlugField', [], {'max_length': '255', 'db_index': 'True'}),
+                       'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'})
+               }
+       }
+
+       complete_apps = ['philo']
index 86569b7..2f798ae 100644 (file)
@@ -319,7 +319,12 @@ class Entity(models.Model):
                
                """
                return mapper(self)
-       attributes = property(get_attribute_mapper)
+       
+       @property
+       def attributes(self):
+               if not hasattr(self, '_attributes'):
+                       self._attributes = self.get_attribute_mapper()
+               return self._attributes
        
        class Meta:
                abstract = True
@@ -500,7 +505,6 @@ class TreeEntity(Entity, MPTTModel):
                        else:
                                mapper = AttributeMapper
                return super(TreeEntity, self).get_attribute_mapper(mapper)
-       attributes = property(get_attribute_mapper)
        
        def __unicode__(self):
                return self.path
index ab3bca5..5b8b8ed 100644 (file)
@@ -1,4 +1,6 @@
 from inspect import getargspec
+import mimetypes
+from os.path import basename
 
 from django.contrib.contenttypes import generic
 from django.contrib.contenttypes.models import ContentType
@@ -374,23 +376,32 @@ class Redirect(TargetURLModel, View):
 
 class File(View):
        """Stores an arbitrary file."""
-       #: Defines the mimetype of the uploaded file. This will not be validated.
-       mimetype = models.CharField(max_length=255)
+       #: The name of the uploaded file. This is meant for finding the file again later, not for display.
+       name = models.CharField(max_length=255)
+       #: Defines the mimetype of the uploaded file. This will not be validated. If no mimetype is provided, it will be automatically generated based on the filename.
+       mimetype = models.CharField(max_length=255, blank=True)
        #: Contains the uploaded file. Files are uploaded to ``philo/files/%Y/%m/%d``.
        file = models.FileField(upload_to='philo/files/%Y/%m/%d')
        
+       def clean(self):
+               if not self.mimetype:
+                       self.mimetype = mimetypes.guess_type(self.file.name, strict=False)[0]
+                       if self.mimetype is None:
+                               raise ValidationError("Unknown file type.")
+       
        def actually_render_to_response(self, request, extra_context=None):
                wrapper = FileWrapper(self.file)
                response = HttpResponse(wrapper, content_type=self.mimetype)
                response['Content-Length'] = self.file.size
+               response['Content-Disposition'] = "inline; filename=%s" % basename(self.file.name)
                return response
        
        class Meta:
                app_label = 'philo'
        
        def __unicode__(self):
-               """Returns the path of the uploaded file."""
-               return self.file.name
+               """Returns the value of :attr:`File.name`."""
+               return self.name
 
 
 register_value_model(Node)
\ No newline at end of file
index 05e41fc..1ddff05 100644 (file)
@@ -20,8 +20,8 @@ class AttributeMapper(object, DictMixin):
        
        def __getitem__(self, key):
                """Returns the ultimate python value of the :class:`~philo.models.base.Attribute` with the given ``key`` from the cache, populating the cache if necessary."""
-               if not self._cache_populated:
-                       self._populate_cache()
+               if not self._cache_filled:
+                       self._fill_cache()
                return self._cache[key]
        
        def __setitem__(self, key, value):
@@ -53,30 +53,30 @@ class AttributeMapper(object, DictMixin):
        
        def get_attribute(self, key, default=None):
                """Returns the :class:`~philo.models.base.Attribute` instance with the given ``key`` from the cache, populating the cache if necessary, or ``default`` if no such attribute is found."""
-               if not self._cache_populated:
-                       self._populate_cache()
+               if not self._cache_filled:
+                       self._fill_cache()
                return self._attributes_cache.get(key, default)
        
        def keys(self):
                """Returns the keys from the cache, first populating the cache if necessary."""
-               if not self._cache_populated:
-                       self._populate_cache()
+               if not self._cache_filled:
+                       self._fill_cache()
                return self._cache.keys()
        
        def items(self):
                """Returns the items from the cache, first populating the cache if necessary."""
-               if not self._cache_populated:
-                       self._populate_cache()
+               if not self._cache_filled:
+                       self._fill_cache()
                return self._cache.items()
        
        def values(self):
                """Returns the values from the cache, first populating the cache if necessary."""
-               if not self._cache_populated:
-                       self._populate_cache()
+               if not self._cache_filled:
+                       self._fill_cache()
                return self._cache.values()
        
-       def _populate_cache(self):
-               if self._cache_populated:
+       def _fill_cache(self):
+               if self._cache_filled:
                        return
                
                attributes = self.get_attributes()
@@ -92,24 +92,24 @@ class AttributeMapper(object, DictMixin):
                        values_bulk[ct] = ct.model_class().objects.in_bulk(pks)
                
                self._cache.update(dict([(a.key, getattr(values_bulk[a.value_content_type].get(a.value_object_id), 'value', None)) for a in attributes]))
-               self._cache_populated = True
+               self._cache_filled = True
        
        def clear_cache(self):
                """Clears the cache."""
                self._cache = {}
                self._attributes_cache = {}
-               self._cache_populated = False
+               self._cache_filled = False
 
 
 class LazyAttributeMapperMixin(object):
        """In some cases, it may be that only one attribute value needs to be fetched. In this case, it is more efficient to avoid populating the cache whenever possible. This mixin overrides the :meth:`__getitem__` and :meth:`get_attribute` methods to prevent their populating the cache. If the cache has been populated (i.e. through :meth:`keys`, :meth:`values`, etc.), then the value or attribute will simply be returned from the cache."""
        def __getitem__(self, key):
-               if key not in self._cache and not self._cache_populated:
+               if key not in self._cache and not self._cache_filled:
                        self._add_to_cache(key)
                return self._cache[key]
        
        def get_attribute(self, key, default=None):
-               if key not in self._attributes_cache and not self._cache_populated:
+               if key not in self._attributes_cache and not self._cache_filled:
                        self._add_to_cache(key)
                return self._attributes_cache.get(key, default)
        
@@ -175,16 +175,16 @@ class PassthroughAttributeMapper(AttributeMapper):
                self._attributes = [e.attributes for e in entities]
                super(PassthroughAttributeMapper, self).__init__(self._attributes[0].entity)
        
-       def _populate_cache(self):
-               if self._cache_populated:
+       def _fill_cache(self):
+               if self._cache_filled:
                        return
                
                for a in reversed(self._attributes):
-                       a._populate_cache()
+                       a._fill_cache()
                        self._attributes_cache.update(a._attributes_cache)
                        self._cache.update(a._cache)
                
-               self._cache_populated = True
+               self._cache_filled = True
        
        def get_attributes(self):
                raise NotImplementedError