Passing for Django 1.10.
authorRadek Czajka <rczajka@rczajka.pl>
Sat, 16 Feb 2019 21:09:45 +0000 (22:09 +0100)
committerRadek Czajka <rczajka@rczajka.pl>
Sat, 16 Feb 2019 21:09:45 +0000 (22:09 +0100)
requirements/requirements.txt
src/catalogue/models/book.py
src/catalogue/models/tag.py
src/catalogue/tests/test_visit.py
src/catalogue/urls.py
src/newtagging/models.py
src/newtagging/views.py [deleted file]
src/pdcounter/models.py
src/picture/models.py

index 85e69d1..f9374c3 100644 (file)
@@ -1,7 +1,7 @@
 -i https://py.mdrn.pl/simple/
 
 # django
-Django>=1.9,<1.10
+Django>=1.10,<1.11
 fnpdjango==0.3
 django-pipeline==1.6.10
 jsmin
@@ -56,8 +56,8 @@ pyoai==2.4.4
 ## egenix-mx-base  # Doesn't play nice with mx in dist-packages.
 sunburnt
 
-#django-getpaid==1.7.4
--e git+https://github.com/django-getpaid/django-getpaid.git@v1.7.4#egg=django-getpaid
+django-getpaid==1.8.0
+deprecated
 
 httplib2
 Texml
index 068bae8..923a604 100644 (file)
@@ -207,11 +207,6 @@ class Book(models.Model):
     def get_absolute_url(self):
         return 'book_detail', [self.slug]
 
-    @staticmethod
-    @permalink
-    def create_url(slug):
-        return 'book_detail', [slug]
-
     def gallery_path(self):
         return gallery_path(self.slug)
 
index c6b6f26..31da256 100644 (file)
@@ -14,7 +14,7 @@ from django.db.models.query import Prefetch
 from django.dispatch import Signal
 from django.utils.translation import ugettext_lazy as _
 
-from newtagging.models import TagBase
+from newtagging.models import TagManager, TaggedItemManager
 from ssify import flush_ssi_includes
 
 
@@ -37,6 +37,8 @@ class TagRelation(models.Model):
     object_id = models.PositiveIntegerField(_('object id'), db_index=True)
     content_object = GenericForeignKey('content_type', 'object_id')
 
+    objects = TaggedItemManager()
+
     class Meta:
         db_table = 'catalogue_tag_relation'
         unique_together = (('tag', 'content_type', 'object_id'),)
@@ -48,7 +50,7 @@ class TagRelation(models.Model):
             return u'<deleted> [%s]' % self.tag
 
 
