fix
[wolnelektury.git] / src / catalogue / models / book.py
index 97677bd..2371103 100644 (file)
@@ -229,8 +229,15 @@ class Book(models.Model):
     def is_accessible_to(self, user):
         if not self.preview:
             return True
     def is_accessible_to(self, user):
         if not self.preview:
             return True
+        if not user.is_authenticated:
+            return False
         Membership = apps.get_model('club', 'Membership')
         Membership = apps.get_model('club', 'Membership')
-        return Membership.is_active_for(user)
+        if Membership.is_active_for(user):
+            return True
+        Funding = apps.get_model('funding', 'Funding')
+        if Funding.objects.filter(user=user, offer__book=self):
+            return True
+        return False
 
     def save(self, force_insert=False, force_update=False, **kwargs):
         from sortify import sortify
 
     def save(self, force_insert=False, force_update=False, **kwargs):
         from sortify import sortify
@@ -836,7 +843,7 @@ class Book(models.Model):
     def related_themes(self):
         return Tag.objects.usage_for_queryset(
             Fragment.objects.filter(models.Q(book=self) | models.Q(book__ancestor=self)),
     def related_themes(self):
         return Tag.objects.usage_for_queryset(
             Fragment.objects.filter(models.Q(book=self) | models.Q(book__ancestor=self)),
-            counts=True).filter(category='theme')
+            counts=True).filter(category='theme').order_by('-count')
 
     def parent_cover_changed(self):
         """Called when parent book's cover image is changed."""
 
     def parent_cover_changed(self):
         """Called when parent book's cover image is changed."""