aboutsummaryrefslogtreecommitdiff
path: root/urls.py
blob: de3675bc937cedcb1b2e07f3cc032d103110b9da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
from django.conf import settings
from django.views.generic import RedirectView

from django.conf.urls import include, url
from django.urls import reverse_lazy
from django.views.static import serve
from django.conf.urls.static import static

from django.contrib.auth import views as auth_views

from license_protected_downloads.views import (
    show_license
    as show_license_views,
    redirect_to_root
    as redirect_to_root_views,
    accept_license
    as accept_license_views,
    get_textile_files
    as get_textile_files_views,
    reports
    as reports_views,
    reports_month_downloads
    as reports_month_downloads_views,
    reports_month_file_downloads
    as reports_month_file_downloads_views,
    reports_month_country
    as reports_month_country_views,
    reports_month_region
    as reports_month_region_views,
    reports_month_country_details
    as reports_month_country_details_views,
    reports_month_region_details
    as reports_month_region_details_views,
    file_server
    as file_server_views,
    error_view
)

# V1 and V2 not used
# Lets import anyway and delete this at a later date
from license_protected_downloads.api.v1 import (
    list_files_api
    as list_files_api_views,
    get_license_api
    as get_license_api_views
)

from license_protected_downloads.api.v2 import (
    token
    as token_v2_views,
    publish
    as publish_v2_views
    )
from license_protected_downloads.api.v2 import (
    link_latest as
    link_v2_latest_views
)

from license_protected_downloads.api.v3 import token as token_views
from license_protected_downloads.api.v3 import publish as publish_views
from license_protected_downloads.api.v3 import link_latest as link_latest_views



# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()


urlpatterns = [
    url(r'^admin/', admin.site.urls),

    # Use "linaro-openid" to allow peaceful coexistence of both
    # python-apache-openid and django-openid authentication on the
    # same server.  When we get rid of apache openid protection,
    # we can go back to using just "openid" here.
    url(r'^linaro-openid/', include('django_openid_auth.urls')),
    url(r'^login/?$',
        RedirectView.as_view(url='/linaro-openid/login/', permanent=True),
        name='login'),
    url(r'^logout/?$',
        auth_views.logout,
        name='logout'),

    # Handle JS libs and CSS.
    url(r'^js/(?P<path>.*)$', serve,
          {'document_root': settings.JS_PATH}),
    url(r'^css/(?P<path>.*)$', serve,
         {'document_root': settings.CSS_PATH}),

    # The license page...
    url(r'^license$',
        show_license_views,
        name='show_license'),

    # Exceptions redirected to root...
    url(r'^license',
        redirect_to_root_views,
        name='redirect_to_root'),

    # Accept the license
    url(r'^accept-license',
        accept_license_views,
        name='accept_license'),

    # Recursively get files for rendering (async calls accepted only).
    url(r'^get-textile-files',
        get_textile_files_views,
        name='get_textile_files'),

    # V1 and V2 API's not used
    url(r'^api/ls/(?P<path>.*)$',
        list_files_api_views),
    url(r'^api/license/(?P<path>.*)$',
        get_license_api_views),
    url(r'^api/v2/token/(?P<token>.*)$',
        token_v2_views),
    url(r'^api/v2/publish/(?P<path>.*)$',
        publish_v2_views),
    url(r'^api/v2/link_latest/(?P<path>.*)$',
        link_v2_latest_views),

    url(r'^api/v3/token/(?P<token>.*)$',
        token_views),
    url(r'^api/v3/publish/(?P<path>.*)$',
        publish_views),
    url(r'^api/v3/link_latest/(?P<path>.*)$',
        link_latest_views),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

if settings.TRACK_DOWNLOAD_STATS:
    urlpatterns += [
        url(r'^reports/$',
            reports_views),

        url(r'^reports/(?P<year_month>\d{4}\.\d{2})/downloads/$',
            reports_month_downloads_views),
        url(r'^reports/(?P<year_month>\d{4}\.\d{2})/downloads(?P<name>/.*)',
            reports_month_file_downloads_views),
        url(r'^reports/(?P<year_month>\d{4}\.\d{2})/country/$',
            reports_month_country_views),
        url(r'^reports/(?P<year_month>\d{4}\.\d{2})/region/$',
            reports_month_region_views),
        url(r'^reports/(?P<year_month>\d{4}\.\d{2})/country/(?P<country>.*)/',
            reports_month_country_details_views),
        url(r'^reports/(?P<year_month>\d{4}\.\d{2})/region/(?P<region>.*)/',
            reports_month_region_details_views),
    ]

urlpatterns += [
    # Catch-all. We always return a file (or try to) if it exists.
    # This handler does that.
    url(r'(?P<path>.*)', file_server_views),
]

handler500 = error_view