Dodanie informacji o kodowaniu do settings.py.
[wolnelektury.git] / newtagging / utils.py
1 # -*- coding: utf-8 -*-
2 """
3 Tagging utilities - from user tag input parsing to tag cloud
4 calculation.
5 """
6
7
8 def get_queryset_and_model(queryset_or_model):
9     """
10     Given a ``QuerySet`` or a ``Model``, returns a two-tuple of
11     (queryset, model).
12
13     If a ``Model`` is given, the ``QuerySet`` returned will be created
14     using its default manager.
15     """
16     try:
17         return queryset_or_model, queryset_or_model.model
18     except AttributeError:
19         return queryset_or_model._default_manager.all(), queryset_or_model
20
21
22 def get_tag_list(tags):
23     """
24     Utility function for accepting tag input in a flexible manner.
25     
26     If a ``Tag`` object is given, it will be returned in a list as
27     its single occupant.
28     """
29     from newtagging.models import TagBase
30     if isinstance(tags, TagBase):
31         return [tags]
32     else:
33         return tags
34