summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/builder/base.py2
-rw-r--r--app/projects/admin.py20
-rw-r--r--app/projects/models/__init__.py2
-rw-r--r--app/projects/models/code.py69
-rw-r--r--app/projects/urls.py1
-rw-r--r--app/projects/views.py7
6 files changed, 96 insertions, 5 deletions
diff --git a/app/builder/base.py b/app/builder/base.py
index 9dc07e9..56d4149 100644
--- a/app/builder/base.py
+++ b/app/builder/base.py
@@ -274,3 +274,5 @@ class BuildAbout(Build):
fpath = '%sindex.html' %(path)
self.write_file(fpath,t)
+class BuildCodeSite(Build):
+
diff --git a/app/projects/admin.py b/app/projects/admin.py
index 13357b0..e97a261 100644
--- a/app/projects/admin.py
+++ b/app/projects/admin.py
@@ -166,7 +166,7 @@ class NationalParksAdmin(OSMGeoAdmin):
from django.contrib import admin
-from projects.models.code import Code
+from projects.models.code import Code,CodeBlogEntry,CodeBlogDemo
class CodeAdmin(admin.ModelAdmin):
list_display = ('name', 'date_created', 'status')
@@ -176,6 +176,22 @@ class CodeAdmin(admin.ModelAdmin):
(None, {'fields': ('name','date_created','slug','status','body_html')}),
)
+class CodeBlogEntryAdmin(admin.ModelAdmin):
+ list_display = ('title', 'pub_date', 'status')
+ search_fields = ['name','body_markdown']
+ list_filter = ['status',]
+ prepopulated_fields = {"slug" : ('title',)}
+ fieldsets = (
+ (None, {'fields': ('title','body_markdown','pub_date','slug','status','enable_comments')}),
+ )
+
+class CodeBlogDemoAdmin(admin.ModelAdmin):
+ list_display = ('title', 'pub_date', )
+ search_fields = ['name','body']
+ fieldsets = (
+ (None, {'fields': ('title','slug','template','head','body')}),
+ )
+
class AnimatedGifAdmin(admin.ModelAdmin):
list_display = ('title', 'date_created')
search_fields = ['title',]
@@ -185,6 +201,8 @@ class AnimatedGifAdmin(admin.ModelAdmin):
admin.site.register(AnimatedGif, AnimatedGifAdmin)
+admin.site.register(CodeBlogEntry, CodeBlogEntryAdmin)
+admin.site.register(CodeBlogDemo, CodeBlogDemoAdmin)
admin.site.register(Code, CodeAdmin)
admin.site.register(Project, ProjectAdmin)
admin.site.register(FiveBy, FiveByAdmin)
diff --git a/app/projects/models/__init__.py b/app/projects/models/__init__.py
index 6f61282..19a4f56 100644
--- a/app/projects/models/__init__.py
+++ b/app/projects/models/__init__.py
@@ -1,5 +1,5 @@
from base import Project
from fiveby import FiveBy
from natparks import NationalParks
-from code import Code
+from code import Code, CodeBlogDemo, CodeBlogEntry
from gifs import AnimatedGif
diff --git a/app/projects/models/code.py b/app/projects/models/code.py
index 14a66f0..62179dc 100644
--- a/app/projects/models/code.py
+++ b/app/projects/models/code.py
@@ -1,11 +1,13 @@
+import datetime
from django.db import models
-
+from utils import markdown2 asfaccount.coms markdown
PUB_STATUS = (
(0, 'Draft'),
(1, 'Published'),
)
-
+def markdown_processor(md):
+ return markdown.markdown(md, ['footnotes'],safe_mode = False)
class Code(models.Model):
@@ -23,3 +25,66 @@ class Code(models.Model):
def __unicode__(self):
return self.slug
+class CodeBlogEntry(models.Model):
+ title = models.CharField(max_length=254)
+ slug = models.SlugField()
+ body_markdown = models.TextField()
+ body_html = models.TextField(blank=True)
+ pub_date = models.DateTimeField('Date published', blank=True)
+ status = models.IntegerField(choices=PUB_STATUS, default=0)
+ enable_comments = models.BooleanField(default=True)
+
+ class Meta:
+ verbose_name_plural = "Code Blog"
+ app_label = 'projects'
+ ordering = ('-pub_date',)
+
+ # Returns the string representation of the model.
+ def __unicode__(self):
+ return self.slug
+
+ def get_absolute_url(self):
+ return "/projects/code/%s/%s/" % (self.pub_date.strftime("%Y/%b/%d").lower(), self.slug)
+
+ @property
+ def get_previous_published(self):
+ return self.get_previous_by_pub_date(status__exact=1)
+
+ @property
+ def get_next_published(self):
+ return self.get_next_by_pub_date(status__exact=1)
+
+
+ def comment_period_open(self):
+ return self.enable_comments and datetime.datetime.today() - datetime.timedelta(30) <= self.pub_date
+
+ def save(self):
+ self.body_html = markdown_processor(self.body_markdown)
+ if not self.id and self.pub_date == None:
+ self.pub_date = datetime.datetime.now()
+ super(CodeBlogEntry, self).save()
+
+
+
+DEMO_TEMPLATES = (
+ (0, 'Blank'),
+ (1, 'Basic_light'),
+ )
+
+
+class CodeBlogDemo(models.Model):
+ title = models.CharField(max_length=254)
+ slug = models.SlugField()
+ body = models.TextField(blank=True,null=True)
+ head = models.TextField(blank=True,null=True)
+ template= models.IntegerField(choices=DEMO_TEMPLATES, default=0)
+ pub_date = models.DateTimeField('Date published',blank=True)
+ class Meta:
+ verbose_name_plural = "Demos"
+ app_label = 'projects'
+ ordering = ('-pub_date',)
+
+ def save(self):
+ if not self.id:
+ self.pub_date = datetime.datetime.now()
+ super(CodeBlogDemo, self).save()
diff --git a/app/projects/urls.py b/app/projects/urls.py
index 83f07c7..f4d692c 100644
--- a/app/projects/urls.py
+++ b/app/projects/urls.py
@@ -12,6 +12,7 @@ projects = {
urlpatterns = patterns('',
(r'data/(?P<id>\d+)/$', 'projects.views.data_json'),
(r'gifs/(?P<slug>[-\w]+)/$', 'projects.views.gif_detail'),
+ (r'code/(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/(?P<slug>[-\w]+)/$', 'projects.views.code_entry_detail'),
(r'(?P<slug>[-\w]+)/$', 'projects.views.detail'),
(r'^$',list_detail.object_list, dict(projects, template_name='archives/projects.html')),
)
diff --git a/app/projects/views.py b/app/projects/views.py
index e25802b..90db6ba 100644
--- a/app/projects/views.py
+++ b/app/projects/views.py
@@ -10,7 +10,7 @@ from projects.models.base import Project
from projects.models.fiveby import FiveBy
from projects.models.natparks import NationalParks
from projects.models.gifs import AnimatedGif
-
+from projects.models.code import CodeBlogEntry
projects = {'5x5':'FiveBy','6x6':'SixBy','national-parks':'NationalParks','code':'Code'}
"""
@@ -30,6 +30,11 @@ def gif_detail(request,slug):
obj = get_object_or_404(AnimatedGif, slug__exact=slug)
return render_to_response('details/gifs.html', {'object': obj}, context_instance=RequestContext(request))
+def code_entry_detail(request, year, month, day, slug):
+ obj = get_object_or_404(CodeBlogEntry, slug__exact=slug)
+ return render_to_response('details/code_blog.html', {'object': obj}, context_instance=RequestContext(request))
+
+
def data_json(request, id):
qs = NationalParks.objects.filter(pk=id)