-class Tag(TagBase):
+class Tag(models.Model):
     """A tag attachable to books and fragments (and possibly anything).
 
     Used to represent searchable metadata (authors, epochs, genres, kinds),
@@ -74,6 +76,7 @@ class Tag(TagBase):
     after_change = Signal(providing_args=['instance', 'languages'])
 
     intermediary_table_model = TagRelation
+    objects = TagManager()
 
     class UrlDeprecationWarning(DeprecationWarning):
         def __init__(self, tags=None):
@@ -178,13 +181,6 @@ class Tag(TagBase):
     def get_absolute_gallery_url(self):
         return 'tagged_object_list_gallery', [self.url_chunk]
 
-    @classmethod
-    @permalink
-    def create_url(cls, category, slug):
-        return ('catalogue.views.tagged_object_list', [
-            '/'.join((cls.categories_dict[category], slug))
-        ])
-
     def has_description(self):
         return len(self.description) > 0
     has_description.short_description = _('description')
@@ -192,41 +188,38 @@ class Tag(TagBase):
 
     @staticmethod
     def get_tag_list(tag_str):
-        if isinstance(tag_str, basestring):
-            if not tag_str:
-                return []
-            tags = []
-            ambiguous_slugs = []
-            category = None
-            deprecated = False
-            tags_splitted = tag_str.split('/')
-            for name in tags_splitted:
-                if category:
-                    tags.append(Tag.objects.get(slug=name, category=category))
-                    category = None
-                elif name in Tag.categories_rev:
-                    category = Tag.categories_rev[name]
-                else:
-                    try:
-                        tags.append(Tag.objects.get(slug=name))
-                        deprecated = True
-                    except Tag.MultipleObjectsReturned:
-                        ambiguous_slugs.append(name)
-
+        if not tag_str:
+            return []
+        tags = []
+        ambiguous_slugs = []
+        category = None
+        deprecated = False
+        tags_splitted = tag_str.split('/')
+        for name in tags_splitted:
             if category:
-                # something strange left off
-                raise Tag.DoesNotExist()
-            if ambiguous_slugs:
-                # some tags should be qualified
-                e = Tag.MultipleObjectsReturned()
-                e.tags = tags
-                e.ambiguous_slugs = ambiguous_slugs
-                raise e
-            if deprecated:
-                raise Tag.UrlDeprecationWarning(tags=tags)
-            return tags
-        else:
-            return TagBase.get_tag_list(tag_str)
+                tags.append(Tag.objects.get(slug=name, category=category))
+                category = None
+            elif name in Tag.categories_rev:
+                category = Tag.categories_rev[name]
+            else:
+                try:
+                    tags.append(Tag.objects.get(slug=name))
+                    deprecated = True
+                except Tag.MultipleObjectsReturned:
+                    ambiguous_slugs.append(name)
+
+        if category:
+            # something strange left off
+            raise Tag.DoesNotExist()
+        if ambiguous_slugs:
+            # some tags should be qualified
+            e = Tag.MultipleObjectsReturned()
+            e.tags = tags
+            e.ambiguous_slugs = ambiguous_slugs
+            raise e
+        if deprecated:
+            raise Tag.UrlDeprecationWarning(tags=tags)
+        return tags
 
     @property
     def url_chunk(self):
@@ -275,6 +268,9 @@ class Tag(TagBase):
         return meta_tags
 
 
+TagRelation.tag_model = Tag
+
+
 def prefetch_relations(objects, category, only_name=True):
     queryset = TagRelation.objects.filter(tag__category=category).select_related('tag')
     if only_name:
index e6a83ed..c170c00 100644 (file)
@@ -13,14 +13,14 @@ class VisitTest(WLTestCase):
     def setUp(self):
         WLTestCase.setUp(self)
         author = PersonStub(("Jane",), "Doe")
-        book_info = BookInfoStub(author=author, genre="Genre",
+        book_info = BookInfoStub(author=author, genre="Sielanka",
             epoch='Epoch', kind="Kind", **info_args(u"A book"))
         self.book = models.Book.from_text_and_meta(ContentFile('''
             <utwor>
             <opowiadanie>
                 <akap>
                     <begin id="b1" />
-                    <motyw id="m1">Theme</motyw>
+                    <motyw id="m1">Sielanka</motyw>
                     Test
                     <end id="e1" />
                 </akap>
@@ -40,11 +40,13 @@ class VisitTest(WLTestCase):
                 'nowe/',
                 'lektura/a-book/',
                 'lektura/a-book.html',
-                'lektura/a-book/motyw/theme/',
-                'motyw/theme/',
+                'lektura/a-book/motyw/sielanka/',
+                'motyw/sielanka/',
+                'sielanka/',
                 'autor/jane-doe/',
+                'daisy/',
                 # 'autor/jane-doe/gatunek/genre/',
-                # 'autor/jane-doe/gatunek/genre/motyw/theme/',
+                # 'autor/jane-doe/gatunek/genre/motyw/sielanka/',
                 'b/%d/mini.pl.html' % self.book.pk,
                 'b/%d/mini_nolink.pl.html' % self.book.pk,
                 'b/%d/short.pl.html' % self.book.pk,
@@ -56,7 +58,7 @@ class VisitTest(WLTestCase):
                 'lektury/nonexistent/',  # Nonexistent Collection.
                 'lektura/nonexistent/',  # Nonexistent Book.
                 'lektura/nonexistent.html',  # Nonexistent Book's HTML.
-                'lektura/nonexistent/motyw/theme/',  # Nonexistent Book's theme.
+                'lektura/nonexistent/motyw/sielanka/',  # Nonexistent Book's theme.
                 'lektura/a-book/motyw/nonexistent/',  # Nonexistent theme in a Book.
                 'autor/nonexistent/',  # Nonexistent author.
                 'motyw/nonexistent/',  # Nonexistent theme.
index 8b37e07..458f336 100644 (file)
@@ -18,7 +18,7 @@ urlpatterns = [
     # pictures - currently pictures are coupled with catalogue, hence the url is here
     url(r'^obraz/$', picture.views.picture_list_thumb, name='picture_list_thumb'),
     url(r'^obraz/(?P<slug>%s).html$' % SLUG, picture.views.picture_viewer, name='picture_viewer'),
-    url(r'^obraz/(?P<slug>%s)/$' % SLUG, picture.views.picture_detail),
+    url(r'^obraz/(?P<slug>%s)/$' % SLUG, picture.views.picture_detail, name='picture_detail'),
 
     url(r'^p/(?P<pk>\d+)/mini\.(?P<lang>.+)\.html', picture.views.picture_mini, name='picture_mini'),
     url(r'^p/(?P<pk>\d+)/short\.(?P<lang>.+)\.html', picture.views.picture_short, name='picture_short'),
index b90ea8e..800cd00 100644 (file)
@@ -31,11 +31,14 @@ def get_queryset_and_model(queryset_or_model):
 # Managers #
 ############
 class TagManager(models.Manager):
-    def __init__(self, intermediary_table_model):
+    def __init__(self):
         super(TagManager, self).__init__()
-        self.intermediary_table_model = intermediary_table_model
         models.signals.pre_delete.connect(self.target_deleted)
 
+    @property
+    def intermediary_table_model(self):
+        return self.model.intermediary_table_model
+
     def target_deleted(self, instance, **kwargs):
         """ clear tag relations before deleting an object """
         try:
@@ -52,7 +55,7 @@ class TagManager(models.Manager):
         content_type = ContentType.objects.get_for_model(obj)
         current_tags = list(self.filter(items__content_type__pk=content_type.pk,
                                         items__object_id=obj.pk))
-        updated_tags = self.model.get_tag_list(tags)
+        updated_tags = tags
 
         # Remove tags which no longer apply
         tags_for_removal = [tag for tag in current_tags if tag not in updated_tags]
@@ -156,9 +159,9 @@ class TagManager(models.Manager):
 
 
 class TaggedItemManager(models.Manager):
-    def __init__(self, tag_model):
-        super(TaggedItemManager, self).__init__()
-        self.tag_model = tag_model
+    @property
+    def tag_model(self):
+        return self.model.tag_model
 
     def get_by_model(self, queryset_or_model, tags):
         """
