Commits

Steve Losh  committed 443fbbf

Started pulling out URLs, and also doing some cleanup.

  • Participants
  • Parent commits 7167996

Comments (0)

Files changed (7)

File blog/models.py

     author = models.ForeignKey(User)
     published = models.BooleanField(default=False)
     
+    @models.permalink
     def get_absolute_url(self):
-        return "/blog/entry/%i/%i/%i/%s/" % (self.pub_date.year, 
-            self.pub_date.month, self.pub_date.day, self.slug)
+        return ('blog-entry', (self.pub_date.year, self.pub_date.month, 
+                               self.pub_date.day, self.slug),)
     
     def __unicode__(self):
         return u'%s' % (self.title,)

File blog/urls.py

+from django.conf.urls.defaults import *
+
+urlpatterns = patterns('lindyjam.blog.views',
+    url(r'^$',                             'index',   name='blog-list'),
+    url(r'^page/(\d+)/$',                  'index',   name='blog-list-page'),
+    url(r'^entry/(\d+)/(\d+)/(\d+)/(.*)/$', 'entry',   name='blog-entry'),
+    url(r'^comment/$',                      'comment', name='blog-comment'),
+)

File templates/blog/entry.html

 {% block title %}Blog - {{ entry.title }}{% endblock %}
 
 {% block style %}
-	<link rel="stylesheet" type="text/css" href="/site-media/styles/blogstyle.css"/>
+    <link rel="stylesheet" type="text/css" href="/site-media/styles/blogstyle.css"/>
 {% endblock %}
 
 {% block scripts %}
-	<script type="text/javascript"
-	 		src="/site-media/scripts/blog_entry.js"></script>
+    <script type="text/javascript"
+            src="/site-media/scripts/blog_entry.js"></script>
 {% endblock %}
 
 {% block content %}
