nicer footer
[wolnelektury.git] / apps / api / urls.py
1 # -*- coding: utf-8 -*-
2 from django.conf.urls.defaults import *
3 from piston.authentication import OAuthAuthentication
4 from piston.resource import Resource
5
6 from api import handlers
7 from catalogue.models import Book
8
9 auth = OAuthAuthentication(realm="Wolne Lektury")
10
11 book_changes_resource = Resource(handler=handlers.BookChangesHandler)
12 tag_changes_resource = Resource(handler=handlers.TagChangesHandler)
13 changes_resource = Resource(handler=handlers.ChangesHandler)
14
15 book_list_resource = Resource(handler=handlers.BooksHandler, authentication=auth)
16 #book_list_resource = Resource(handler=handlers.BooksHandler)
17 book_resource = Resource(handler=handlers.BookDetailHandler)
18
19 tag_list_resource = Resource(handler=handlers.TagsHandler)
20 tag_resource = Resource(handler=handlers.TagDetailHandler)
21
22 fragment_resource = Resource(handler=handlers.FragmentDetailHandler)
23 fragment_list_resource = Resource(handler=handlers.FragmentsHandler)
24
25 picture_resource = Resource(handler=handlers.PictureHandler, authentication=auth)
26
27 urlpatterns = patterns(
28     'piston.authentication',
29     url(r'^oauth/request_token/$', 'oauth_request_token'),
30     url(r'^oauth/authorize/$', 'oauth_user_auth'),
31     url(r'^oauth/access_token/$', 'oauth_access_token'),
32
33 ) + patterns('',
34     url(r'^$', 'django.views.generic.simple.direct_to_template',
35             {'template': 'api/main.html'}),
36
37
38     # changes handlers
39     url(r'^book_changes/(?P<since>\d*?)\.(?P<emitter_format>xml|json|yaml)$', book_changes_resource),
40     url(r'^tag_changes/(?P<since>\d*?)\.(?P<emitter_format>xml|json|yaml)$', tag_changes_resource),
41     # used by mobile app
42     url(r'^changes/(?P<since>\d*?)\.(?P<emitter_format>xml|json|yaml)$', changes_resource),
43
44     # info boxes (used by mobile app)
45     url(r'book/(?P<id>\d*?)/info\.html$', 'catalogue.views.book_info'),
46     url(r'tag/(?P<id>\d*?)/info\.html$', 'catalogue.views.tag_info'),
47
48
49     # objects details
50     url(r'^books/(?P<book>[a-z0-9-]+)/$', book_resource, name="api_book"),
51     url(r'^(?P<category>[a-z0-9-]+)/(?P<slug>[a-z0-9-]+)/$',
52         tag_resource, name="api_tag"),
53     url(r'^books/(?P<book>[a-z0-9-]+)/fragments/(?P<anchor>[a-z0-9-]+)/$',
54         fragment_resource, name="api_fragment"),
55
56     # books by tags
57     url(r'^(?P<tags>(?:(?:[a-z0-9-]+/){2}){0,6})books/$', book_list_resource),
58     url(r'^(?P<tags>(?:(?:[a-z0-9-]+/){2}){0,6})parent_books/$', book_list_resource, {"top_level": True}),
59
60     url(r'^pictures/$', picture_resource),
61
62     # fragments by book, tags, themes
63     # this should be paged
64     url(r'^(?P<tags>(?:(?:[a-z0-9-]+/){2}){1,6})fragments/$', fragment_list_resource),
65
66     # tags by category
67     url(r'^(?P<category>[a-z0-9-]+)/$', tag_list_resource),
68 )