-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
## 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
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)
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
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'),)
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),
after_change = Signal(providing_args=['instance', 'languages'])
intermediary_table_model = TagRelation
+ objects = TagManager()
class UrlDeprecationWarning(DeprecationWarning):
def __init__(self, tags=None):
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')
@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):
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:
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>
'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,
'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.
# 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'),
# 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:
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]
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):
"""
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()
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
# 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
+++ /dev/null
-# -*- 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)
@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
@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
@permalink
def get_absolute_url(self):
- return 'picture.views.picture_detail', [self.slug]
+ return 'picture_detail', [self.slug]
def get_initial(self):
try: