Restructure cookbook directories and use Grappelli for the admin interface.
authorW. Trevor King <wking@drexel.edu>
Fri, 5 Aug 2011 16:11:46 +0000 (12:11 -0400)
committerW. Trevor King <wking@drexel.edu>
Fri, 5 Aug 2011 16:19:48 +0000 (12:19 -0400)
Moving the static and template directories into the python modules
makes it easy for Django to find them using its built-in finders:
  django.contrib.staticfiles.finders.AppDirectoriesFinder
  django.template.loaders.app_directories.Loader

This means that people using cookbook will not need to shift these
files around on their own, or adjust their settings.py file to do more
than add 'cookbook' to their INSTALLED_APPS.

Grappelli is makes it very easy to add drag-and-drop sorting for
Ingredient and IngredientBlock fields, which I also put in in this
commit.

13 files changed:
README
cookbook/admin.py
cookbook/models.py
cookbook/static/cookbook/cookbook.ico [moved from example/data/static/cookbook.ico with 100% similarity]
cookbook/static/cookbook/style.css [moved from example/data/static/style.css with 100% similarity]
cookbook/templates/admin/edit_inline/tabular.html [moved from example/data/template/admin/edit_inline/tabular.html with 100% similarity]
cookbook/templates/cookbook/base.html [moved from example/data/template/cookbook/base.html with 100% similarity]
cookbook/templates/cookbook/recipe.html [moved from example/data/template/cookbook/recipe.html with 100% similarity]
cookbook/templates/cookbook/recipes.html [moved from example/data/template/cookbook/recipes.html with 100% similarity]
cookbook/templates/cookbook/tags.html [moved from example/data/template/cookbook/tags.html with 100% similarity]
cookbook/urls.py
example/data/static/.gitignore [new file with mode: 0644]
example/settings.py

diff --git a/README b/README
index e07153884528c47f8af5c0cfe3a39ea1c1dd56e0..5d723f24c1fc8b617fa81e730ea6a3556913ddb8 100644 (file)
--- a/README
+++ b/README
@@ -16,7 +16,7 @@ Dependencies
 ------------
 
 Outside of Django_ and the Python_ standard libraries, the only
-required dependencies are `django-taggit`_ (docs__) and
+required dependencies are Grappelli_, `django-taggit`_ (docs__) and
 `python-markdown`_.
 
 __ dt2-docs_
@@ -28,6 +28,7 @@ If you don't have a Django project and you just want to run cookbook as
 a stand-alone service, you can use the example project written up in
 `example`.  Set up the project (once)::
 
+  $ python example/manage.py collectstatic
   $ python example/manage.py syncdb
 
 See the `Django documentation`_ for more details.
@@ -55,6 +56,7 @@ That's a good place to start if you're new to Django.
 .. _Django: https://www.djangoproject.com/
 .. _Git: http://git-scm.com/
 .. _cookbook: http://physics.drexel.edu/~wking/code/git/gitweb.cgi?p=cookbook.git
+.. _Grappelli: https://github.com/sehmaschine/django-grappelli
 .. _django-taggit: https://github.com/alex/django-taggit
 .. _dt2-docs: http://django-taggit.readthedocs.org/en/latest/
 .. _python-markdown: http://pypi.python.org/pypi/Markdown
index fa29c02d4f4cbc75f797337eefd9c533bab6ec33..4515bd831155064ff70e409bfda0f2e8f4baf958 100644 (file)
@@ -2,14 +2,14 @@ from django import forms
 from django.contrib import admin
 from django.db import models as django_models
 
-import models
+from . import models
 
 
 class IngredientInline (admin.TabularInline):
     model = models.Ingredient
+    sortable_field_name = 'position'
     extra = 0
 