@@ -166,7 +169,6 @@ class TaggedItemManager(models.Manager):
         model associated with a given tag or list of tags.
         """
         queryset, model = get_queryset_and_model(queryset_or_model)
-        tags = self.tag_model.get_tag_list(tags)
         if not tags:
             # No existing tags were given
             return queryset.none()
@@ -183,7 +185,6 @@ class TaggedItemManager(models.Manager):
         model associated with *any* of the given list of tags.
         """
         queryset, model = get_queryset_and_model(queryset_or_model)
-        tags = self.tag_model.get_tag_list(tags)
         if not tags:
             return queryset.none()
         # TODO: presumes reverse generic relation
@@ -200,38 +201,3 @@ class TaggedItemManager(models.Manager):
         # Do we know it's 'tags'?
         return queryset.filter(tag_relations__tag__in=obj.tags).annotate(
             count=models.Count('pk')).order_by('-count').exclude(pk=obj.pk)
-
-
-##########
-# Models #
-##########
-
-class TagMeta(ModelBase):
-    """Metaclass for tag models (models inheriting from TagBase)."""
-    def __new__(mcs, name, bases, attrs):
-        model = super(TagMeta, mcs).__new__(mcs, name, bases, attrs)
-        if not model._meta.abstract:
-            # Register custom managers for concrete models
-            TagManager(model.intermediary_table_model).contribute_to_class(model, 'objects')
-            TaggedItemManager(model).contribute_to_class(model.intermediary_table_model, 'objects')
-        return model
-
-
-class TagBase(models.Model):
-    """Abstract class to be inherited by model classes."""
-    __metaclass__ = TagMeta
-
-    class Meta:
-        abstract = True
-
-    @staticmethod
-    def get_tag_list(tag_list):
-        """
-        Utility function for accepting tag input in a flexible manner.
-
-        You should probably override this method in your subclass.
-        """
-        if isinstance(tag_list, TagBase):
-            return [tag_list]
-        else:
-            return tag_list
diff --git a/src/newtagging/views.py b/src/newtagging/views.py
deleted file mode 100644 (file)
index 12e528a..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-Tagging related views.
-"""
-from django.http import Http404
-from django.utils.translation import ugettext as _
-from django.views.generic import ListView
-
-
-def tagged_object_list(request, queryset_or_model, tag_model, tags, related_tags=False,
-                       related_tag_counts=True, **kwargs):
-    """
-    A thin wrapper around
-    ``django.views.generic.list_detail.object_list`` which creates a
-    ``QuerySet`` containing instances of the given queryset or model
-    tagged with the given tag.
-
-    In addition to the context variables set up by ``object_list``, a
-    ``tag`` context variable will contain the ``Tag`` instance for the
-    tag.
-
-    If ``related_tags`` is ``True``, a ``related_tags`` context variable
-    will contain tags related to the given tag for the given model.
-    Additionally, if ``related_tag_counts`` is ``True``, each related
-    tag will have a ``count`` attribute indicating the number of items
-    which have it in addition to the given tag.
-    """
-
-    tag_instances = tag_model.get_tag_list(tags)
-    if tag_instances is None:
-        raise Http404(_('No tags found matching "%s".') % tags)
-    queryset = tag_model.intermediary_table_model.objects.get_by_model(queryset_or_model, tag_instances)
-    if 'extra_context' not in kwargs:
-        kwargs['extra_context'] = {}
-    kwargs['extra_context']['tags'] = tag_instances
-    if related_tags:
-        kwargs['extra_context']['related_tags'] = \
-            tag_model.objects.related_for_model(tag_instances, queryset_or_model, counts=related_tag_counts)
-    return ListView.as_view(queryset=queryset)(request, **kwargs)
index 69c70c1..24866fe 100644 (file)
@@ -36,7 +36,7 @@ class Author(models.Model):
 
     @permalink
     def get_absolute_url(self):
-        return 'catalogue.views.tagged_object_list', [self.url_chunk]
+        return 'tagged_object_list', [self.url_chunk]
 
     def has_description(self):
         return len(self.description) > 0
@@ -76,7 +76,7 @@ class BookStub(models.Model):
 
     @permalink
     def get_absolute_url(self):
-        return 'catalogue.views.book_detail', [self.slug]
+        return 'book_detail', [self.slug]
 
     def in_pd(self):
         return self.pd is not None and self.pd <= datetime.now().year
index e203257..a3c098c 100644 (file)
@@ -144,7 +144,7 @@ class Picture(models.Model):
 
     @permalink
     def get_absolute_url(self):
-        return 'picture.views.picture_detail', [self.slug]
+        return 'picture_detail', [self.slug]
 
     def get_initial(self):
         try: