# HG changeset patch # User Steve Losh # Date 1234677245 18000 # Node ID 8d75ea2ae6de92406ef9c04b6ea875a74374a3b9 # Parent 3a51bfa414da2eced1867ac4c054d4fed8dd53e1 Goodbye thoughts, youll live on in version control! diff -r 3a51bfa414da -r 8d75ea2ae6de settings.py --- a/settings.py Sun Feb 15 00:50:20 2009 -0500 +++ b/settings.py Sun Feb 15 00:54:05 2009 -0500 @@ -89,7 +89,6 @@ 'django.contrib.flatpages', 'stevelosh.blog', 'stevelosh.projects', - 'stevelosh.thoughts', 'stevelosh.photoblog', 'mobileadmin', 'typogrify', diff -r 3a51bfa414da -r 8d75ea2ae6de templates/feeds/thoughts_description.html --- a/templates/feeds/thoughts_description.html Sun Feb 15 00:50:20 2009 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -{% load markup %} - -{% ifequal obj.type 'thought-text' %} - {{ obj.item.body|markdown }} -{% endifequal %} - -{% ifequal obj.type 'thought-link' %} - - {% if obj.item.name %} - {{ obj.item.name }} - {% else %} - {{ obj.item.url }} - {% endif %} - - {% if obj.item.description %} - {{ obj.item.description|markdown }} - {% endif %} -{% endifequal %} \ No newline at end of file diff -r 3a51bfa414da -r 8d75ea2ae6de templates/feeds/thoughts_title.html --- a/templates/feeds/thoughts_title.html Sun Feb 15 00:50:20 2009 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -{% ifequal obj.type 'thought-text' %} - {% if obj.item.title %} - {{ obj.item.title }} - {% else %} - {{ obj.item.body|truncatewords:10 }} - {% endif %} -{% endifequal %} - -{% ifequal obj.type 'thought-link' %} - {% if obj.item.name %} - {{ obj.item.name }} - {% else %} - {{ obj.item.url }} - {% endif %} -{% endifequal %} \ No newline at end of file diff -r 3a51bfa414da -r 8d75ea2ae6de templates/thoughts/list.html --- a/templates/thoughts/list.html Sun Feb 15 00:50:20 2009 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -{% extends "base.html" %} -{% load markup %} -{% load typogrify %} - -{% block title %}Thoughts{% endblock %} - -{% block style %} - -{% endblock %} - -{% block header %}/ thoughts{% endblock %} - -{% block content %} -
- {% for thought in thoughts %} -
- {% ifequal thought.type 'text' %} - -
-

text

-
-
- {% ifnotequal thought.title None %} -

{{ thought.title|typogrify }}

- {% endifnotequal %} - {{ thought.body|markdown|typogrify }} -
- {% endifequal %} - {% ifequal thought.type 'link' %} - -
-

link

-
- - {% endifequal %} -
- {% endfor %} - - {% ifnotequal newer_page older_page %} -
- {% ifnotequal newer_page None %} - {% ifequal newer_page 0 %} - {% url thoughts-list-newest as new_page %} - {% else %} - {% url thoughts-list-page newer_page as new_page %} - {% endifequal %} - -

- Newer » -

-
- {% endifnotequal %} - {% ifnotequal older_page None %} - -

- « Older -

-
- {% else %} - -

 