-
 class IngredientBlockAdmin (admin.ModelAdmin):
     fieldsets = [
         (None, {'fields': ['name']}),
@@ -25,10 +25,10 @@ class IngredientBlockAdmin (admin.ModelAdmin):
 class IngredientBlockInline (admin.TabularInline):
     model = models.IngredientBlock
     fieldsets = [
-        (None, {'fields': ['name']}),
+        (None, {'fields': ['name', 'position']}),
         ]
+    sortable_field_name = 'position'
     inlines = [IngredientInline]
-
     list_display = ['name']
     extra = 0
     show_edit_link = True  # https://code.djangoproject.com/ticket/13163
index cfad7b588687259b968cc7ad87530502b5fdb41a..f32eb9e2432dd77b51615c4e6921996c8f5ad47a 100644 (file)
@@ -129,9 +129,10 @@ class Recipe (Amount, Directions):
 class IngredientBlock (Directions):
     name = models.CharField(max_length=200)
     recipe = models.ForeignKey(Recipe)
+    position = models.PositiveIntegerField()
 
     class Meta:
-        ordering = ['recipe', 'name']
+        ordering = ['recipe', 'position']
 
     def __unicode__(self):
         return u'{0.name}'.format(self)
@@ -142,6 +143,10 @@ class Ingredient (Amount):
     name = models.CharField(max_length=200)
     note = models.CharField(max_length=200, null=True, blank=True)
     block = models.ForeignKey(IngredientBlock)
+    position = models.PositiveIntegerField()
+
+    class Meta:
+        ordering = ['block', 'position']
 
     def __unicode__(self):
         fmt = '{i.name}'
index 2c5bf64456e68f777f2f6a68e39a53e51525056e..c242268658fc548c2deaf822852dc7d44dd30b9f 100644 (file)
@@ -35,6 +35,7 @@ urlpatterns = patterns('',
 
     # Uncomment the next line to enable the admin:
     url(r'^admin/', include(admin.site.urls), name='admin'),
+    url(r'^grappelli/', include('grappelli.urls'), name='admin'),
 
     url(r'^favicon\.ico$', 'django.views.generic.simple.redirect_to',
         kwargs={'url': settings.STATIC_URL + 'cookbook.ico'}),
diff --git a/example/data/static/.gitignore b/example/data/static/.gitignore
new file mode 100644 (file)
index 0000000..72e8ffc
--- /dev/null
@@ -0,0 +1 @@
+*
index b253e12f843d6b72f6ff94438afd8928a9aaa43b..49d2f64e49d43b2ba70704354a08df35fb3d83ee 100644 (file)
@@ -69,7 +69,7 @@ MEDIA_URL = '/media/'
 # Don't put anything in this directory yourself; store your static files
 # in apps' "static/" subdirectories and in STATICFILES_DIRS.
 # Example: "/home/media/media.lawrence.com/static/"
-STATIC_ROOT = ''
+STATIC_ROOT = os.path.join(DATA_DIRECTORY, 'static')
 
 # URL prefix for static files.
 # Example: "http://media.lawrence.com/static/"
@@ -78,15 +78,14 @@ STATIC_URL = '/static/'
 # URL prefix for admin static files -- CSS, JavaScript and images.
 # Make sure to use a trailing slash.
 # Examples: "http://foo.com/static/admin/", "/static/admin/".
-ADMIN_MEDIA_PREFIX = '/static/admin/'
+#ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'
+ADMIN_MEDIA_PREFIX = STATIC_URL + 'grappelli/'
 
 # Additional locations of static files
 STATICFILES_DIRS = (
     # Put strings here, like "/home/html/static" or "C:/www/django/static".
     # Always use forward slashes, even on Windows.
     # Don't forget to use absolute paths, not relative paths.
-    os.path.join(DATA_DIRECTORY, 'media'),
-    os.path.join(DATA_DIRECTORY, 'static'),
 )
 
 # List of finder classes that know how to find static files in
@@ -121,7 +120,6 @@ TEMPLATE_DIRS = (
     # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
     # Always use forward slashes, even on Windows.
     # Don't forget to use absolute paths, not relative paths.
-    os.path.join(DATA_DIRECTORY, 'template'),
 )
 
 INSTALLED_APPS = (
@@ -132,6 +130,7 @@ INSTALLED_APPS = (
     'django.contrib.messages',
     'django.contrib.staticfiles',
     # Uncomment the next line to enable the admin:
+    'grappelli',
     'django.contrib.admin',
     # Uncomment the next line to enable admin documentation:
     # 'django.contrib.admindocs',