minor display fix
[wolnelektury.git] / apps / api / urls.py
1 # -*- coding: utf-8 -*-
2 from django.conf.urls.defaults import *
3 from django.views.decorators.csrf import csrf_exempt
4 from django.views.generic import TemplateView
5 from piston.authentication import OAuthAuthentication, oauth_access_token 
6 from piston.resource import Resource
7
8 from api import handlers
9 from api.helpers import CsrfExemptResource
10
11 auth = OAuthAuthentication(realm="Wolne Lektury")
12
13 book_changes_resource = Resource(handler=handlers.BookChangesHandler)
14 tag_changes_resource = Resource(handler=handlers.TagChangesHandler)
15 changes_resource = Resource(handler=handlers.ChangesHandler)
16
17 book_list_resource = CsrfExemptResource(handler=handlers.BooksHandler, authentication=auth)
18 ebook_list_resource = Resource(handler=handlers.EBooksHandler)
19 #book_list_resource = Resource(handler=handlers.BooksHandler)
20 book_resource = Resource(handler=handlers.BookDetailHandler)
21
22 collection_resource = Resource(handler=handlers.CollectionDetailHandler)
23 collection_list_resource = Resource(handler=handlers.CollectionsHandler)
24
25 tag_list_resource = Resource(handler=handlers.TagsHandler)
26 tag_resource = Resource(handler=handlers.TagDetailHandler)
27
28 fragment_resource = Resource(handler=handlers.FragmentDetailHandler)
29 fragment_list_resource = Resource(handler=handlers.FragmentsHandler)
30
31 picture_resource = CsrfExemptResource(handler=handlers.PictureHandler, authentication=auth)
32
33 urlpatterns = patterns(
34     'piston.authentication',
35     url(r'^oauth/request_token/$', 'oauth_request_token'),
36     url(r'^oauth/authorize/$', 'oauth_user_auth'),
37     url(r'^oauth/access_token/$', csrf_exempt(oauth_access_token)),
38
39 ) + patterns('',
40     url(r'^$', TemplateView.as_view(template_name='api/main.html'), name='api'),
41
42
43     # changes handlers
44     url(r'^book_changes/(?P<since>\d*?)\.(?P<emitter_format>xml|json|yaml)$', book_changes_resource),
45     url(r'^tag_changes/(?P<since>\d*?)\.(?P<emitter_format>xml|json|yaml)$', tag_changes_resource),
46     # used by mobile app
47     url(r'^changes/(?P<since>\d*?)\.(?P<emitter_format>xml|json|yaml)$', changes_resource),
48
49     # info boxes (used by mobile app)
50     url(r'book/(?P<id>\d*?)/info\.html$', 'catalogue.views.book_info'),
51     url(r'tag/(?P<id>\d*?)/info\.html$', 'catalogue.views.tag_info'),
52
53
54     # books by collections
55     url(r'^collections/$', collection_list_resource, name="api_collections"),
56     url(r'^collections/(?P<slug>[^/]+)/$', collection_resource, name="api_collection"),
57
58     # objects details
59     url(r'^books/(?P<book>[a-z0-9-]+)/$', book_resource, name="api_book"),
60     url(r'^(?P<category>[a-z0-9-]+)/(?P<slug>[a-z0-9-]+)/$',
61         tag_resource, name="api_tag"),
62     url(r'^books/(?P<book>[a-z0-9-]+)/fragments/(?P<anchor>[a-z0-9-]+)/$',
63         fragment_resource, name="api_fragment"),
64
65     # books by tags
66     url(r'^(?P<tags>(?:(?:[a-z0-9-]+/){2}){0,6})books/$',
67         book_list_resource, name='api_book_list'),
68     url(r'^(?P<tags>(?:(?:[a-z0-9-]+/){2}){0,6})ebooks/$',
69         ebook_list_resource, name='api_ebook_list'),
70     url(r'^(?P<tags>(?:(?:[a-z0-9-]+/){2}){0,6})parent_books/$',
71         book_list_resource, {"top_level": True}, name='api_parent_book_list'),
72     url(r'^(?P<tags>(?:(?:[a-z0-9-]+/){2}){0,6})parent_ebooks/$',
73         ebook_list_resource, {"top_level": True}, name='api_parent_ebook_list'),
74     url(r'^(?P<tags>(?:(?:[a-z0-9-]+/){2}){0,6})audiobooks/$',
75         book_list_resource, {"audiobooks": True}, name='api_audiobook_list'),
76     url(r'^(?P<tags>(?:(?:[a-z0-9-]+/){2}){0,6})daisy/$',
77         book_list_resource, {"daisy": True}, name='api_daisy_list'),
78
79     url(r'^pictures/$', picture_resource),
80
81     # fragments by book, tags, themes
82     # this should be paged
83     url(r'^(?P<tags>(?:(?:[a-z0-9-]+/){2}){1,6})fragments/$', fragment_list_resource),
84
85     # tags by category
86     url(r'^(?P<category>[a-z0-9-]+)/$', tag_list_resource, name='api_tag_list'),
87 )