remove even more query chars
[wolnelektury.git] / src / catalogue / models / book.py
index cdb1100..e5ab5e4 100644 (file)
@@ -42,7 +42,8 @@ class UploadToPath(object):
 
 _cover_upload_to = UploadToPath('book/cover/%s.jpg')
 _cover_thumb_upload_to = UploadToPath('book/cover_thumb/%s.jpg')
-_cover_api_thumb_opload_to = UploadToPath('book/cover_api_thumb/%s.jpg')
+_cover_api_thumb_upload_to = UploadToPath('book/cover_api_thumb/%s.jpg')
+_simple_cover_upload_to = UploadToPath('book/cover_simple/%s.jpg')
 
 
 def _ebook_upload_to(upload_path):
@@ -81,9 +82,14 @@ class Book(models.Model):
         upload_to=_cover_thumb_upload_to,
         max_length=255)
     cover_api_thumb = EbookField(
-        'cover_api_thumb', _('cover thumbnail for API'),
+        'cover_api_thumb', _('cover thumbnail for mobile app'),
         null=True, blank=True,
-        upload_to=_cover_api_thumb_opload_to,
+        upload_to=_cover_api_thumb_upload_to,
+        max_length=255)
+    simple_cover = EbookField(
+        'simple_cover', _('cover for mobile app'),
+        null=True, blank=True,
+        upload_to=_simple_cover_upload_to,
         max_length=255)
     ebook_formats = constants.EBOOK_FORMATS
     formats = ebook_formats + ['html', 'xml']
@@ -440,6 +446,7 @@ class Book(models.Model):
             book.cover.build_delay()
             book.cover_thumb.build_delay()
             book.cover_api_thumb.build_delay()
+            book.simple_cover.build_delay()
 
         # Build HTML and ebooks.
         book.html_file.build_delay()
@@ -458,6 +465,7 @@ class Book(models.Model):
             child.parent_cover_changed()
 
         book.save()  # update sort_key_author
+        book.update_popularity()
         cls.published.send(sender=cls, instance=book)
         return book
 
@@ -543,6 +551,7 @@ class Book(models.Model):
                 self.cover.build_delay()
                 self.cover_thumb.build_delay()
                 self.cover_api_thumb.build_delay()
+                self.simple_cover.build_delay()
             for format_ in constants.EBOOK_FORMATS_WITH_COVERS:
                 if format_ not in app_settings.DONT_BUILD:
                     getattr(self, '%s_file' % format_).build_delay()
@@ -707,4 +716,4 @@ add_file_fields()
 
 class BookPopularity(models.Model):
     book = models.OneToOneField(Book, related_name='popularity')
-    count = models.IntegerField(default=0)
+    count = models.IntegerField(default=0, db_index=True)