-# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
-# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+# This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
#
from functools import reduce
import pickle
from django.core.files.base import ContentFile
from django.db import models
from django.utils.timezone import utc
-from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import GenericForeignKey
from django.conf import settings
from django.urls import reverse
-from catalogue.models import Book, Tag
+from catalogue.models import Book
+from social.models import UserList
class Poem(models.Model):
- slug = models.SlugField(_('slug'), max_length=120, db_index=True)
- text = models.TextField(_('text'))
+ slug = models.SlugField('slug', max_length=120, db_index=True)
+ text = models.TextField('tekst')
created_by = models.ForeignKey(User, models.SET_NULL, null=True)
- created_from = models.TextField(_('extra information'), null=True, blank=True)
- created_at = models.DateTimeField(_('creation date'), auto_now_add=True, editable=False)
- seen_at = models.DateTimeField(_('last view date'), auto_now_add=True, editable=False)
- view_count = models.IntegerField(_('view count'), default=1)
+ created_from = models.TextField('dodatkowe informacje', null=True, blank=True)
+ created_at = models.DateTimeField('data utworzenia', auto_now_add=True, editable=False)
+ seen_at = models.DateTimeField('data ostatniego obejrzenia', auto_now_add=True, editable=False)
+ view_count = models.IntegerField('licznik obejrzeń', default=1)
try:
f = open(settings.LESMIANATOR_PICKLE, 'rb')
class Continuations(models.Model):
- pickle = models.FileField(_('Continuations file'), upload_to='lesmianator')
+ pickle = models.FileField('plik kontynuacji', upload_to='lesmianator')
content_type = models.ForeignKey(ContentType, models.CASCADE)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey('content_type', 'object_id')
conts)
@classmethod
- def for_set(cls, tag):
- books = Book.tagged_top_level([tag])
- cont_tabs = (cls.get(b) for b in books.iterator())
+ def for_userlist(cls, ul):
+ cont_tabs = [cls.get(b) for b in ul.get_books()]
+ if not cont_tabs: return {}
return reduce(cls.join_conts, cont_tabs)
@classmethod
def get(cls, sth):
object_type = ContentType.objects.get_for_model(sth)
should_keys = {sth.id}
- if isinstance(sth, Tag):
- should_keys = set(b.pk for b in Book.tagged.with_any((sth,)).iterator())
+ if isinstance(sth, UserList):
+ should_keys = set(b.pk for b in sth.get_books())
try:
obj = cls.objects.get(content_type=object_type, object_id=sth.id)
if not obj.pickle:
except cls.DoesNotExist:
if isinstance(sth, Book):
conts = cls.for_book(sth)
- elif isinstance(sth, Tag):
- conts = cls.for_set(sth)
+ elif isinstance(sth, UserList):
+ conts = cls.for_userlist(sth)
else:
raise NotImplementedError('Lesmianator continuations: only Book and Tag supported')