- """ Returns all collections. """
- return Collection.objects.all()
-
-
-class TagDetails(object):
- """Custom Tag fields."""
-
- @classmethod
- def href(cls, tag):
- """ Returns URI in the API for the tag. """
-
- return API_BASE + reverse("api_tag", args=[category_plural[tag.category], tag.slug])
-
- @classmethod
- def url(cls, tag):
- """ Returns URL on the site. """
-
- return WL_BASE + tag.get_absolute_url()
-
-
-class TagDetailHandler(BaseHandler, TagDetails):
- """ Responsible for details of a single Tag object. """
-
- fields = ['name', 'url', 'sort_key', 'description']
-
- @piwik_track
- def read(self, request, category, slug):
- """ Returns details of a tag, identified by category and slug. """
-
- try:
- category_sng = category_singular[category]
- except KeyError:
- return rc.NOT_FOUND
-
- try:
- return Tag.objects.get(category=category_sng, slug=slug)
- except Tag.DoesNotExist:
- return rc.NOT_FOUND
-
-
-class TagsHandler(BaseHandler, TagDetails):
- """ Main handler for Tag objects.
-
- Responsible for lists of Tag objects
- and fields used for representing Tags.
-
- """
- allowed_methods = ('GET',)
- model = Tag
- fields = ['name', 'href', 'url', 'slug']
-
- @piwik_track
- def read(self, request, category=None, pk=None):
- """ Lists all tags in the category (eg. all themes). """
- if pk is not None:
- try:
- return Tag.objects.exclude(category='set').get(pk=pk)
- except Book.DoesNotExist:
- return rc.NOT_FOUND
-
- try:
- category_sng = category_singular[category]
- except KeyError:
- return rc.NOT_FOUND
-