1f2356294a8e

Started the photoblog app.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sat, 14 Feb 2009 11:39:34 -0500
parents 315df6ca542d
children 95340a47d081
branches/tags (none)
files photoblog/__init__.py photoblog/admin.py photoblog/models.py photoblog/specs.py photoblog/views.py settings.py

Changes

--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/photoblog/admin.py	Sat Feb 14 11:39:34 2009 -0500
@@ -0,0 +1,17 @@
+from stevelosh.photoblog.models import Entry
+from django.contrib import admin
+
+class EntryAdmin(admin.ModelAdmin):
+    fieldsets = [
+        ('Entry', { 'fields': ['title', 'original_image', 'body'] }),
+        ('Publishing', { 'fields': ['pub_date', 'published'] }),
+        ('Advanced', { 'fields': ['slug'] }),
+    ]
+    save_on_top = True
+    list_display = ('title', 'snippet', 'num_views', 'pub_date', 'published',)
+    list_filter = ('published',)
+    date_hierarchy = 'pub_date'
+    ordering = ('-pub_date',)
+    prepopulated_fields = { 'slug': ('title',) }
+
+admin.site.register(Entry, EntryAdmin)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/photoblog/models.py	Sat Feb 14 11:39:34 2009 -0500
@@ -0,0 +1,22 @@
+from django.db import models
+from imagekit.models import ImageModel
+import datetime
+
+class Entry(ImageModel):
+    title = models.CharField(max_length=300)
+    slug = models.SlugField()
+    pub_date = models.DateField(default=datetime.datetime.today)
+    body = models.TextField(blank=True)
+    original_image = models.ImageField(upload_to="storage/photoblog/original")
+    num_views = models.PositiveIntegerField(editable=False, default=0)
+    published = models.BooleanField(default=True)
+    
+    def snippet(self):
+        return self.body[:50] + ('...' if len(self.body) > 50 else '')
+    
+    class IKOptions:
+        spec_module = 'photoblog.specs'
+        cache_dir = 'storage/photoblog/cache'
+        image_field = 'original_image'
+        save_count_as = 'num_views'
+    
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/photoblog/specs.py	Sat Feb 14 11:39:34 2009 -0500
@@ -0,0 +1,22 @@
+from imagekit.specs import ImageSpec
+from imagekit import processors
+
+class ResizeThumb(processors.Resize): 
+    width = 100
+    height = 100
+
+class ResizeDisplay(processors.Resize):
+    width = 550
+
+class EnchanceThumb(processors.Adjustment): 
+    contrast = 1.2
+    sharpness = 1.1
+
+class Thumbnail(ImageSpec):
+    access_as = 'thumbnail'
+    pre_cache = True
+    processors = [ResizeThumb, EnchanceThumb]
+
+class Display(ImageSpec):
+    increment_count = True
+    processors = [ResizeDisplay]
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/photoblog/views.py	Sat Feb 14 11:39:34 2009 -0500
@@ -0,0 +1,1 @@
+# Create your views here.
--- a/settings.py	Fri Feb 13 20:40:27 2009 -0500
+++ b/settings.py	Sat Feb 14 11:39:34 2009 -0500
@@ -90,6 +90,8 @@
     'stevelosh.blog',
     'stevelosh.projects',
     'stevelosh.thoughts',
+    'stevelosh.photoblog',
     'mobileadmin',
     'typogrify',
+    'imagekit',
 )