summaryrefslogtreecommitdiff
path: root/app/books
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2014-05-23 11:28:10 -0400
committerluxagraf <sng@luxagraf.net>2014-05-23 11:28:10 -0400
commit518b2d618bc10f93cfa44a83715593b8358eb9ce (patch)
treea07993c3ae31bed42f32c0e00788989568790716 /app/books
parent4bae11bb25a8e3c43118891d17fd8e981ecf8dc6 (diff)
minor refactor to adoipt pep8 and pyflakes coding styles and clean up
some cruft that's been hangin round for years
Diffstat (limited to 'app/books')
-rw-r--r--app/books/admin.py16
-rw-r--r--app/books/kindleparser.py31
-rw-r--r--app/books/models.py16
3 files changed, 35 insertions, 28 deletions
diff --git a/app/books/admin.py b/app/books/admin.py
index 0b9b7b7..3f222d8 100644
--- a/app/books/admin.py
+++ b/app/books/admin.py
@@ -1,11 +1,13 @@
from django.contrib import admin
-from .models import Book,BookHighlight
+from .models import Book, BookHighlight
+
class BookAdmin(admin.ModelAdmin):
- list_display = ('title', 'isbn', 'author_name', 'read_date')
-
+ list_display = ('title', 'isbn', 'author_name', 'read_date')
+
+
class BookHighlightAdmin(admin.ModelAdmin):
- list_display = ('book', 'date_added')
-
-admin.site.register(Book, BookAdmin)
-admin.site.register(BookHighlight, BookHighlightAdmin)
+ list_display = ('book', 'date_added')
+
+admin.site.register(Book, BookAdmin)
+admin.site.register(BookHighlight, BookHighlightAdmin)
diff --git a/app/books/kindleparser.py b/app/books/kindleparser.py
index 6b708d9..aaa742f 100644
--- a/app/books/kindleparser.py
+++ b/app/books/kindleparser.py
@@ -8,6 +8,7 @@ import datetime
from django.core.exceptions import ObjectDoesNotExist
from books.models import Book, BookHighlight
+
def parse_kindle_clippings(path):
json_data = open(path)
data = json.load(json_data)
@@ -20,11 +21,11 @@ def parse_kindle_clippings(path):
body_markdown = clip['content']
except KeyError:
body_markdown = ""
- try:
+ try:
location = int(clip['locationRange'])
except:
location = 0
- try:
+ try:
page = int(clip['pageRange'])
except:
page = 0
@@ -37,21 +38,23 @@ def parse_kindle_clippings(path):
row = Book.objects.get(title=clip['title'])
except ObjectDoesNotExist:
b, created = Book.objects.get_or_create(
- title = clip['title'],
- author_name = author_name,
- read_date = clip_date
+ title=clip['title'],
+ author_name=author_name,
+ read_date=clip_date
)
try:
- #see if we already this highlight
- row = BookHighlight.objects.get(book__title=clip['title'], date_added=clip_date )
- #if we don't create a new book highlight
+ #see if we already this highlight
+ row = BookHighlight.objects.get(
+ book__title=clip['title'],
+ date_added=clip_date
+ )
+ #if we don't create a new book highlight
except ObjectDoesNotExist:
book = Book.objects.get(title=clip['title'])
bh, created = BookHighlight.objects.get_or_create(
- book = book,
- page = page,
- location = location,
- date_added = clip_date,
- body_markdown = body_markdown
+ book=book,
+ page=page,
+ location=location,
+ date_added=clip_date,
+ body_markdown=body_markdown
)
-
diff --git a/app/books/models.py b/app/books/models.py
index 173b5f6..7af5d5c 100644
--- a/app/books/models.py
+++ b/app/books/models.py
@@ -1,6 +1,6 @@
from django.db import models
from django.template.defaultfilters import slugify
-from taggit.managers import TaggableManager
+from taggit.managers import TaggableManager
class Book(models.Model):
@@ -10,13 +10,13 @@ class Book(models.Model):
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_html = models.TextField(null=True, blank=True)
-
+
url = models.CharField(max_length=200, blank=True, null=True)
#tags = TaggableManager(blank=True, null=True)
- tags = models.CharField(max_length=200,blank=True, null=True)
+ tags = models.CharField(max_length=200, blank=True, null=True)
RATINGS = (
('1', "1 Star"),
('2', "2 Stars"),
@@ -29,14 +29,15 @@ class Book(models.Model):
class Meta:
ordering = ('-read_date',)
-
+
def __str__(self):
return self.title
-
+
def save(self, *args, **kwargs):
self.slug = slugify(self.title[:50])
super(Book, self).save()
+
class BookHighlight(models.Model):
book = models.ForeignKey(Book)
page = models.PositiveSmallIntegerField(null=True)
@@ -48,7 +49,8 @@ class BookHighlight(models.Model):
ordering = ('-date_added',)
def __str__(self):
- return "%s%s" %(self.book.title, self.id)
+ return "%s%s" % (self.book.title, self.id)
+
class BookNote(BookHighlight):
pass