summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/books/admin.py2
-rw-r--r--app/books/models.py9
-rw-r--r--app/books/views.py15
3 files changed, 18 insertions, 8 deletions
diff --git a/app/books/admin.py b/app/books/admin.py
index 6ba03ff..83ccf93 100644
--- a/app/books/admin.py
+++ b/app/books/admin.py
@@ -3,7 +3,7 @@ from .models import Book, BookHighlight
class BookAdmin(admin.ModelAdmin):
- list_display = ('title', 'admin_thumbnail', 'isbn', 'author_name', 'read_date')
+ list_display = ('title', 'admin_thumbnail', 'isbn', 'author_name', 'read_date', 'publish_date', 'openlib_url')
class BookHighlightAdmin(admin.ModelAdmin):
diff --git a/app/books/models.py b/app/books/models.py
index 14c7160..f31edce 100644
--- a/app/books/models.py
+++ b/app/books/models.py
@@ -4,19 +4,19 @@ from django.conf import settings
from django.template.defaultfilters import slugify
from taggit.managers import TaggableManager
+# http://freewisdom.org/projects/python-markdown/
import markdown
class Book(models.Model):
title = models.CharField(max_length=200)
author_name = models.CharField(max_length=200)
slug = models.CharField(max_length=50)
- year_pub = models.CharField(max_length=4, blank=True, null=True)
read_date = models.DateTimeField()
isbn = models.CharField(max_length=100, blank=True, null=True)
+ body_markdown = models.TextField(null=True, blank=True)
body_html = models.TextField(null=True, blank=True)
read_in = models.TextField(null=True, blank=True)
url = models.CharField(max_length=200, blank=True, null=True)
- tags = TaggableManager()
pages = models.CharField(max_length=5, blank=True, null=True)
publish_date = models.CharField(max_length=40, blank=True, null=True)
publish_place = models.CharField(max_length=100, blank=True, null=True)
@@ -44,12 +44,17 @@ class Book(models.Model):
def get_image_url(self):
return '%sbook-covers/%s.jpg' % (settings.IMAGES_URL, self.slug)
+ def get_rating (self):
+ return int(self.rating)
+
def admin_thumbnail(self):
return force_text('<a href=""><img src="%s" width="100" style="width:100px"></a>' % (self.get_image_url()))
admin_thumbnail.allow_tags = True
admin_thumbnail.short_description = 'Thumbnail'
def save(self, *args, **kwargs):
+ if self.body_markdown:
+ self.body_html = markdown.markdown(self.body_markdown, extensions=['extra'], safe_mode=False)
self.slug = slugify(self.title[:50])
super(Book, self).save()
diff --git a/app/books/views.py b/app/books/views.py
index 7809f17..21f271f 100644
--- a/app/books/views.py
+++ b/app/books/views.py
@@ -11,22 +11,27 @@ from photos.models import Photo
def book_detail(request, slug):
- obj = get_object_or_404(Book, slug__exact=slug)
- return render_to_response('details/book.html', {'object': obj}, context_instance=RequestContext(request))
+ context = {
+ 'object': get_object_or_404(Book, slug__exact=slug),
+ 'ratings_range' : range(1, 6)
+ }
+ return render_to_response('details/book.html', context, context_instance=RequestContext(request))
def book_list(request, page):
- request.page_url = '/book/%d/'
+ request.page_url = '/books/%d/'
request.page = int(page)
try:
is_build = request.POST['builder']
extra_context={
'page':page,
- 'MEDIA_URL': settings.BAKED_MEDIA_URL
+ 'MEDIA_URL': settings.BAKED_MEDIA_URL,
+ 'ratings_range': range(1, 6)
}
except:
extra_context={'page':page}
context = {
'object_list': Book.objects.order_by('-read_date').select_related(),
- 'page': page
+ 'page': page,
+ 'ratings_range' : range(1, 6)
}
return render_to_response("archives/books.html", context, context_instance=RequestContext(request))