Skip to content

Commit

Permalink
Add Markdown.
Browse files Browse the repository at this point in the history
  • Loading branch information
sjl committed Jan 23, 2011
1 parent 9529429 commit 5038801
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 2 deletions.
3 changes: 2 additions & 1 deletion chunks/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
class ChunkAdmin(admin.ModelAdmin):
list_display = ('key',)
search_fields = ('key', 'content')
fields = ('key', 'content')

admin.site.register(Chunk, ChunkAdmin)
admin.site.register(Chunk, ChunkAdmin)
35 changes: 35 additions & 0 deletions chunks/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# encoding: utf-8
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models

class Migration(SchemaMigration):

def forwards(self, orm):

# Adding model 'Chunk'
db.create_table('chunks_chunk', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('key', self.gf('django.db.models.fields.CharField')(unique=True, max_length=255)),
('content', self.gf('django.db.models.fields.TextField')(blank=True)),
))
db.send_create_signal('chunks', ['Chunk'])


def backwards(self, orm):

# Deleting model 'Chunk'
db.delete_table('chunks_chunk')


models = {
'chunks.chunk': {
'Meta': {'object_name': 'Chunk'},
'content': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
}
}

complete_apps = ['chunks']
31 changes: 31 additions & 0 deletions chunks/migrations/0002_auto__add_field_chunk_content_rendered.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# encoding: utf-8
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models

class Migration(SchemaMigration):

def forwards(self, orm):

# Adding field 'Chunk.content_rendered'
db.add_column('chunks_chunk', 'content_rendered', self.gf('django.db.models.fields.TextField')(default='', blank=True), keep_default=False)


def backwards(self, orm):

# Deleting field 'Chunk.content_rendered'
db.delete_column('chunks_chunk', 'content_rendered')


models = {
'chunks.chunk': {
'Meta': {'object_name': 'Chunk'},
'content': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'content_rendered': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
}
}

complete_apps = ['chunks']
Empty file added chunks/migrations/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions chunks/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import markdown
from django.db import models

class Chunk(models.Model):
Expand All @@ -9,6 +10,11 @@ class Chunk(models.Model):
"""
key = models.CharField(help_text="A unique name for this chunk of content", blank=False, max_length=255, unique=True)
content = models.TextField(blank=True)
content_rendered = models.TextField(blank=True)

def __unicode__(self):
return u"%s" % (self.key,)

def save(self, *args, **kwargs):
self.content_rendered = markdown.markdown(self.content)
return super(Chunk, self).save(*args, **kwargs)
2 changes: 1 addition & 1 deletion chunks/templatetags/chunks.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def render(self, context):
if c is None:
c = Chunk.objects.get(key=self.key)
cache.set(cache_key, c, int(self.cache_time))
content = c.content
content = c.content_rendered
except Chunk.DoesNotExist:
content = ''
return content
Expand Down

0 comments on commit 5038801

Please sign in to comment.