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