444fa384fab8

Got a working photoblog (almost).
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sat, 14 Feb 2009 12:39:39 -0500
parents a8bf2eea85f7
children 91f05965e207
branches/tags (none)
files photoblog/models.py photoblog/specs.py photoblog/urls.py photoblog/views.py site-media/style/photoblog.css site-media/style/stevelosh.css templates/photoblog/base.html templates/photoblog/entry.html urls.py

Changes

--- a/photoblog/models.py	Sat Feb 14 11:46:36 2009 -0500
+++ b/photoblog/models.py	Sat Feb 14 12:39:39 2009 -0500
@@ -11,6 +11,11 @@
     num_views = models.PositiveIntegerField(editable=False, default=0)
     published = models.BooleanField(default=True)
     
+    @models.permalink
+    def get_absolute_url(self):
+        return ('photoblog-entry', (self.pub_date.year, self.pub_date.month, 
+                                    self.pub_date.day, self.slug),)
+    
     def snippet(self):
         return self.body[:50] + ('...' if len(self.body) > 50 else '')
     
--- a/photoblog/specs.py	Sat Feb 14 11:46:36 2009 -0500
+++ b/photoblog/specs.py	Sat Feb 14 12:39:39 2009 -0500
@@ -1,9 +1,8 @@
 from imagekit.specs import ImageSpec
 from imagekit import processors
 
-class ResizeThumb(processors.Resize): 
-    width = 100
-    height = 100
+class ResizeThumb(processors.Resize):
+    height = 50
 
 class ResizeDisplay(processors.Resize):
     width = 550
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/photoblog/urls.py	Sat Feb 14 12:39:39 2009 -0500
@@ -0,0 +1,6 @@
+from django.conf.urls.defaults import *
+
+urlpatterns = patterns('stevelosh.photoblog.views',
+    url(r'^$',                              'entry', name='photoblog-newest'),
+    url(r'^entry/(\d+)/(\d+)/(\d+)/(.*)/$', 'entry', name='photoblog-entry'),
+)
--- a/photoblog/views.py	Sat Feb 14 11:46:36 2009 -0500
+++ b/photoblog/views.py	Sat Feb 14 12:39:39 2009 -0500
@@ -1,1 +1,11 @@
-# Create your views here.
+from stevelosh.photoblog.models import Entry
+from django.shortcuts import get_object_or_404, render_to_response
+
+def entry(request, year=None, month=None, day=None, slug=None):
+    if year == None and month == None and day == None and slug == None:
+        entry = Entry.objects.all().order_by('-pub_date')[0]
+    else:
+        entry = get_object_or_404(Entry, slug=slug, pub_date__year=year, 
+                                  pub_date__month=month, pub_date__day=day,)
+    
+    return render_to_response('photoblog/entry.html', { 'entry': entry })
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/site-media/style/photoblog.css	Sat Feb 14 12:39:39 2009 -0500
@@ -0,0 +1,7 @@
+img#photoblog-main-image { border: 15px solid #eee; margin: 1em auto 2em; display: block; }
+div#photoblog-entry-date { color: #666; }
+div.photoblog-nav-entry { border-bottom: 1px solid #eee; height: 54px; vertical-align: middle; }
+div.photoblog-nav-entry h2, div.photoblog-nav-entry h3 { line-height: 54px; display: inline; }
+div.photoblog-nav-entry img { float: right; margin: 2px 0px; }
+div#photoblog-nav-older { width: 48%; }
+div#photoblog-nav-newer { width: 48%; float: right; }
\ No newline at end of file
--- a/site-media/style/stevelosh.css	Sat Feb 14 11:46:36 2009 -0500
+++ b/site-media/style/stevelosh.css	Sat Feb 14 12:39:39 2009 -0500
@@ -79,12 +79,13 @@
 	margin-bottom: 0.5em; font-weight: bold; 
 }
 
-h1 a:link, h1 a:visited, h1 a:active, h2 a:link, h2 a:visited, h2 a:active {
+h1 a:link, h1 a:visited, h1 a:active, h2 a:link, h2 a:visited, h2 a:active,
+h3 a:link, h3 a:visited, h3 a:active {
     color: black;
     text-decoration: none;
 }
 
-h1 a:hover, h2 a:hover {
+h1 a:hover, h2 a:hover, h3 a:hover {
     color: #900;
 }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/photoblog/base.html	Sat Feb 14 12:39:39 2009 -0500
@@ -0,0 +1,10 @@
+{% extends "base.html" %}
+
+{% block title %}Photo Blog{% endblock %}
+
+{% block style %}
+	<link rel="stylesheet" href="/site-media/style/photoblog.css" 
+		  type="text/css"/>
+{% endblock %}
+
+{% block header %}/ photo blog{% endblock %}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/photoblog/entry.html	Sat Feb 14 12:39:39 2009 -0500
@@ -0,0 +1,52 @@
+{% extends "photoblog/base.html" %}
+{% load markup %}
+{% load typogrify %}
+
+{% block title %}{{ entry.title }}{% endblock %}
+
+{% block script %}
+{% endblock %}
+
+{% block content %}
+    <div id="photoblog-entry">
+        <h1 id="photoblog-entry-title">
+            <a href="{{ entry.get_absolute_url }}">
+                {{ entry.title|typogrify }}
+            </a>
+        </h1>
+        
+        <img id="photoblog-main-image" src="{{ entry.display.url }}" />
+        
+        <div id="photoblog-entry-body" class="content">
+            {{ entry.body|markdown|typogrify }}
+        </div>
+        
+        <div id="photoblog-entry-date">
+            <p>
+                Posted on {{ entry.pub_date|date:"F j, Y" }}
+            </p>
+        </div>
+        
+        <div id="photoblog-nav">
+            <div id="photoblog-nav-newer">
+                <div class="photoblog-nav-entry">
+                    <h2>Newer</h2>
+                </div>
+                <div class="photoblog-nav-entry">
+                    <a href=""><img src="{{ entry.thumbnail.url }}" /></a>
+                    <h3><a href="">{{ entry.title }}</a></h3>
+                </div>
+            </div>
+            
+            <div id="photoblog-nav-older">
+                <div class="photoblog-nav-entry">
+                    <h2>Older</h2>
+                </div>
+                <div class="photoblog-nav-entry">
+                    <a href=""><img src="{{ entry.thumbnail.url }}" /></a>
+                    <h3><a href="">{{ entry.title }}</a></h3>
+                </div>
+            </div>
+        </div>
+    </div>
+{% endblock %}
\ No newline at end of file
--- a/urls.py	Sat Feb 14 11:46:36 2009 -0500
+++ b/urls.py	Sat Feb 14 12:39:39 2009 -0500
@@ -12,6 +12,7 @@
     url(r'^blog/', include('stevelosh.blog.urls')),
     url(r'^projects/', include('stevelosh.projects.urls')),
     url(r'^thoughts/', include('stevelosh.thoughts.urls')),
+    url(r'^photoblog/', include('stevelosh.photoblog.urls')),
     url(r'^rss/', include('stevelosh.rss.urls')),
 )