diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/src/__init__.py | 0 | ||||
-rw-r--r-- | app/src/admin.py | 37 | ||||
-rw-r--r-- | app/src/models.py | 93 | ||||
-rw-r--r-- | app/src/urls.py | 16 | ||||
-rw-r--r-- | app/src/views.py | 8 |
5 files changed, 154 insertions, 0 deletions
diff --git a/app/src/__init__.py b/app/src/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/src/__init__.py diff --git a/app/src/admin.py b/app/src/admin.py new file mode 100644 index 0000000..2a9a285 --- /dev/null +++ b/app/src/admin.py @@ -0,0 +1,37 @@ +from django.contrib import admin +from .models import Topic, Entry, Book +from blog.admin import BlogEntryForm + +class TopicAdmin(admin.ModelAdmin): + prepopulated_fields = {"slug": ('name',), "pluralized_name":('name',)} + +class BookAdmin(admin.ModelAdmin): + prepopulated_fields = {"slug": ('title',),} + +class EntryAdmin(admin.ModelAdmin): + form = BlogEntryForm + list_display = ('title', 'pub_date', 'enable_comments', 'status') + list_filter = ('pub_date', 'enable_comments', 'status') + prepopulated_fields = {"slug": ('title',)} + fieldsets = ( + ('Entry', { + 'fields': ( + 'title', + 'body_markdown', + ('pub_date', 'status'), + 'topics', + 'meta_description', + ('slug', 'enable_comments', 'template_name'), + ), + 'classes': ( + 'show', + 'extrapretty', + 'wide' + ) + } + ), + ) + +admin.site.register(Book, BookAdmin) +admin.site.register(Topic, TopicAdmin) +admin.site.register(Entry, EntryAdmin) diff --git a/app/src/models.py b/app/src/models.py new file mode 100644 index 0000000..f7362cb --- /dev/null +++ b/app/src/models.py @@ -0,0 +1,93 @@ +from django.db import models +from blog.models import image_url_replace, extract_images +import markdown + +class Topic(models.Model): + name = models.CharField(max_length=60) + slug = models.SlugField() + pluralized_name = models.CharField(max_length=60) + + def __str__(self): + return self.name + + +class Entry(models.Model): + title = models.CharField(max_length=200) + slug = models.SlugField(unique_for_date='pub_date') + body_html = models.TextField(blank=True) + body_markdown = models.TextField() + pub_date = models.DateTimeField('Date published') + topics = models.ManyToManyField(Topic, blank=True) + last_updated = models.DateTimeField(auto_now=True) + enable_comments = models.BooleanField(default=False) + PUB_STATUS = ( + (0, 'Draft'), + (1, 'Published'), + ) + status = models.IntegerField(choices=PUB_STATUS, default=0) + meta_description = models.CharField(max_length=256, null=True, blank=True) + TEMPLATES = ( + (0, 'default'), + ) + template_name = models.IntegerField(choices=TEMPLATES, default=0) + + class Meta: + ordering = ('-pub_date',) + get_latest_by = 'pub_date' + verbose_name_plural = 'entries' + + def __str__(self): + return self.title + + def get_absolute_url(self): + return "/src/%s" % self.slug + + def comment_period_open(self): + return self.enable_comments and datetime.datetime.today() - datetime.timedelta(30) <= self.pub_date + + + def get_images(self): + return extract_images(self.body_html) + + @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 save(self): + md = image_url_replace(self.body_markdown) + self.body_html = markdown.markdown(md, extensions=['extra'], safe_mode=False) + super(Entry, self).save() + + +def get_upload_path(self, filename): + return "images/src/%s" % filename + + +class Book(models.Model): + title = models.CharField(max_length=200) + image = models.FileField(blank=True, null=True, upload_to=get_upload_path) + slug = models.SlugField(unique_for_date='pub_date') + body_html = models.TextField(blank=True) + body_markdown = models.TextField() + pub_date = models.DateTimeField('Date published') + last_updated = models.DateTimeField(auto_now=True) + PUB_STATUS = ( + (0, 'Draft'), + (1, 'Published'), + ) + status = models.IntegerField(choices=PUB_STATUS, default=0) + meta_description = models.CharField(max_length=256, null=True, blank=True) + + class Meta: + ordering = ('-pub_date',) + get_latest_by = 'pub_date' + + def __str__(self): + return self.title + + def get_absolute_url(self): + return "/src/books/%s" % (self.slug) diff --git a/app/src/urls.py b/app/src/urls.py new file mode 100644 index 0000000..c9e8077 --- /dev/null +++ b/app/src/urls.py @@ -0,0 +1,16 @@ +from django.conf.urls import * +from django.views.generic import ListView + +from .models import Entry, Book + +urlpatterns = patterns('', + (r'books/$', ListView.as_view( + queryset=Book.objects.filter(status__exact=1).order_by('-pub_date'), + template_name="archives/src_books.html", + )), + (r'(?P<slug>[-\w]+)/$', 'src.views.detail'), + (r'^$', ListView.as_view( + queryset=Entry.objects.filter(status__exact=1).order_by('-pub_date'), + template_name="archives/src_home.html", + )), +) diff --git a/app/src/views.py b/app/src/views.py new file mode 100644 index 0000000..f3803b9 --- /dev/null +++ b/app/src/views.py @@ -0,0 +1,8 @@ +from django.shortcuts import render_to_response, get_object_or_404 +from django.template import RequestContext +from .models import Entry + +def detail(request, slug): + obj = get_object_or_404(Entry, slug__exact=slug) + return render_to_response('details/src_entry.html', {'object': obj}, context_instance=RequestContext(request)) + |