-
- {% endifnotequal %} -
- {% endifnotequal %} -
-{% endblock %} \ No newline at end of file diff -r 3a51bfa414da -r 8d75ea2ae6de thoughts/__init__.py diff -r 3a51bfa414da -r 8d75ea2ae6de thoughts/admin.py --- a/thoughts/admin.py Sun Feb 15 00:50:20 2009 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -from stevelosh.thoughts.models import TextThought, LinkThought -from django.contrib import admin - -class TextAdmin(admin.ModelAdmin): - list_display = ('posted', 'title', 'body',) - search_fields = ('title', 'body',) - list_filter = ('posted',) - date_hierarchy = 'posted' - ordering = ('-posted',) - -class LinkAdmin(admin.ModelAdmin): - list_display = ('url', 'name', 'posted', 'description',) - search_fields = ('name', 'url', 'description',) - list_filter = ('posted',) - date_hierarchy = 'posted' - ordering = ('-posted',) - - -admin.site.register(TextThought, TextAdmin) -admin.site.register(LinkThought, LinkAdmin) \ No newline at end of file diff -r 3a51bfa414da -r 8d75ea2ae6de thoughts/import.py --- a/thoughts/import.py Sun Feb 15 00:50:20 2009 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -#!/usr/local/bin/python2.5 - -import sys, os -sys.path.append('/home/sjl/webapps/stevelosh') -os.environ['DJANGO_SETTINGS_MODULE'] = 'stevelosh.settings' - -import simplejson, urllib, urllib2 -from stevelosh.thoughts.models import TextThought, LinkThought -from datetime import datetime - - -TUMBLR_API_URL = r'http://stevelosh.tumblr.com/api/read/json' - -def parse_tumblr_json(data): - tumblr_prefix = r'var tumblr_api_read = ' - if data.startswith(tumblr_prefix): - data = data.strip() - data = data[len(tumblr_prefix):-1] - else: - return None - return simplejson.loads(data) - -def fetch_tumblr_data(type): - parameters = {'type': type, 'filter': 'none'} - url_parameters = urllib.urlencode(parameters) - full_api_url = TUMBLR_API_URL + '?' + url_parameters - response = urllib2.urlopen(full_api_url) - return parse_tumblr_json(response.read()) - -def update_text_thoughts(): - recent_thoughts = fetch_tumblr_data('regular') - for thought in recent_thoughts['posts']: - tumblr_id = thought['id'] - try: - TextThought.objects.get(tumblr_id=tumblr_id) - except TextThought.DoesNotExist: - title = thought['regular-title'] \ - if thought['regular-title'] != "" else None - new_thought = TextThought( - tumblr_id=tumblr_id, - title=title, - body=thought['regular-body'], - posted=datetime.fromtimestamp(thought['unix-timestamp']) ) - new_thought.save() - -def update_link_thoughts(): - recent_thoughts = fetch_tumblr_data('link') - for thought in recent_thoughts['posts']: - tumblr_id = thought['id'] - try: - LinkThought.objects.get(tumblr_id=tumblr_id) - except LinkThought.DoesNotExist: - name = thought['link-text'] \ - if thought['link-text'] != "" else None - description = thought['link-description'] \ - if thought['link-description'] != "" else None - new_thought = LinkThought( - tumblr_id=tumblr_id, - name=name, - description=description, - url=thought['link-url'], - posted=datetime.fromtimestamp(thought['unix-timestamp']) ) - new_thought.save() - -update_text_thoughts() -update_link_thoughts() diff -r 3a51bfa414da -r 8d75ea2ae6de thoughts/models.py --- a/thoughts/models.py Sun Feb 15 00:50:20 2009 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -from django.db import models -import datetime - -class TextThought(models.Model): - title = models.CharField(blank=True, null=True, max_length=1000) - posted = models.DateTimeField() - body = models.TextField() - tumblr_id = models.IntegerField(blank=False, null=False) - type = models.CharField(default='text', max_length=100) - - def get_absolute_url(self): - return u'/thoughts/#text-' + str(self.id) - - def __unicode__(self): - return u'%s' % (self.body[:20],) - -class LinkThought(models.Model): - name = models.CharField(blank=True, null=True, max_length=1000) - posted = models.DateTimeField() - url = models.URLField(blank=False, verify_exists=False) - description = models.TextField(blank=True, null=True) - tumblr_id = models.IntegerField(blank=False, null=False) - type = models.CharField(default='link', max_length=100) - - def get_absolute_url(self): - return u'/thoughts/#text-' + str(self.id) - - def __unicode__(self): - return u'%s' % (self.url,) - diff -r 3a51bfa414da -r 8d75ea2ae6de thoughts/urls.py --- a/thoughts/urls.py Sun Feb 15 00:50:20 2009 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -from django.conf.urls.defaults import * - -urlpatterns = patterns('stevelosh.thoughts.views', - url(r'^$', 'list', name='thoughts-list-newest'), - url(r'^page/(\d+)/$', 'list', name='thoughts-list-page'), -) \ No newline at end of file diff -r 3a51bfa414da -r 8d75ea2ae6de thoughts/views.py --- a/thoughts/views.py Sun Feb 15 00:50:20 2009 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -from stevelosh.thoughts.models import TextThought, LinkThought -from django.shortcuts import render_to_response -from django.core.paginator import Paginator -import operator - -ENTRIES_PER_PAGE = 10 - -def list(request, page=1): - page = int(page) - - thoughts = [] - thoughts += TextThought.objects.all().order_by('-posted') - thoughts += LinkThought.objects.all().order_by('-posted') - thoughts.sort(key=operator.attrgetter('posted')) - thoughts.reverse() - - paginator = Paginator(thoughts, 5, orphans=2) - p = paginator.page(page) - - return render_to_response('thoughts/list.html', - { 'thoughts': p.object_list, - 'older_page': p.next_page_number() if p.has_next() else None, - 'newer_page': p.previous_page_number() if p.has_previous() else None } ) diff -r 3a51bfa414da -r 8d75ea2ae6de urls.py --- a/urls.py Sun Feb 15 00:50:20 2009 -0500 +++ b/urls.py Sun Feb 15 00:54:05 2009 -0500 @@ -11,7 +11,6 @@ (r'^m/(.*)', mobileadmin.sites.site.root), 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')), )