-class FragmentDetailHandler(BaseHandler, FragmentDetails):
- fields = ['book', 'anchor', 'text', 'url', 'themes']
-
- @piwik_track
- def read(self, request, book, anchor):
- """ Returns details of a fragment, identified by book slug and anchor. """
- try:
- return Fragment.objects.get(book__slug=book, anchor=anchor)
- except Fragment.DoesNotExist:
- return rc.NOT_FOUND
-
-
-class FragmentsHandler(BaseHandler, FragmentDetails):
- """ Main handler for Fragments.
-
- Responsible for lists of Fragment objects
- and fields used for representing Fragments.
-
- """
- model = Fragment
- fields = ['book', 'url', 'anchor', 'href']
- allowed_methods = ('GET',)
-
- categories = {'author', 'epoch', 'kind', 'genre', 'book', 'theme'}
-
- @piwik_track
- def read(self, request, tags):
- """ Lists all fragments with given book, tags, themes.
-
- :param tags: should be a path of categories and slugs, i.e.:
- books/book-slug/authors/an-author/themes/a-theme/
-
- """
- try:
- tags, ancestors = read_tags(tags, allowed=self.categories)
- except ValueError:
- return rc.NOT_FOUND
- fragments = Fragment.tagged.with_all(tags).select_related('book')
- if fragments.exists():
- return fragments
- else:
- return rc.NOT_FOUND
-
-
-class PictureHandler(BaseHandler):
- model = Picture
- fields = ('slug', 'title')
- allowed_methods = ('POST',)
-
- def create(self, request):
- if not request.user.has_perm('picture.add_picture'):
- return rc.FORBIDDEN