-	{% url lindyjam.blog.views.entry entry.pub_date.year, entry.pub_date.month, entry.pub_date.day, entry.slug as permalink %}
-	{% include "blog/single_entry.html" %}
-	<a name="comments"></a>
-	<h2 id="blog_comments_header">Comments</h2>
-	{% include "blog/entry_comments.html" %}
-	<h2 id="blog_new_comment_header">Say Something</h2>
-	<div id="blog_message"></div>
-	<form id="blog_new_comment_form" action="">
-		<div id="blog_new_comment">
-			<input type="hidden" name="entry_id" id="blog_entry_id" 
-				   value="{{ entry.id }}" />
-			<input id="blog_comment_name" class="input_text with-instructions"
-			 	   name="name" type="text" 
-				   title="Who are you?" />
-			<textarea id="blog_comment_body" 
-					  rows="" cols=""
-				      class="input_text with-instructions" name="body"
-				      title="What do you want to say?"></textarea>
-			<input id="blog_comment_submit" class="input_submit"
-			 	   name="submit" type="submit" value="Comment" />
-			<div id="blog_body_instructions">
-				You can use <a href="http://daringfireball.net/projects/markdown/syntax">Markdown</a> when writing your comment.  That means you can do things like *<em>italics</em>*, **<strong>bold</strong>**, and [<a href="">links to stuff</a>](http://lindyjam.com/) and they'll show up when you post it.  <strong>Don't</strong> use HTML.
-			</div>
-		</div>
-	</form>
+    {% include "blog/single_entry.html" %}
+    <a name="comments"></a>
+    <h2 id="blog_comments_header">Comments</h2>
+    {% include "blog/entry_comments.html" %}
+    <h2 id="blog_new_comment_header">Say Something</h2>
+    <div id="blog_message"></div>
+    <form id="blog_new_comment_form" action="">
+        <div id="blog_new_comment">
+            <input type="hidden" name="entry_id" id="blog_entry_id" 
+                   value="{{ entry.id }}" />
+            <input id="blog_comment_name" class="input_text with-instructions"
+                   name="name" type="text" 
+                   title="Who are you?" />
+            <textarea id="blog_comment_body" 
+                      rows="" cols=""
+                      class="input_text with-instructions" name="body"
+                      title="What do you want to say?"></textarea>
+            <input id="blog_comment_submit" class="input_submit"
+                   name="submit" type="submit" value="Comment" />
+            <div id="blog_body_instructions">
+                You can use <a href="http://daringfireball.net/projects/markdown/syntax">Markdown</a> when writing your comment.  That means you can do things like *<em>italics</em>*, **<strong>bold</strong>**, and [<a href="">links to stuff</a>](http://lindyjam.com/) and they'll show up when you post it.  <strong>Don't</strong> use HTML.
+            </div>
+        </div>
+    </form>
 {% endblock %}

File templates/blog/entry_footer.html

-				<div class="blog_footer">
-					<hr class="blog_footer_hr"/>
-					<a class="blog_permalink" 
-					   href="{{ permalink }}">Permanent Link</a>
-					<a class="blog_commentlink"
-					   href="{{ permalink }}#comments">
-					{% ifequal entry.comment_set.count 0  %}
-						No Comments (yet)
-					{% else %}
-						{{ entry.comment_set.count }}
-						{% ifequal entry.comment_set.count 1  %}
-							Comment
-						{% else %}
-							Comments
-						{% endifequal %}
-					{% endifequal %}
-					</a>
-				</div>
+<div class="blog_footer">
+    <hr class="blog_footer_hr"/>
+    <a class="blog_permalink" 
+       href="{{ entry.get_absolute_url }}">Permanent Link</a>
+    <a class="blog_commentlink"
+       href="{{ entry.get_absolute_url }}#comments">
+    {% ifequal entry.comment_set.count 0  %}
+        No Comments (yet)
+    {% else %}
+        {{ entry.comment_set.count }}
+        {% ifequal entry.comment_set.count 1  %}
+            Comment
+        {% else %}
+            Comments
+        {% endifequal %}
+    {% endifequal %}
+    </a>
+</div>

File templates/blog/index.html

 		{% include "blog/entry_paging.html" %}
 		<div id="blog_entries">
 			{% for entry in entries %}
-				{% url lindyjam.blog.views.entry entry.pub_date.year, entry.pub_date.month, entry.pub_date.day, entry.slug as permalink %}
 				{% include "blog/single_entry.html" %}
 			{% endfor %}
 		</div>

File templates/blog/single_entry.html

 {% load markup %}
 
-	<div class="blog_entry">
-		<h1 class="blog_title">
-			<a class="blog_title_link" href="{{ permalink }}">
-				{{ entry.title }}
-			</a>
-		</h1>
-		<div class="blog_byline">
-			Posted by {{ entry.author.get_full_name }}
-			on {{ entry.pub_date.date|date:"F j, Y" }}
-			at {{ entry.pub_date.time|time:"g:i A" }}</div>
-		<div class="blog_body">{{ entry.body|markdown }}</div>
-		{% include "blog/entry_footer.html" %}
-	</div>
+<div class="blog_entry">
+    <h1 class="blog_title">
+        <a class="blog_title_link" href="{{ entry.get_absolute_url }}">
+            {{ entry.title }}
+        </a>
+    </h1>
+    <div class="blog_byline">
+        Posted by {{ entry.author.get_full_name }}
+        on {{ entry.pub_date.date|date:"F j, Y" }}
+        at {{ entry.pub_date.time|time:"g:i A" }}</div>
+    <div class="blog_body">{{ entry.body|markdown }}</div>
+    {% include "blog/entry_footer.html" %}
+</div>
     url(r'^admin/(.*)', admin.site.root),
     url(r'^m/(.*)', mobileadmin.sites.site.root),
     url(r'^$', 'lindyjam.splash.views.index'), 
-    url(r'^blog/$', 'lindyjam.blog.views.index'),
-    url(r'^blog/page/(\d+)/$', 'lindyjam.blog.views.index'),
-    url(r'^blog/entry/(\d+)/(\d+)/(\d+)/(.*)/', 'lindyjam.blog.views.entry'),
-    url(r'^blog/comment/', 'lindyjam.blog.views.comment'),
+    url(r'^blog/', include('lindyjam.blog.urls')),
     url(r'^links/$', 'lindyjam.links.views.index'),
     url(r'^links/submit/$', 'lindyjam.links.views.submit'),
     url(r'^schedule/$', 'lindyjam.djschedule.views.index'),